View previous topic :: View next topic |
Author |
Message |
hadeelqasaimeh
Joined: 05 Jan 2006 Posts: 105
|
get_int()?!! |
Posted: Mon May 14, 2007 1:37 am |
|
|
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
|
|
Posted: Mon May 14, 2007 2:28 am |
|
|
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
|
|
Posted: Mon May 14, 2007 2:53 am |
|
|
thank you
its work fine |
|
|
|