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 |
|
|
28 |
unsigned char global_message_buffer1[BUFFER]; |
unsigned char global_message_buffer1[BUFFER]; |
29 |
unsigned char global_message_buffer2[BUFFER]; |
unsigned char global_message_buffer2[BUFFER]; |
51 |
void on_recieve(void); |
void on_recieve(void); |
52 |
void on_initial_recieve(void); |
void on_initial_recieve(void); |
53 |
void sms_recieved(void); |
void sms_recieved(void); |
54 |
void send_sms(unsigned char* payload); |
void send_sms(const unsigned char* payload); |
55 |
|
|
56 |
|
|
57 |
void reset_recieve_buffer(void) |
void reset_recieve_buffer(void) |
219 |
while(TRMT==0) ; |
while(TRMT==0) ; |
220 |
DelayMs(10); |
DelayMs(10); |
221 |
} |
} |
222 |
DelayMs(250); |
DelayMs(150); |
223 |
global_serial_send[0] = 0; |
global_serial_send[0] = 0; |
224 |
DelayMs(250); |
DelayMs(150); |
225 |
} |
} |
226 |
|
|
227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
229 |
// global_serial_recieve_buffer, to global_message_buffer1, and sets the flag global_recieve_done. |
// global_serial_recieve_buffer, to global_message_buffer1, and sets the flag global_recieve_done. |
230 |
void serial_recieved(void) |
void serial_recieved(void) |
231 |
{ |
{ |
232 |
char data_byte, saved_data[LCD_LENGTH]; |
char data_byte; |
233 |
|
|
234 |
data_byte = RCREG; |
data_byte = RCREG; |
235 |
|
|
239 |
if (global_serial_byte_counter == 0 && data_byte == '\r') // don't care about '\r', if it's the first byte we recieve. |
if (global_serial_byte_counter == 0 && data_byte == '\r') // don't care about '\r', if it's the first byte we recieve. |
240 |
return; |
return; |
241 |
|
|
|
// if (global_serial_byte_counter == BUFFER -1) |
|
|
// global_seriaæl_recieve_buffer[global_serial_byte_counter] = 0; |
|
242 |
|
|
243 |
// if (data_byte != '\r' && (global_serial_byte_counter-1) < BUFFER) |
if ( global_serial_byte_counter < BUFFER) //Prevent buffer overrun |
244 |
// 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. |
245 |
global_serial_recieve_buffer[ global_serial_byte_counter] = data_byte; |
|
246 |
|
|
247 |
|
|
248 |
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 |
264 |
|
|
265 |
global_serial_byte_counter = 0; |
global_serial_byte_counter = 0; |
266 |
} |
} |
|
else |
|
|
{ |
|
|
global_serial_byte_counter++; |
|
|
} |
|
|
|
|
267 |
} |
} |
268 |
|
|
269 |
void timer1_interrupt(void) |
void timer1_interrupt(void) |
277 |
|
|
278 |
void update_lcd(void) |
void update_lcd(void) |
279 |
{ |
{ |
280 |
lcd_clear(); |
//lcd_clear(); |
281 |
lcd_goto(0x00); |
lcd_goto(0x00); |
282 |
|
|
283 |
sprintf(global_lcd_buf, "Temp: %d", global_temp); |
sprintf(global_lcd_buf, "Temp: %3d", global_temp); |
284 |
lcd_puts(global_lcd_buf); |
lcd_puts(global_lcd_buf); |
285 |
|
|
286 |
} |
} |
294 |
global_sms_counter++; |
global_sms_counter++; |
295 |
} |
} |
296 |
|
|
297 |
void send_sms(unsigned char* payload) |
void send_sms(const unsigned char* payload) |
298 |
{ |
{ |
299 |
sprintf(global_serial_send, "at+cmgs=\"%s\"\r", global_cell_nr); |
sprintf(global_serial_send, "at+cmgs=\"%s\"\r", global_cell_nr); |
300 |
serial_send(); |
serial_send(); |
301 |
sprintf(global_serial_send, "%s%c", payload, 0x1A); |
sprintf(global_serial_send, "%s%c", payload, 0x1A); |
302 |
serial_send(); |
serial_send(); |
303 |
DelayMs(250); |
DelayMs(150); |
304 |
|
|
305 |
} |
} |
306 |
|
|
495 |
global_Pot_Hi = ADRESH; |
global_Pot_Hi = ADRESH; |
496 |
global_Pot_Lo = ADRESL; |
global_Pot_Lo = ADRESL; |
497 |
convertTemp(); |
convertTemp(); |
498 |
update_lcd(); |
if (global_temp != global_temp_old) |
499 |
|
{ |
500 |
|
update_lcd(); |
501 |
|
global_temp_old = global_temp; |
502 |
|
} |
503 |
GODONE = 1; |
GODONE = 1; |
504 |
} |
} |
505 |
// Handels the recieve sms'es. |
// Handels the recieve sms'es. |