2007 20 Nov
This test will be part of one of the main module that I will need to communicate between PC and all sensors/modules. I want for the PC from the robot to communicate with one Master PIC by RS232, exchanging commands and information to/from sensors/modules. Than the Master PIC will make the interface to all sensor/modules by I2C Bus.
Still have a lot of work to do on the H-Bridge module, and the I2C Bus, but decided to test RS232! It was fun to play with and my test worked well!
I’ve just assembled on a test board this simple circuit:
Then I’ve made the PicC code to test RS232 communication:
-
#include <16F628A.h>
-
#use delay(clock=4000000)
-
#use rs232(baud=9600, parity=N, xmit=PIN_B2, rcv=PIN_B1,bits=8,errors)
-
-
#fuses NOWDT,XT, PUT, NOPROTECT, BROWNOUT, MCLR, NOLVP, NOCPD
-
// PORTB.1 [RB1 pin7] -> PicRX (RS232 input)
-
// PORTB.2 [RB2 pin8] -> PicTX (RS232 output)
-
// PORTB.4 [RB4 pin10] -> Led Test
-
//————————————————————————————————————————————————————————————
-
void main()
-
{
-
int8 rx_char;
-
-
setup_comparator(NC_NC_NC_NC);
-
setup_vref(FALSE);
-
set_tris_a(0b11111111);
-
set_tris_b(0b11101011);
-
-
output_low(PIN_B4);
-
-
while(TRUE)
-
{
-
if(kbhit()) // test is any data has arrived by RS232 interface
-
{
-
rx_char = getc(); // fetch char from RS232 -> PC
-
rx_char = rx_char + 1; // will convert char to is next value
-
// if ‘a’ was received will send ‘b’
-
putc(rx_char); // send new char to PC
-
-
output_high(PIN_B4); // will blink external led for 0.5 seconds
-
delay_ms(500);
-
output_low(PIN_B4);
-
delay_ms(500);
-
}
-
}
-
}
To test communication between PC and PIC I’ve used WinCommV1.2 at 9600 bps with 8 data bits, 1 stop bit, No parity, but hyper-terminal should be fine!