mldt28
Newbie level 6
- Joined
- Feb 20, 2013
- Messages
- 14
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,401
guys pls help me with my code... i can't send sms through gsm modem using a PIC18f4550
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 // LCD module connections sbit LCD_RS at RB0_bit; sbit LCD_EN at RB1_bit; sbit LCD_D4 at RB2_bit; sbit LCD_D5 at RB3_bit; sbit LCD_D6 at RB4_bit; sbit LCD_D7 at RB5_bit; sbit LCD_RS_Direction at TRISB0_bit; sbit LCD_EN_Direction at TRISB1_bit; sbit LCD_D4_Direction at TRISB2_bit; sbit LCD_D5_Direction at TRISB3_bit; sbit LCD_D6_Direction at TRISB4_bit; sbit LCD_D7_Direction at TRISB5_bit; //End of LCD Initialization //GSM Modem AT Commands const unsigned char AT_CMGF1[] = "AT+CMGF=1\r"; const unsigned char AT_CMGD[] = "AT+CMGDA=1\r"; const unsigned char AT_CSQ[] = "AT+CSQ\r"; const unsigned char AT_CMGF[] = "AT+CMGF=0\r"; const unsigned char AT_CMGL[] = "AT+CMGL\r"; const unsigned char AT[] = "AT\r"; const unsigned char ATE0[] = "ATE0\r"; //!< Echo off const unsigned char AT_CNMI[] = "AT+CNMI=1,1,,,1\r"; //!< Identification of new sms const unsigned char AT_CPMS[] = "AT+CPMS=\"ME\",\"ME\",\"ME\"\r"; //!< Preferred storage const unsigned char AT_CMGS[] = "AT+CMGS=\"09184637272\"\r"; void Init(); void main() { char dat, err, ptr, extra[10], kwdata[10], kwhdata[10], kwsumEEP; unsigned char mybuff[54], mypbuff = 0; float wattsec_ = 0; float total = 0; float ave = 0; float ave2 = 0; float kw =0; float kwh =0; float kwhsum = 0; int count = 0; int count2 =0; /*===========Declarations============*/ TRISD=0; PORTB=0; PORTD=0; TRISB = 0; ADCON1 = 0x0F; /*====================================*/ /*===========Initialization and Main Display===========*/ Init(); Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,2, "Energy Monitoring"); Lcd_Out(2,8, "System"); Lcd_Out(4,1, "AROMAMI"); delay_ms(5000); /*======================================================*/ /*==Executions of Data Fetching, Calculations, Sending==*/ for(;;) { while(1) { do{ dat = Soft_Uart_Read(&err); }while(err); if(dat == 'O'){ break; } if((mypbuff == 0) && (dat != 'I')){ continue; } mybuff[mypbuff++] = dat; if(mypbuff == 53) { ptr = strtok(mybuff, ","); //mybuff here contains the string from power analyzer module ptr = strtok(0, ","); // ptr now contains string of watts count++; total += wattsec_; wattsec_ = atof(ptr); kw = wattsec_/1000; kwh = kw/3600; kwhsum += kwh; sprintf(kwdata, "%.2f", kw); //FloatToStr(kw,kwdata); sprintf(kwhdata, "%.2f", kwhsum); //FloatToStr(kwhsum,kwhdata); if((count % 5) == 0){ ave = total / 1000; ave2 = ave / 3600; //to kph /30 secs sprintf(extra, "%.10f", ave2); // to GSM modem //FloatToStr(ave2, extra); THIS IS THE AREA WHERE I DONT REALLY KNOW WHAT TO DO... pls help me guys // send to gsm program************************************************************* uart1_write(ATE0); uart1_write(0x0A); uart1_write(0x1A); delay_ms(500); UART1_Write(AT_CMGF1); UART1_Write(13); //Enter key = CF + LF UART1_Write(10); delay_ms(500); UART1_Write(AT_CMGS); UART1_Write(13); //Enter key = CF + LF UART1_Write(10); delay_ms(500); UART1_Write(extra); UART1_Write(0x1A); // <ctrl-z> delay_ms(3000); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1, "SENT"); ave = 0; ave2 = 0; total = 0; count = 0; delay_ms(2000); } Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1, "KW: "); Lcd_Out(1,5, kwdata); Lcd_Out(2,1, "KW/hour: "); Lcd_Out(2,10, kwhdata); Lcd_Out(3,1, "Ave/30s: "); Lcd_Out(3,10, extra); Uart1_Write_Text(kwdata); mypbuff = 0; break; } } } } /*=====================================================*/ void COM_puts(const unsigned char *cmd) { while(*cmd) UART1_Write(*cmd++); } void Init() { Soft_UART_Init(&PORTD,1,0,9600,0); // initialize serial extra port UART1_Init(2500); // initializes GSM Delay_ms(1000); COM_puts(ATE0); // gsm mode: echo off Delay_ms(350); COM_puts(AT_CMGF1); Delay_ms(350); COM_puts(AT_CMGS); Delay_ms(350); //COM_puts(AT_CPMS); //Delay_ms(350); //COM_puts(AT_CNMI); //Delay_ms(1000); //COM_puts(AT_CMGD); //Delay_ms(2000); }
Last edited by a moderator: