yogeshnand
Newbie level 4
hi
my task is simply check the received message from particular number, if yes then relay will be operated and there is acknowledgement message from sim800 module to sender that inform that
relay has operated .
my problem message function i can operate relay but as i inserted a function to send a message
code will not work properly, why this happening i could not understand
please help me out
my task is simply check the received message from particular number, if yes then relay will be operated and there is acknowledgement message from sim800 module to sender that inform that
relay has operated .
my problem message function i can operate relay but as i inserted a function to send a message
code will not work properly, why this happening i could not understand
please help me out
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 /////////////////////////////////////////// //LCD decleration// #define LCD_DIR TRISD #define CTRL_DIR1 TRISB.F0 #define CTRL_DIR2 TRISB.F1 #define LCD_DIR TRISD #define LCD PORTD #define RS PORTB.F0 #define E PORTB.F1 #include"lcd.h" ////////////////////////////////////////////////////// #define STRLEN 55 volatile unsigned char flag=0; unsigned char flag1=0; unsigned char t; volatile unsigned char rcindex; volatile unsigned char rcbuf[STRLEN]; unsigned char num[]="918208996450"; unsigned char i,j; unsigned char rcvd[13]; unsigned char Msg[]="Relay On"; void UART_Init(void) { TXSTA.TXEN=1; // enable transmitter TXSTA.BRGH=1; // enable high baud rate RCSTA.CREN=1; // continuous data receiption //configure input output TRISC.TRISC6=1; // rRX pin as a input TRISC.TRISC7=1; // TX pin as a input TRISC.TRISC0=1; SPBRG=103; // set buad rate 9600 PIE1.RCIE=1; //enable USART receive interrupt RCSTA.SPEN=1; //enable USART } ///////////Initialise Message/////////////// void Init_Msg() { UART1_Write_Text("AT\r\n"); // turn disable the echo delay_ms(500); UART1_Write_Text("AT+CMGF = 1\r"); // set text mode Delay_ms(100); UART1_Write_Text("AT+CMGS="+918446323311"\r"); delay_ms(500); UART1_Write_text("Relay Opearted \r"); UART1_Write(26); UART1_Write(0x1A); } void main() { INTCON.PEIE=1; //enable interrupt INTCON.GIE=1; // enable globle interrupt CTRL_DIR1=CTRL_DIR2=0X00; LCD_DIR=0X00; TRISB.F6=0x00; TRISB.F7=0xFF; init_lcd(); delay_ms(500); //Init_gsm(); UART_Init(); delay_ms(500); UART1_Write_Text("ATE0\r\n"); // turn disable the echo delay_ms(500); delay_ms(500); UART1_Write_Text("AT+CMGF = 1\r"); // set text mode Delay_ms(1000); UART1_Write_Text("AT+CNMI=2,2,0,0,0\r"); Delay_ms(1000); cmd_lcd(0x80); string_lcd("Init Complete"); while(1) { if(flag) //if flag is set execute the below command { // check(); //cmd_lcd(0x80); //string_lcd(rcbuf); for(i=8;i<20;i++) {rcvd[i-8]=rcbuf[i];} //get the number if(rcvd[0]=='9') //compare with predefined number { if(rcvd[1]=='1') { if(rcvd[2]=='8') { if(rcvd[3]=='2') { if(rcvd[4]=='0') { if(rcvd[5]=='8') { if(rcvd[6]=='9') { if(rcvd[7]=='9') { if(rcvd[8]=='6') { if(rcvd[9]=='4') { cmd_lcd(0x80); string_lcd(rcbuf); PORTB.F6=1; delay_ms(5000); Init_Msg(); //if yes relay opearateed // INTCON.PEIE=0; //enable interrupt // INTCON.GIE=0; /*delay_ms(1000); Init_Msg(); delay_ms(2000);*/ /*INTCON.PEIE=1; //enable interrupt INTCON.GIE=1;*/ //flag1=1; }}}}}}}}}} flag=0; //set the falg to zero } if(PORTB.F7==0) {PORTB.F6=0;} } } void interrupt(void) { if(PIR1.RCIF) //check the receive interrupt flag has fired { t=RCREG; if((t!='\n')&&(rcindex<STRLEN)) //check the new line ,if not found save the string to rcbuf { rcbuf[rcindex]=t; if(rcbuf[0]=='+') //check the '+' char ,if yes increment rcindex { rcindex++; } else //if not ,reset the rcindex ,flag to zero { rcindex=0; //reset string index flag=0; } } else //if new line found reset the rcindex and set he flag { flag=1; rcindex=0;} } //PIR1.RCIF=0; //it is read only }