//PROGRAMM FOR rs232 communication//// PROCESSOR : PIC16F688// CLOCK : 20MHz, EXTERNAL// SPEED : 9600 bps(1bit=104us)
#include <pic.h>
__CONFIG(WDTDIS & MCLREN & BORDIS & HS & PWRTEN & FCMDIS & IESODIS) ;
unsigned char ch;
void InitUsart(void) {
// TX Pin - output
TRISC4 = 0;
// RX Pin - inputT
RISC5 = 1;
// RX Setting, 8bit, enable receive,
RCSTA = 0x90;
// TX Setting, 8bit, Asinchronius mode, High speed
TXSTA = 0x24;
// Baudcontrol - disable auto mode, 8bit baudrate
BAUDCTL = 0x00;
// Set Baudrade - 9600 (from datasheet baudrade table)
SPBRG = 129;
}
void WriteByte(unsigned char byte) {
while(!TXIF);
TXREG = byte;
}
unsigned char ReadByte(void) {
while(!RCIF);
return RCREG;
}
// main functionvoid
main( void ) {
// Init Interface
InitUsart();
while(1) { ch = ReadByte(); //wait to receive character
WriteByte(ch); //send it back followed by “*”
WriteByte('*');
}
}
[code]