/[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 163 by hedin, Wed Dec 5 15:39:55 2007 UTC revision 173 by hedin, Thu Dec 6 12:30:39 2007 UTC
# Line 23  bit global_recieve_done = 0, global_inte Line 23  bit global_recieve_done = 0, global_inte
23  unsigned int global_serial_byte_counter = 0, global_sms_counter = 1, global_time_counter = 0;  unsigned int global_serial_byte_counter = 0, global_sms_counter = 1, global_time_counter = 0;
24  unsigned int global_emergency_counter = 600, global_time_interval = 3600;  unsigned int global_emergency_counter = 600, global_time_interval = 3600;
25  unsigned char global_temp = 0;  unsigned char global_temp = 0;
26  unsigned char global_temp_old = 0;  
27    unsigned char global_temp_update_display = 0;
28    
29  unsigned char global_message_buffer1[BUFFER];  unsigned char global_message_buffer1[BUFFER];
30  unsigned char global_message_buffer2[BUFFER];  unsigned char global_message_buffer2[BUFFER];
# Line 52  void on_recieve(void); Line 53  void on_recieve(void);
53  void on_initial_recieve(void);  void on_initial_recieve(void);
54  void sms_recieved(void);  void sms_recieved(void);
55  void send_sms(const unsigned char* payload);  void send_sms(const unsigned char* payload);
56    void eeprom_writer(void);
57    
58  void reset_recieve_buffer(void)  void reset_recieve_buffer(void)
59  {  {
# Line 98  void ad_init(void) // Nicked from H7 Line 99  void ad_init(void) // Nicked from H7
99          PCFG2=1;          PCFG2=1;
100          PCFG3=1;          PCFG3=1;
101                    
102            //Reset the A/D result registers
103            ADRESH = 0;
104            ADRESL = 0;
105            
106          //Result is right justified          //Result is right justified
107          ADFM=1;          ADFM=1;
108                    
# Line 147  void sms_init(void) Line 152  void sms_init(void)
152  {  {
153          int i;          int i;
154          char buf[2];          char buf[2];
155            
156            while ( strstr(global_message_buffer1,"+WIND: 7") == 0 && global_time_counter < 10 ) ;  // Waiting for the modem to be ready
157    
158          reset_recieve_buffer();          reset_recieve_buffer();
159          sprintf(global_serial_send,"at+cgsn\r");          sprintf(global_serial_send,"at+cgsn\r");
160          serial_send();          serial_send();
         DelaySek(1);  
         //while(!global_recieve_done) ;  
161                    
162          while (global_has_imei == 0)          while (global_has_imei == 0)
163          {          {
# Line 165  void sms_init(void) Line 169  void sms_init(void)
169                                  buf[0] = global_message_buffer2[i];                                  buf[0] = global_message_buffer2[i];
170                                  buf[1] = 0;                                  buf[1] = 0;
171                                  global_imei_tversum += atoi(buf);                                  global_imei_tversum += atoi(buf);
                                 //global_imei_tversum += (global_message_buffer2[i] - '0');  
172                          }                          }
173                                                    
174                          global_has_imei = 1;                          global_has_imei = 1;
# Line 242  void serial_recieved(void) Line 245  void serial_recieved(void)
245    
246          if ( global_serial_byte_counter < BUFFER) //Prevent buffer overrun          if ( global_serial_byte_counter < BUFFER) //Prevent buffer overrun
247                  global_serial_recieve_buffer[ global_serial_byte_counter++ ] = data_byte;       // fills the data_byte into our buffer.                  global_serial_recieve_buffer[ global_serial_byte_counter++ ] = data_byte;       // fills the data_byte into our buffer.
248            else
249            {
250                    global_serial_recieve_buffer[0] = 0;
251                    global_serial_byte_counter = 0;
252                    return;
253            }
254                    
255                    
256          if (data_byte == '\r')  // when we meet a '\r', the transmission is done, and we fill the constxt of          if (data_byte == '\r')  // when we meet a '\r', the transmission is done, and we fill the constxt of
# Line 277  void timer1_interrupt(void) Line 285  void timer1_interrupt(void)
285    
286  void update_lcd(void)  void update_lcd(void)
287  {  {
288          //lcd_clear();          if(global_temp_update_display != global_time_counter)
289          lcd_goto(0x00);          {
290            //      lcd_clear();
291                    lcd_goto(0x00);
292                    
293          sprintf(global_lcd_buf, "Temp: %3d", global_temp);                  sprintf(global_lcd_buf, "Temp: %3d", global_temp);
294          lcd_puts(global_lcd_buf);                  lcd_puts(global_lcd_buf);
295                    global_temp_update_display = global_time_counter;
296            }
297    
298  }  }
299                    
# Line 301  void send_sms(const unsigned char* paylo Line 313  void send_sms(const unsigned char* paylo
313          sprintf(global_serial_send, "%s%c", payload, 0x1A);          sprintf(global_serial_send, "%s%c", payload, 0x1A);
314          serial_send();          serial_send();
315          DelayMs(150);          DelayMs(150);
316                    if(global_sms_counter % 3 == 0)
317            {
318                    eeprom_writer();
319                    sprintf(global_serial_send, "at+cmgd=1,3\r");
320                    serial_send();
321                    while ( strstr(global_message_buffer1,"OK") == 0) ;
322            }
323  }        }      
324    
325  void convertTemp()  void convertTemp()
# Line 453  void main() Line 471  void main()
471          ad_init();          ad_init();
472          lcd_init(0);          lcd_init(0);
473          interrupt_init();          interrupt_init();
         sms_init();  
         //eeprom_init();  
474          timer_init();          timer_init();
475            sms_init();
476          eeprom_reader();          eeprom_reader();
477  ///////////////  ///////////////
478  // Main loop //  // Main loop //
# Line 468  void main() Line 485  void main()
485          while(1)          while(1)
486          {          {
487          // If there happends to be a critical state on the system, we send a sms.          // If there happends to be a critical state on the system, we send a sms.
488                  if( (global_temp >= 90 || PWRFAIL == 1 || FIREDET == 0 || FEEDING == 1 || EMPTYTANK == 1) && global_emergency_counter >= 600 )                  if( (global_temp >= 90 || PWRFAIL == 1 || FIREDET == 0 || FEEDING ==1 ) && global_emergency_counter >= 600 )
489                  {                  {
490                          send_update();                          send_update();
491                          global_emergency_counter = 0;                          global_emergency_counter = 0;
# Line 495  void main() Line 512  void main()
512                          global_Pot_Hi = ADRESH;                          global_Pot_Hi = ADRESH;
513                          global_Pot_Lo = ADRESL;                          global_Pot_Lo = ADRESL;
514                          convertTemp();                          convertTemp();
515                          if (global_temp != global_temp_old)                          update_lcd();
                         {  
                                 update_lcd();  
                                 global_temp_old = global_temp;  
                         }  
516                          GODONE = 1;                          GODONE = 1;
517                  }                  }
518          // Handels the recieve sms'es.          // Handels the recieve sms'es.

Legend:
Removed from v.163  
changed lines
  Added in v.173

  ViewVC Help
Powered by ViewVC 1.1.20