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

rs-232 not accepting data

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



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

rs-232 not accepting data
PostPosted: Mon Jan 31, 2011 6:47 pm     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Mon Jan 31, 2011 7:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 31, 2011 7:42 pm     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Mon Jan 31, 2011 8:35 pm     Reply with quote

I found that out today and am using STREAM now, it's much cleaner this way.

Cheers!
_________________
Vinnie Ryan
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