Hey guys,
I would like to ask all of u to give opinion on my tx and rx code. I don't know whether it is correct or not. Thank you.
1. tx
#include <18F4550.h>
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, MCLR, NOLVP, NOPROTECT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, STREAM=PIN_A1)
void main()
{
while(1)
{
getc(PIN_A1);
delay_ms(20);
putc('T');
delay_ms(20);
output_high(PIN_A1);
delay_ms(100);
output_low(PIN_A1);
delay_ms(100);
}
}
2. rx
#include <18F4550.h>
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, MCLR, NOLVP, NOPROTECT
#use delay(clock=8000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8,ERRORS,STREAM=COM_A)
unsigned int8 data;
int1 flag=0;
#int_rda
void rd_isr(void)
{
//disable_interrupts(INT_RDA); // Disable Serial Recieve Interrupt
//disable_interrupts(GLOBAL); // Disable Global Interrupts
data= fgetc(COM_A);
if(data=='T')
{
flag=1;
}
//enable_interrupts(GLOBAL);
//enable_interrupts(INT_RDA);
}
void main()
{
enable_interrupts(global);
enable_interrupts(int_rda);
while(true)
{
if(flag==1)
{
output_high(PIN_B6);
delay_ms(100);
output_low(PIN_B6);
delay_ms(100);
flag=0;
}
else
{
delay_ms(100);
delay_ms(20);
fputc('T',COM_A);
delay_ms(20);
delay_ms(100);
}
output_high(PIN_B2);
delay_ms(100);
output_low(PIN_B2);
delay_ms(100);
}
}