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 send and transmit data by using serial port

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



Joined: 06 Apr 2010
Posts: 13

View user's profile Send private message

problem with send and transmit data by using serial port
PostPosted: Tue Apr 06, 2010 1:44 am     Reply with quote

HI, I'm a new user for CCS compiler. Can anyone can check the following code? Why the PIN_B6 can't be turned on although I have sent the char "1" from my computer to PIC?? Anyone can guide me about it?? Thanks
Code:

#include <16F877A.h>
#include <string.h>
#use delay(clock=20000000)

#define REDLED PIN_B4
#define GREENLED PIN_B6
#define YELLOWLED PIN_B3

#use rs232 (baud = 9200,xmit=PIN_C6, rcv=PIN_C7)
#fuses HS,NOWDT,NOPROTECT,NOLVP

char ch;

void main()
{
      ch= getc();

      if (ch == "1")
      {
      set_tris_b(0b00);
   
      output_High(GREENLED);
     
      }
     
}
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 2:03 am     Reply with quote

Try this.

Code:

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232 (baud = 9200,xmit=PIN_C6, rcv=PIN_C7)
#include <string.h>

#define REDLED PIN_B4
#define GREENLED PIN_B6
#define YELLOWLED PIN_B3

 

char ch;

void main()
{
  set_tris_b(0x00);
  while(1)
  {
   ch= getc();
   if (ch == "1")
   {
     output_toggle(GREENLED);
   }
  }
}
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 2:09 am     Reply with quote

Your first problem is that in C to represent a single char you use single quotes '

So you should do:-

if (ch == '1')
thiam



Joined: 06 Apr 2010
Posts: 13

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 8:56 am     Reply with quote

i have try the code but still have the problem... Confused ... what wrong with the code?? anyone pls help me??
Ttelmah



Joined: 11 Mar 2010
Posts: 19330

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 8:59 am     Reply with quote

Start with the code:
Have you corrected the test, as Wayne pointed out. This is vital.
Then, are you sure about your baud rate?. 9200bps, is 'non standard'. 9600bps, is the nearest standard setting.
Then are you sure about your hardware. RS232 transceiver chip?. Correctly wired?. Have you tested that the processor is actually running, and running at the right speed (toggle an LED at one second intervals - is it actually working at the right interval?). Can you send a 'hello world' message to the PC over the serial?.

Best Wishes
thiam



Joined: 06 Apr 2010
Posts: 13

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 10:13 am     Reply with quote

Thanks for you all. I have corrected the code and changed the baud rate to 9600. About the hardware, I use UC00A which is USB-UART converter from Cytron. I have tried the code again but still have the same problem. Ttelmah, can you give me a sample code?? Thank you very much.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 10:32 am     Reply with quote

Do you have an RS232 interface transceiver on the PIC though?


In order to hook a PIC to an RS232 port, say on a PC, you must meet the voltage requirements needed by RS232 standards.

This is typically accomplished with an interface IC like the MAX232 or in the needs of only TX/RX, a MAX221.

If you are connecting your PIC directly to an RS232 port (via USB or backpanel connector), you are most likely injecting >+5VDC and <0VDC to the pins on your RX line, while your TX line is seen as a marginal/erroneous transmitter to the PC.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
thiam



Joined: 06 Apr 2010
Posts: 13

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 11:32 am     Reply with quote

thanks guys... finally i have done.. the problem is the baud rate and the hardware... thanks Smile
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