/[H9]/trunk/Embedded/main.c
ViewVC logotype

Diff of /trunk/Embedded/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 175 by hedin, Thu Dec 6 13:36:07 2007 UTC revision 201 by hedin, Sun Dec 9 15:07:32 2007 UTC
# Line 6  Line 6 
6    
7  #include "lcd.h"  #include "lcd.h"
8  #include "Delay.h"  #include "Delay.h"
 // Delay.h is included inside lcd.c  
9    
 #define LCD_LENGTH 16  
 #define LCD_ROWS 2  
10  #define BUFFER 128  #define BUFFER 128
11  #define PWRFAIL RB1  #define PWRFAIL RB1
12  #define FIREDET RB2  #define FIREDET RB2
# Line 33  unsigned char global_message_buffer_leng Line 30  unsigned char global_message_buffer_leng
30    
31  unsigned char global_lcd_buf[16];  unsigned char global_lcd_buf[16];
32    
33  unsigned short global_imei_tversum;  unsigned int global_imei_tversum;
34    
35  unsigned char global_cell_nr[15] = ""; // = "21681784";  unsigned char global_cell_nr[15] = ""; // = "21681784";
36  bit global_modem_init = 0;  bit global_modem_init = 0;
# Line 154  void rs232_init(void) Line 151  void rs232_init(void)
151          RCSTA   = 0x90; // 0x90 enables SPEN and CREN in the RCSTA register          RCSTA   = 0x90; // 0x90 enables SPEN and CREN in the RCSTA register
152  }  }
153    
154  void sms_init(void)  void modem_init(void)
155  {  {
156          int i;          int i;
157          char buf[2];          char buf[2];
# Line 183  void sms_init(void) Line 180  void sms_init(void)
180    
181          sprintf(global_serial_send,"%s", "at+cpin?\r");          sprintf(global_serial_send,"%s", "at+cpin?\r");
182          serial_send();          serial_send();
183          DelayMs(100);           // To give the modem a chance to answer.          DelayMs(100);           // Delay to give the modem a chance to answer.
184                    
185          if (strstr(global_message_buffer1, "+CPIN: SIM PIN") != 0)          if (strstr(global_message_buffer1, "+CPIN: SIM PIN") != 0)
186          {          {
# Line 217  void serial_send(void) Line 214  void serial_send(void)
214          DelayMs(150);          DelayMs(150);
215          global_serial_send[0] = 0;          global_serial_send[0] = 0;
216          DelayMs(150);          DelayMs(150);
217  }        }
218    
219    void on_initial_recieve(void)
220    {
221            char imei[16];
222            char* ptr;
223            char i;
224            char buf[2];
225            
226            if (strstr(global_serial_recieve_buffer,"+WIND: 11") != 0)
227            {
228                    global_modem_init = 1;
229    
230                    ptr = strstr(global_serial_recieve_buffer,"cgsn");
231                    ptr +=4;
232                    strncpy(imei, ptr,15);
233                    imei[15] = 0;
234                    
235                    reset_recieve_buffer();
236            }
237    }
238    
239  //////////  INTERRUPT HANDLER  //////////  //////////  INTERRUPT HANDLER  //////////
240  void interrupt interrupt_handler(void)  void interrupt interrupt_handler(void)
241  {  {
# Line 319  void send_sms(const unsigned char* paylo Line 337  void send_sms(const unsigned char* paylo
337          sprintf(global_serial_send, "%s%c", payload, 0x1A);          sprintf(global_serial_send, "%s%c", payload, 0x1A);
338          serial_send();          serial_send();
339          DelayMs(150);          DelayMs(150);
340          if(global_sms_counter % 3 == 0)          if(global_sms_counter % 4 == 0)
341          {          {
342                  eeprom_writer();                  eeprom_writer();
343                  sprintf(global_serial_send, "at+cmgd=1,3\r");                  sprintf(global_serial_send, "at+cmgd=1,3\r");
# Line 328  void send_sms(const unsigned char* paylo Line 346  void send_sms(const unsigned char* paylo
346          }          }
347  }        }      
348    
349  void convertTemp()  void convert_temp()
350  {  {
351          short adVal;          short adVal;
352          adVal = (global_Pot_Hi << 8) | global_Pot_Lo;          adVal = (global_Pot_Hi << 8) | global_Pot_Lo;
# Line 373  void eeprom_reader(void) Line 391  void eeprom_reader(void)
391          global_cell_nr[i] = 0; //zero terminated!          global_cell_nr[i] = 0; //zero terminated!
392  }        }      
393    
 void on_initial_recieve(void)  
 {  
         char imei[16];  
         char* ptr;  
         char i;  
         char buf[2];  
           
         if (strstr(global_serial_recieve_buffer,"+WIND: 11") != 0)  
         {  
                 global_modem_init = 1;  
   
                 ptr = strstr(global_serial_recieve_buffer,"cgsn");  
                 ptr +=4;  
                 strncpy(imei, ptr,15);  
                 imei[15] = 0;  
                   
                 reset_recieve_buffer();  
         }  
 }  
394    
395  void on_recieve(void)  void on_recieve(void)
396  {  {
# Line 405  void on_recieve(void) Line 404  void on_recieve(void)
404          if (strstr(global_message_buffer1,"CMTI") != 0) // here we handles a incomming SMS          if (strstr(global_message_buffer1,"CMTI") != 0) // here we handles a incomming SMS
405          {          {
406                  ptr = strstr(global_message_buffer1,",");       // finds the point just before the nr. of the SMS.                  ptr = strstr(global_message_buffer1,",");       // finds the point just before the nr. of the SMS.
407                  strcat(tmp,ptr+1);                                                      // puts that number in tmp                  strcat(tmp,ptr+1);                      // puts that number in tmp
408                  global_sms_recieve_number[0] = 0;                       // wanna be sure that we write the new number from global_sms_recieve_number[0]                  global_sms_recieve_number[0] = 0;       // wanna be sure that we write the new number from global_sms_recieve_number[0]
409                  strcat(global_sms_recieve_number, tmp);         // puts the sms number into the global variable.                  strcat(global_sms_recieve_number, tmp); // puts the sms number into the global variable.
410                  sms_recieved();                  sms_recieved();
411          }                }      
412          reset_recieve_buffer();          reset_recieve_buffer();
# Line 455  void sms_recieved(void) Line 454  void sms_recieved(void)
454                                    
455                  global_time_interval = atoi(buf);                  global_time_interval = atoi(buf);
456                  global_time_interval *= 60;                  global_time_interval *= 60;
457                  eeprom_writer();                        // writes the new cell nr. and time interval to the eeprom.                  eeprom_writer();  // writes the new cell nr. and time interval to the eeprom.
458                  send_sms("conf ok");                  send_sms("conf ok");
459          }          }
460                    
# Line 476  void main() Line 475  void main()
475    
476          // Running init for various components.          // Running init for various components.
477          pic18_io_init();          pic18_io_init();
478          RA5 = 1;                        // Indicates that the board is running inits.          RA5 = 1;                // Indicates that the board is running inits.
479                    
480          rs232_init();          rs232_init();
481          ad_init();          ad_init();
# Line 485  void main() Line 484  void main()
484          lcd_home();          lcd_home();
485          interrupt_init();          interrupt_init();
486          timer_init();          timer_init();
487          sms_init();          modem_init();
488          eeprom_reader();          eeprom_reader();
489  ///////////////  ///////////////
490  // Main loop //  // Main loop //
# Line 525  void main() Line 524  void main()
524                  {                  {
525                          global_Pot_Hi = ADRESH;                          global_Pot_Hi = ADRESH;
526                          global_Pot_Lo = ADRESL;                          global_Pot_Lo = ADRESL;
527                          convertTemp();                          convert_temp();
528                          update_lcd();                          update_lcd();
529                          GODONE = 1;                          GODONE = 1;
530                  }                  }

Legend:
Removed from v.175  
changed lines
  Added in v.201

  ViewVC Help
Powered by ViewVC 1.1.20