--- trunk/Embedded/main.c 2007/12/05 15:01:15 160 +++ trunk/Embedded/main.c 2007/12/05 16:11:12 167 @@ -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,7 +52,7 @@ 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 reset_recieve_buffer(void) @@ -218,9 +220,9 @@ while(TRMT==0) ; DelayMs(10); } - DelayMs(250); + DelayMs(150); global_serial_send[0] = 0; - DelayMs(250); + DelayMs(150); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -228,7 +230,7 @@ // global_serial_recieve_buffer, to global_message_buffer1, and sets the flag global_recieve_done. void serial_recieved(void) { - char data_byte, saved_data[LCD_LENGTH]; + char data_byte; data_byte = RCREG; @@ -238,12 +240,15 @@ if (global_serial_byte_counter == 0 && data_byte == '\r') // don't care about '\r', if it's the first byte we recieve. return; -// if (global_serial_byte_counter == BUFFER -1) -// global_seriaæl_recieve_buffer[global_serial_byte_counter] = 0; -// if (data_byte != '\r' && (global_serial_byte_counter-1) < BUFFER) -// 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; + 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 @@ -265,11 +270,6 @@ global_serial_byte_counter = 0; } - else - { - global_serial_byte_counter++; - } - } void timer1_interrupt(void) @@ -283,11 +283,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; + } } @@ -300,13 +304,13 @@ 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); }