|
|
View previous topic :: View next topic |
Author |
Message |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
rs-232 not accepting data |
Posted: Mon Jan 31, 2011 6:47 pm |
|
|
I'm having a strange problem with the rs-232 communication in my program. The xmit pin is sending data to a 19,200 baud serial LCD, and the rcv pin is receiving data from a 2400 baud RF receiver. The problem is, var always equals 0. I can't get it to accept any serial data correctly. Is my rs-232 set up correctly?
Code: |
#include "16f684.h"
#device ADC=10
#use delay(clock=4000000)
#Fuses NOFCMEN,NOPROTECT,MCLR,NOBROWNOUT,NOCPD,NOPUT,NOIESO,INTRC_IO,NOWDT
#use rs232(baud=2400,rcv=PIN_a4,force_sw, bits=8)
#use rs232(baud=19200,invert,long_data,force_sw,xmit=pin_a0)
unsigned int8 command=0;
int8 var=0;
int8 state=0;
void main()
{
while(1)
{
if(state==0)
{
if(!kbhit())
{
var=getc();
delay_ms(5);
state=1;
}
}
if(state==1)
{
command=12; //clear and return home
putc(command);
printf("var=%d", var);
delay_ms(20);
state=0;
}
}
} |
_________________ Vinnie Ryan |
|
|
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Mon Jan 31, 2011 7:25 pm |
|
|
Nevermind, I figured it out. I had to put the #use(rs-232) statements before each rs-232 function, like this:
Code: |
#include "16f684.h"
#device ADC=10
#use delay(clock=4000000)
#Fuses NOFCMEN,NOPROTECT,MCLR,NOBROWNOUT,NOCPD,NOPUT,NOIESO,INTRC_IO,NOWDT
unsigned int8 command=0;
int8 var=0;
int8 state=0;
void main()
{
while(1)
{
if(state==0)
{
#use rs232(baud=2400,rcv=PIN_a4,force_sw, bits=8)
if(!kbhit())
{
var=getc();
delay_ms(5);
state=1;
}
}
if(state==1)
{
#use rs232(baud=19200,invert,long_data,force_sw,xmit=pin_a0)
command=12; //clear and return home
putc(command);
printf("var=%d", var);
delay_ms(20);
state=0;
}
}
} |
_________________ Vinnie Ryan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 31, 2011 7:42 pm |
|
|
It would be better to define each #use rs232() statement with a Stream
parameter, and then use fgetc(), fputc, etc., and specify the desired
stream in each statement. Then the #use rs232() statements can be
placed at the top of your program again. This is described in the CCS
manual. |
|
|
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Mon Jan 31, 2011 8:35 pm |
|
|
I found that out today and am using STREAM now, it's much cleaner this way.
Cheers! _________________ Vinnie Ryan |
|
|
|
|
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
|