View previous topic :: View next topic |
Author |
Message |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
how to send int16 number to another PIC via RS232 |
Posted: Thu Jan 09, 2014 10:24 am |
|
|
hello ,
please help how to send 16 bit number from PIC to another PIC
I tried something like this but I know it don't work...
Code: |
//TRANSMIT 16 bit long unsigned int number:
//define software UART to pins
#use rs232(STREAM = min_data,baud = 9600, xmit=pin_C4)
//and send it to another PIC
int16 minute_data;
fprintf(minute_data,"%Lu",second_counter);
//receive that int16: there's only one stream in receiver
//XMIT is here for that kbhit() works ... this only receive data
#use rs232(baud = 9600, RCV = pin_D3,XMIT = pin_D2,ERRORS)
//maybe something like that ... but how ?
char rcv_data;
int16 bignumber;
while(!kbhit()){
delay_us(1);
}
if(kbhit())
//I know there must be some kind of buffer because long int is two bytes long
//but how??
char string[3];
bignumber = atol(string);
|
I'll be happy if someone help me
friendly regards
-arto- |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Sun Jan 12, 2014 8:26 am |
|
|
ok no success ...
is it ok to send data to another pic like this:
//define software UART to pins
#use rs232(STREAM = sec_data,baud = 9600, xmit=pin_C4)
//and send it to another PIC
int8 second_counter;
fprintf(sec_data,"%u",second_counter);
must there be something carriage return maybe \r when I send unsigned int second_counter ?
I tried to use the examples input.c but no success...
is my transmitter OK ?
and what kind of receiver must be to make things work ?
best regards
-arto- |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jan 12, 2014 10:42 am |
|
|
code snippets NOT tested but theory should be solid...
xmt...
int16 value;
int8 msb;
int8 lsb;
value=0x1234;
msb=make8(value,1);
lsb=make8(value,0);
putc(msb);
putc(lsb);
rcv...
int16 value;
int8 msb;
int8 lsb;
getc(msb);
getc(lsb);
make16(msb,lsb);
hth
jay |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Sun Jan 12, 2014 11:03 am |
|
|
temtronic wrote: | code snippets NOT tested but theory should be solid...
xmt...
int16 value;
int8 msb;
int8 lsb;
value=0x1234;
msb=make8(value,1);
lsb=make8(value,0);
putc(msb);
putc(lsb);
rcv...
int16 value;
int8 msb;
int8 lsb;
getc(msb);
getc(lsb);
make16(msb,lsb);
hth
hth |
HI !
"temtronic"
I do not understand what means hth ...
but is it so that I can not use printf() function to communicate between
two pics ?
have to use putc() function ?
OK thanks a lot for your good answer I'll give up to use fprintf() !
best regards
-arto- |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jan 12, 2014 11:37 am |
|
|
hth = hope this helps
putc(x) is the simple ,easy way to do it....
if you press F11 while your project is open, the CCS manual comes up...
locate printf(...) and see how to use it.
cheers
jay |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Sun Jan 12, 2014 11:55 am |
|
|
temtronic wrote: | hth = hope this helps
putc(x) is the simple ,easy way to do it....
if you press F11 while your project is open, the CCS manual comes up...
locate printf(...) and see how to use it.
cheers
jay |
OH YEH thank's a lot
now it works OK !
I printed out that CCS manual long time ago ...
maybe I'm a bit dumbass to think easy way ...
and I'm not good reading any manuals ...
thank's for your good advice and have fun and good winter...
brdgs
-arto- |
|
|
|