CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

get_int()?!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

get_int()?!!
PostPosted: Mon May 14, 2007 1:37 am     Reply with quote

hi
i have two codes,first to work as TX and seconde to work as RX
as below:
Code:

#include <16f877a.h>
#fuses hs,NOWDT,NOLVP
#use delay(clock=20000000)    //one instruction=1us
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)

int value;


void main()   {

    set_tris_d(0xff);


while(1)
   {

   value = input_d();
   delay_ms(5000);
   printf("%u",value);

   }//while
}//MAIN



rx:
Code:

#include <16f877a.h>
#include <stdlib.h>
#fuses hs,NOWDT,NOLVP
#use delay(clock=20000000)    //one instruction=1us
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
#include <INPUT.C>


signed int value,i;
char RX[3];
int1 flag;


#INT_RDA
void serial_isr() {
  value= get_int();
  output_d(value);
   delay_ms(1000);
  flag=1;
}


void main()   {
    flag=0;
    set_tris_d(0x00);
    enable_interrupts(GLOBAL);
    enable_interrupts(INT_RDA);


while(1)
   {

    output_d(0x00);
   if (flag==1)
   {
   //output_d(value);
   //delay_ms(1000);
   flag=0;

   }

   }//while
}//MAIN





first work fine
second cant convert ascii to hex
i try with atoi()
and try with get_int()
and try with:
Code:

unsigned int Ascii2Int()
//convert an ascii string to an interger
{
   return((rxBuffer[0]&0x0f)*100+(rxBuffer[1]&0x0f)*10+(rxBuffer[2]&0x0f));
}





but no way!!! it out nothing
help me please
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 14, 2007 2:28 am     Reply with quote

get_int() doesn't work because this internally function calls get_string() which in turn waits for the string to be terminated by a carriage return character (0x0D).
You can fix this by changing the transmitter to send a CR as well.
Code:
printf("%u\n",value);


Similar reason for atoi() to fail. atoi() expects a zero terminated string as input.
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

PostPosted: Mon May 14, 2007 2:53 am     Reply with quote

thank you
its work fine
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group