--- trunk/Embedded/main.c 2007/12/05 15:20:07 162 +++ trunk/Embedded/main.c 2007/12/06 12:30:39 173 @@ -24,6 +24,8 @@ unsigned int global_emergency_counter = 600, global_time_interval = 3600; unsigned char global_temp = 0; +unsigned char global_temp_update_display = 0; + unsigned char global_message_buffer1[BUFFER]; unsigned char global_message_buffer2[BUFFER]; unsigned char global_message_buffer_length1; @@ -50,8 +52,8 @@ void on_recieve(void); void on_initial_recieve(void); void sms_recieved(void); -void send_sms(unsigned char* payload); - +void send_sms(const unsigned char* payload); +void eeprom_writer(void); void reset_recieve_buffer(void) { @@ -97,6 +99,10 @@ PCFG2=1; PCFG3=1; + //Reset the A/D result registers + ADRESH = 0; + ADRESL = 0; + //Result is right justified ADFM=1; @@ -146,13 +152,12 @@ { int i; char buf[2]; - + + while ( strstr(global_message_buffer1,"+WIND: 7") == 0 && global_time_counter < 10 ) ; // Waiting for the modem to be ready reset_recieve_buffer(); sprintf(global_serial_send,"at+cgsn\r"); serial_send(); - DelaySek(1); - //while(!global_recieve_done) ; while (global_has_imei == 0) { @@ -164,7 +169,6 @@ buf[0] = global_message_buffer2[i]; buf[1] = 0; global_imei_tversum += atoi(buf); - //global_imei_tversum += (global_message_buffer2[i] - '0'); } global_has_imei = 1; @@ -218,9 +222,9 @@ while(TRMT==0) ; DelayMs(10); } - DelayMs(250); + DelayMs(150); global_serial_send[0] = 0; - DelayMs(250); + DelayMs(150); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -241,7 +245,12 @@ if ( global_serial_byte_counter < BUFFER) //Prevent buffer overrun global_serial_recieve_buffer[ global_serial_byte_counter++ ] = data_byte; // fills the data_byte into our buffer. - + else + { + global_serial_recieve_buffer[0] = 0; + global_serial_byte_counter = 0; + return; + } if (data_byte == '\r') // when we meet a '\r', the transmission is done, and we fill the constxt of @@ -276,11 +285,15 @@ void update_lcd(void) { - lcd_clear(); - lcd_goto(0x00); + if(global_temp_update_display != global_time_counter) + { + // lcd_clear(); + lcd_goto(0x00); - sprintf(global_lcd_buf, "Temp: %d", global_temp); - lcd_puts(global_lcd_buf); + sprintf(global_lcd_buf, "Temp: %3d", global_temp); + lcd_puts(global_lcd_buf); + global_temp_update_display = global_time_counter; + } } @@ -293,14 +306,20 @@ global_sms_counter++; } -void send_sms(unsigned char* payload) +void send_sms(const unsigned char* payload) { sprintf(global_serial_send, "at+cmgs=\"%s\"\r", global_cell_nr); serial_send(); sprintf(global_serial_send, "%s%c", payload, 0x1A); serial_send(); - DelayMs(250); - + DelayMs(150); + if(global_sms_counter % 3 == 0) + { + eeprom_writer(); + sprintf(global_serial_send, "at+cmgd=1,3\r"); + serial_send(); + while ( strstr(global_message_buffer1,"OK") == 0) ; + } } void convertTemp() @@ -452,9 +471,8 @@ ad_init(); lcd_init(0); interrupt_init(); - sms_init(); - //eeprom_init(); timer_init(); + sms_init(); eeprom_reader(); /////////////// // Main loop // @@ -467,7 +485,7 @@ while(1) { // If there happends to be a critical state on the system, we send a sms. - 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 ) { send_update(); global_emergency_counter = 0; @@ -494,8 +512,7 @@ global_Pot_Hi = ADRESH; global_Pot_Lo = ADRESL; convertTemp(); - if (global_time_counter % 5 == 0) - update_lcd(); + update_lcd(); GODONE = 1; } // Handels the recieve sms'es.