18f4550's_USART_AND_HC_05_BLUETOOTH_MODULE_TEST
Alternate LED whenever receiving 1.
#define Led PORTB.F1
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
char Uart_Rd;
char Blink_Rate;
void main()
{
Led=1;
TRISB=0;
ADCON1=0xff;
OSCCON=0xff;
TRISC.f7=1; //Rx
TRISC.f6=0; //Tx
UART1_Init(9600);
delay_ms(100);
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
// Lcd_Out(1,1,"Rec:");
// Lcd_Out(2,1,"Tra:");
while (1)
{ // Endless loop
if (UART1_Data_Ready()) // If data is received,
{
uart_rd = UART1_Read(); // read the received data,
UART1_Write(uart_rd); // and send data via UART
if(uart_rd=='1')
{
Led=~Led;
Lcd_Cmd(_LCD_CLEAR);
if(Led==1) Lcd_Out(1,5,"LED_ON");
else Lcd_Out(1,5,"LED_OFF");
}
}
}
}
Comments
Post a Comment