I m using XCTU and send the packet.
At the send packet box. I just send 1 byte that is 1 or in hex "0x31".
Below is my code for the PIC. Correct me if I had done the mistake.
- CODE: SELECT_ALL_CODE
void uart_init(void)
{
SPBRG=129; //set baud rate as 9600 baud
TXSTA.BRGH=1; //baud rate high speed option
TXSTA.TXEN=1; //enable transmission
TXSTA.TX9 =0; //8-bit transmission
RCSTA.RX9 =0; //8-bit reception
RCSTA.CREN=1; //enable reception
RCSTA.SPEN=1; //enable serial port
}
unsigned char uart_rec(void) //receive uart value
{
unsigned int rec_data;
while(PIR1.RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the data received
}
void main() {
ANSEL = 0;
ANSELH = 0;
T2CON = 0x04;
TrisE = 0;
PortE = 0;
uart_init();
Delay_ms(200);
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100)
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
while (1) { // Endless loop
uart_rd = uart_rec();
if(uart_rd == '1'){
portE = 0x01;
delay_ms(1200);
portE = 0;
}
else if(uart_rd == '2'){
portE = 0x02;
delay_ms(1200);
portE = 0;
}
else
UART1_Write_Text("No input");
UART1_Write(13);
delay_ms(2000);
}
}
I want to light up the LED at port E if receiving '1' or '2' from SKXBEE but it seem like couldnt work.
Can anyone gives me any advice or where should I troubleshoot. Thanks.