/[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 205 by hedin, Sun Dec 9 21:01:04 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 48  __EEPROM_DATA( '1', '7', '8', '4',0,0,0, Line 45  __EEPROM_DATA( '1', '7', '8', '4',0,0,0,
45  void serial_recieved(void);  void serial_recieved(void);
46  void serial_send(void);  void serial_send(void);
47  void update_lcd(void);  void update_lcd(void);
48  void convertTemp(void);  void convert_temp(void);
49  void timer1_interrupt(void);  void timer1_interrupt(void);
50  void on_recieve(void);  void on_recieve(void);
51  void on_initial_recieve(void);  void on_initial_recieve(void);
# 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    // can't se what the outcommented lines in here sould do, that make any sence.
222    //      char imei[16];
223    //      char* ptr;
224    //      char i;
225    //      char buf[2];
226            
227            if (strstr(global_serial_recieve_buffer,"+WIND: 11") != 0)
228            {
229                    global_modem_init = 1;
230    
231    //              ptr = strstr(global_serial_recieve_buffer,"cgsn");
232    //              ptr +=4;
233    //              strncpy(imei, ptr,15);
234    //              imei[15] = 0;
235                    
236                    reset_recieve_buffer();
237            }
238    }
239    
240  //////////  INTERRUPT HANDLER  //////////  //////////  INTERRUPT HANDLER  //////////
241  void interrupt interrupt_handler(void)  void interrupt interrupt_handler(void)
242  {  {
# Line 286  void timer1_interrupt(void) Line 305  void timer1_interrupt(void)
305          TMR1L = 0xFF;          TMR1L = 0xFF;
306          global_time_counter++;          global_time_counter++;
307          global_emergency_counter++;          global_emergency_counter++;
308          RA1 = !RA1;  //      RA1 = !RA1;
309  }  }
310  //////////  ORDENARY FUNKTIONS  //////////  //////////  ORDENARY FUNKTIONS  //////////
311  void update_lcd(void)  void update_lcd(void)
# Line 319  void send_sms(const unsigned char* paylo Line 338  void send_sms(const unsigned char* paylo
338          sprintf(global_serial_send, "%s%c", payload, 0x1A);          sprintf(global_serial_send, "%s%c", payload, 0x1A);
339          serial_send();          serial_send();
340          DelayMs(150);          DelayMs(150);
341          if(global_sms_counter % 3 == 0)          if(global_sms_counter % 4 == 0)
342          {          {
343                  eeprom_writer();                  eeprom_writer();
344                  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 347  void send_sms(const unsigned char* paylo
347          }          }
348  }        }      
349    
350  void convertTemp()  void convert_temp(void)
351  {  {
352          short adVal;          short adVal;
353          adVal = (global_Pot_Hi << 8) | global_Pot_Lo;          adVal = (global_Pot_Hi << 8) | global_Pot_Lo;
# Line 373  void eeprom_reader(void) Line 392  void eeprom_reader(void)
392          global_cell_nr[i] = 0; //zero terminated!          global_cell_nr[i] = 0; //zero terminated!
393  }        }      
394    
 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();  
         }  
 }  
395    
396  void on_recieve(void)  void on_recieve(void)
397  {  {
# Line 405  void on_recieve(void) Line 405  void on_recieve(void)
405          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
406          {          {
407                  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.
408                  strcat(tmp,ptr+1);                                                      // puts that number in tmp                  strcat(tmp,ptr+1);                      // puts that number in tmp
409                  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]
410                  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.
411                  sms_recieved();                  sms_recieved();
412          }                }      
413          reset_recieve_buffer();          reset_recieve_buffer();
# Line 455  void sms_recieved(void) Line 455  void sms_recieved(void)
455                                    
456                  global_time_interval = atoi(buf);                  global_time_interval = atoi(buf);
457                  global_time_interval *= 60;                  global_time_interval *= 60;
458                  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.
459                  send_sms("conf ok");                  send_sms("conf ok");
460          }          }
461                    
# Line 476  void main() Line 476  void main()
476    
477          // Running init for various components.          // Running init for various components.
478          pic18_io_init();          pic18_io_init();
479          RA5 = 1;                        // Indicates that the board is running inits.          RA5 = 1;                // Indicates that the board is running inits.
480                    
481          rs232_init();          rs232_init();
482          ad_init();          ad_init();
# Line 485  void main() Line 485  void main()
485          lcd_home();          lcd_home();
486          interrupt_init();          interrupt_init();
487          timer_init();          timer_init();
488          sms_init();          modem_init();
489          eeprom_reader();          eeprom_reader();
490  ///////////////  ///////////////
491  // Main loop //  // Main loop //
# Line 525  void main() Line 525  void main()
525                  {                  {
526                          global_Pot_Hi = ADRESH;                          global_Pot_Hi = ADRESH;
527                          global_Pot_Lo = ADRESL;                          global_Pot_Lo = ADRESL;
528                          convertTemp();                          convert_temp();
529                          update_lcd();                          update_lcd();
530                          GODONE = 1;                          GODONE = 1;
531                  }                  }

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

  ViewVC Help
Powered by ViewVC 1.1.20