// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
//Declare Function
void read_sensor();
void send_msg();
//Declare Variable
int analog_data;
void main()
{
Uart1_init(9600);
delay_ms(100);
ADCON1=0b10000010;
TRISA=0b111111;
ADC_Init();
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
analog_data = 0;
do
{
Lcd_Out(1,1,"Smart Detection");
Lcd_Out(2,1,"System");
read_sensor();
}
while (1);
}
void read_sensor()
{
analog_data = ADC_Read(0);
if (analog_data > 700)
{
send_msg();
}
}
void send_msg()
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Sending Report");
Uart1_Write_Text("AT+CMGS=");
delay_ms(100);
Uart1_write(0x22);
delay_ms(100);
Uart1_Write_Text("0176052241");
delay_ms(100);
Uart1_write(0x22);
delay_ms(100);
Uart1_Write(0x0D);
delay_ms(100);
Uart1_write_Text("9 Jln Tasek Barat 9, Taman Anda 31400, Ipoh Perak");
delay_ms(100);
Uart1_Write(0x0D);
delay_ms(100);
Uart1_Write(26);
delay_ms(100);
Uart1_Write(0x0D);
delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Report Sent");
delay_ms(60000);
}