Sunteți pe pagina 1din 3

void main() { Delay_ms(1000); UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(500); // Wait for UART module to stabilize

UART1_Write_Text("AT+CMGF=1"); //text mode UART1_Write(0x0D); //<cr> mean (ENTER) delay_ms(300); UART1_Write_Text("AT+CMGS="); //AT command for sending SMS UART1_Write(0x22); //Write (") UART1_Write_Text("+639084132492"); //Cell number to send the SMS UART1_Write(0x22); //Write (") UART1_Write(0x0D); //<cr> mean (ENTER) Delay_ms(1000); //Delay UART1_Write_Text("hi monarjay11"); UART1_Write(26); //Write "ctrl+z" }

code 2 /*Header******************************************* ********** Microcontroller=16f877 Clock=10 Mhz Project Title:Air Pollution Control Using GSM/GPRS Developed By:Sathiesh Kumar.V Date:31/01/2010*/ void Calculation(unsigned int ) ; void Gsm_SMS_Init(); void Gsm_SMS_Read(); void Gsm_SMS_Send(); // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections unsigned char ch; // char Receive; unsigned int adc_rd; // Declare variables char *text; // long tlong; // unsigned int i,j; char return_gsm[2]; char Gsm_Receive[100]; char Gsm_Msg[10]; char uart_rd[]="AT"; char uart_rd1[]="AT+CMGF=1"; char uart_rd2[]="AT+CMGR=1" ; char uart_rd3[]="AT+CMGS="; char Mobile_No[]="+919444721638" ; char Send_Msg[]="@ON"; void main()

{ INTCON = 0; // All interrupts disabled ADCON1 = 0x82; // A/D voltage reference is VCC TRISA = 0xFF; // All port A pins are configured as inputs //TRISC=0x01; Delay_ms(2000); // Rest of pins are configured as digital UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize Lcd_Init(); // LCD display initialization Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off) Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD) text = "Air Pollution "; // Define the first message Lcd_Out(1,1,text); // Write the first message in the first line delay_ms(500); text = "Sensor Value"; // Define the second message Lcd_Out(2,1,text); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR);

text = "GSM"; // Define the third message while (1) { Lcd_Out(1,1,text); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); Gsm_SMS_Init(); } } void Gsm_SMS_Init() { if (UART1_Tx_Idle() == 1) { for(i=0;i<=1;i++) { UART1_Write(uart_rd[i]); //AT } UART1_Write(0x0D); //Enter Lcd_Out(2,1,"AT"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); //delay_ms(5000); while(1) { if (UART1_Data_Ready()) { // If data is received, for(i=0;i<=1;i++) { return_gsm[i] = UART1_Read(); // read the received data, Received OK } Lcd_Out(2,1,"OK"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); /* UART1_Write(return_gsm[0]); Lcd_Out(2,1,"OK RESEND"); // Define the first message

delay_ms(500); Lcd_Cmd(_LCD_CLEAR); */ // UART1_Write(return_gsm[1]); } } /*if(return_gsm[0]==0x4F && return_gsm[1]==0x4B) { if (UART1_Tx_Idle() == 1) { for(i=0;i<=8;i++) { UART1_Write(uart_rd1[i]); //AT+CMGF=1 } UART1_Write(0x0D); //Enter Lcd_Out(1,1,"AT+CMGF=1"); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } if (UART1_Data_Ready()) { // If data is received, for(i=0;i<=1;i++) { return_gsm[i] = UART1_Read(); // read the received data,OK } Lcd_Out(2,1,"Received OK"); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } } */ } }

S-ar putea să vă placă și