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 support@ccsinfo.com

Problem with serial communication

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



Joined: 01 Aug 2008
Posts: 2

View user's profile Send private message

Problem with serial communication
PostPosted: Fri Aug 01, 2008 1:04 pm     Reply with quote

Hi everyone, I'm new at ccs compiler and now I've got a big problem with rs-232 communication. I can transmit from pic to pc but when i want to recieve from pc to pic I dónt know what I´m doing wrong. This is my code:
Code:
   #include <16f877a.h>
   #include "programa.h"
   #fuses XT,NOWDT,NOPUT,NOBROWNOUT,NOPROTECT
   #use delay(clock=4000000)
   #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

   int value=0;

   void main()
   {
      while(1)
      {
          if(kbhit())
         {
             putc('a');
             delay_ms(1000);
         }
      }
   }

Pls I need help with this, what am I doing wrong? The result of this is that the PIC always sends de character "a" every second even if I don´t send something from the pc
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 01, 2008 1:12 pm     Reply with quote

You have to actually remove the character from the hardware UART's
receive buffer. Otherwise it will stay there, in the buffer. kbhit()
does not remove the character. kbhit() only tells you if there is a
character in the buffer. Use getc() to read the character and remove
it from the buffer.

Two more things:

1. Add the ERRORS parameter to your #use rs232() statement.
Always do that. This will prevent the hardware UART receiver from
locking up if you don't read the incoming characters.

2. Add NOLVP to your #fuses statement. On recent versions of the
compiler it's done automatically for you. But if you have a slightly
older version, you probably need to add it. NOLVP will prevent your
PIC from locking up if the PGM pin (pin B3) goes to a high level.
NOLVP disables the "low voltage programming" feature of the 16F877A.
RShankar



Joined: 01 Aug 2008
Posts: 2

View user's profile Send private message

PostPosted: Fri Aug 01, 2008 1:23 pm     Reply with quote

lol ok, first of all thanx for ur help. I finally made it work and noticed that I have to use getc to remove the character from the buffer as u said. The main problem was that I forgot to set PIN C7 as an input so this pin was full of noise and kbhit was always high. Thank u very much
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