Mithun_K_Das
Advanced Member level 3

- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 27
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,254
I was working reading a SMS from SIM300cz GSM module. MCU: PIC16F73. I did some other projects SMS sending with this setup. They all works so fine. Even this one works fine too in SMS Sending. But I don't know where I made a mistake with code, it can not read anything from UART.
Can anyone tell me where I did the mistake? I'm simulating the system in real time hardware. Also I simulated it, it can not read any thing in the uart terminal.
Thanks in advance.
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 /******************************************************************************* * Program for 'GSM Based Traffic Signal Control System' * * Compiler: MicroC Pro for PIC v.5.6.1 * * Program Written by Engr. Mithun K. Das * * e-mail: [email]mithun060@gmail.com[/email]; 01722448270 * * MCU: PIC16F73B; X-Tal:8MHz(internal) * * 18-Apr-2015 * *******************************************************************************/ // LCD module connections sbit LCD_RS at RB7_bit; sbit LCD_EN at RB6_bit; sbit LCD_D4 at RB5_bit; sbit LCD_D5 at RB4_bit; sbit LCD_D6 at RB3_bit; sbit LCD_D7 at RB2_bit; sbit LCD_RS_Direction at TRISB7_bit; sbit LCD_EN_Direction at TRISB6_bit; sbit LCD_D4_Direction at TRISB5_bit; sbit LCD_D5_Direction at TRISB4_bit; sbit LCD_D6_Direction at TRISB3_bit; sbit LCD_D7_Direction at TRISB2_bit; // End LCD module connections unsigned char text[64]; int i = 0; short ready = 0; char *string; void UART_Write_CText(const char *cptr) { char chr; for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr); } void Lcd_COut(char row, char col, const char *cptr) { char chr = 0; //first, it is used as empty string Lcd_Out(row, col, &chr); //nothing to write but set position. for ( ; chr = *cptr ; ++cptr ) Lcd_Chr_CP(chr); //out in loop } void Delay2s() { int d; for(d=0;d<200;d++) { Delay_ms(10); } } void Send_SMS_Int(void); void Read_SMS_Int(void); void interrupt() { if (RCIF_bit) { // If interrupt is generated by RCIF text[i] = UART1_Read(); // Read data and store it to txrt string i++; // Increment string index if (i >= 60) { i = 0; // set it to zero ready = 1; // Ready for parsing GPS data } RCIF_bit = 0; // Set RCIF to 0 } } void main() { TRISA = 0x00; TRISC = 0x00; PORTA = 0x00; PORTC = 0x00; ADCON0 = 0x00; ADCON1 = 0x07;//all digital Lcd_Init();//initialize LCD Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_COut(1,1,"SMS BASED TRFc."); Lcd_COut(2,2,"SIGNAL CONTROL"); Delay_ms(2000); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"INITIALIZING..."); Lcd_COut(2,1,"UART(9600)"); UART1_Init(9600);//initialize UART at br 9600 bps Delay_ms(3000);// leave some time for UART Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"INITIALIZING..."); Lcd_COut(2,1,"RCIF INTERRUPT"); GIE_bit = 1; // Enable Global interrupt PEIE_bit = 1; // Enable Peripheral interrupt RCIE_bit = 1; // Enable USART Receiver interrupt Delay_ms(100); Lcd_Cmd(_LCD_CLEAR);//clear display while(1) { OERR_bit = 0;// clear Overrun Error bit FERR_bit = 0;//clear Farming Error bit /*Send_SMS_Int(void); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"Writing data"); Delay2s(); UART_Write_CText("SMS Sending Test"); UART1_Write((char)26); Delay2s(); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"Data sent"); Delay2s();*/ Read_SMS_Int(void); UART_Write_CText("AT\r\n"); }//while(1) }//void main void Send_SMS_Int(void) { RCIE_bit = 0;//Disable RCIE Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"SENDING SMS... "); Delay2s(); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"SELECT SMS MODE"); Lcd_COut(2,1,"AT+CMGF=1"); Delay2s(); UART_Write_CText("AT+cmgf=1\r\n"); Delay2s(); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"SET NUMBER"); Lcd_COut(2,1,"AT+CMGS=`NUMBER`"); Delay2s(); UART_Write_CText("AT+cmgs="); UART1_Write((char)'"'); UART_Write_CText("01722448270"); UART1_Write((char)'"'); UART1_Write((char)13); UART1_Write((char)10); Delay2s(); } void Read_SMS_Int(void) { again: Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"READING SMS... "); Delay2s(); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"SELECT SMS MODE"); Lcd_COut(2,1,"AT+CMGF=1"); Delay2s(); UART_Write_CText("AT+CMGF=1\r\n"); //select SMS mode Delay2s(); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"SET LOCATION 2"); Lcd_COut(2,1,"AT+CNMI=2,1"); Delay2s(); UART_Write_CText("AT+CNMI=2,1\r\n"); //select memory bank 2 Delay2s(); Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"ENGLISH SMS ONLY"); Lcd_COut(2,1,"AT+CSCS=`GSM`"); Delay2s(); UART_Write_CText("AT+CSCS="); //select only English UART1_Write((char)'"'); UART_Write_CText("GSM"); UART1_Write((char)'"'); UART1_Write((char)13);//send Enter Delay2s(); ready = 0; //clear ready Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"READ LOCATION 2"); Lcd_COut(2,1,"AT+CMGR=2"); Delay2s(); memset(text, '\ ', sizeof(text));//clear text in each table i = 0; // set it to zero GIE_bit = 1; PEIE_bit = 1; RCIE_bit = 1;//Enable RCIE RCIF_bit = 0;//clear flag UART_Write_CText("AT+CMGR=2\r\n"); Delay2s(); Delay2s(); if(ready==1) { // if data is received ready = 0; //clear ready Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"SMS READING OK"); Delay2s(); UART_Write_CText("SMS DATA:\n"); for(i=0;i<75;i++) { UART1_Write_Text(text[i]); Delay_ms(5); } UART_Write_CText("END \n"); UART_Write_CText("AT\r\n"); Delay2s(); Delay2s(); //Delay2s(); //Lcd_Cmd(_LCD_CLEAR);//clear display //Lcd_COut(1,1,"DELETE SMS AT 2"); //Lcd_COut(2,1,"AT+CMGD=2"); //Delay2s(); //UART_Write_CText("AT+CMGD=2\r\n"); Delay2s(); } else { Lcd_Cmd(_LCD_CLEAR);//clear display Lcd_COut(1,1,"IF SMS NOT FOUND"); Lcd_COut(2,1,"READ AGAIN"); Delay2s(); goto again; } } //end of the program
Can anyone tell me where I did the mistake? I'm simulating the system in real time hardware. Also I simulated it, it can not read any thing in the uart terminal.
Thanks in advance.