PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 23, 2008 6:24 pm |
|
|
The #use rs232() statement is used to setup the UART.
After that, you can use printf, putc, getc, and other functions to
send and receive bytes.
How to send a string of characters:
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void main()
{
while(1)
{
printf("Hello World\n\r");
}
} |
How to send and receive individual characters:
Code: | #include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//============================
void main()
{
char c;
while(1)
{
c = getc(); // Get char from PC
putc(c); // Send it back to PC
}
} |
How to send an array of bytes:
http://www.ccsinfo.com/forum/viewtopic.php?t=33383&start=3 |
|