4 |
//Includes |
//Includes |
5 |
#include <pic18.h> |
#include <pic18.h> |
6 |
#include <string.h> |
#include <string.h> |
7 |
|
#include <stdio.h> |
8 |
|
|
9 |
#include "delay.h" |
#include "delay.h" |
10 |
#include "i2c.h" |
#include "i2c.h" |
70 |
unsigned char global_comm_slipstate; |
unsigned char global_comm_slipstate; |
71 |
unsigned char global_comm_baudrate; |
unsigned char global_comm_baudrate; |
72 |
|
|
73 |
unsigned char global_lcd_buffer[2][20]; |
unsigned char global_lcd_buffer[2][BUFFERLEN]; |
74 |
|
|
75 |
|
|
76 |
bit global_led_0; |
bit global_led_0; |
223 |
break; |
break; |
224 |
case TSwitch2: |
case TSwitch2: |
225 |
if (cmd == CmdRead) |
if (cmd == CmdRead) |
226 |
global_comm_buffer[1] = RA4; |
global_comm_buffer[1] = !RA4; |
227 |
else |
else |
228 |
global_comm_error = 1; |
global_comm_error = 1; |
229 |
break; |
break; |
230 |
case TSwitch3: |
case TSwitch3: |
231 |
if (cmd == CmdRead) |
if (cmd == CmdRead) |
232 |
global_comm_buffer[1] = RB0; |
global_comm_buffer[1] = !RB0; |
233 |
else |
else |
234 |
global_comm_error = 1; |
global_comm_error = 1; |
235 |
break; |
break; |
454 |
return temp; |
return temp; |
455 |
} |
} |
456 |
|
|
457 |
|
|
458 |
|
|
459 |
void update_lcd(void) |
void update_lcd(void) |
460 |
{ |
{ |
461 |
|
static char current_row = 0; |
462 |
|
static char current_char = 0; |
463 |
|
|
464 |
|
if ( current_char >= BUFFERLEN || global_lcd_buffer[current_row][current_char] == 0 ) |
465 |
|
{ |
466 |
|
current_row++; |
467 |
|
current_char = 0; |
468 |
|
lcd_goto(0x40); |
469 |
|
} |
470 |
|
|
471 |
|
if (current_row >= 2) |
472 |
|
{ |
473 |
|
sprintf(global_lcd_buffer[1], "T=%02d, P=%04d", global_temp, (global_potmeter_hi<<8) | global_potmeter_lo); |
474 |
|
lcd_goto(0x00); |
475 |
|
current_row = 0; |
476 |
|
} |
477 |
|
|
478 |
|
lcd_putch(global_lcd_buffer[current_row][current_char]); |
479 |
|
current_char++; |
480 |
} |
} |
481 |
|
|
482 |
void reset_baudrate(void) |
void reset_baudrate(void) |
488 |
{ |
{ |
489 |
case Baud1200: |
case Baud1200: |
490 |
SPBRG = 207; |
SPBRG = 207; |
491 |
|
strcpy(global_lcd_buffer[0],"Baud=1200 "); |
492 |
break; |
break; |
493 |
case Baud2400: |
case Baud2400: |
494 |
SPBRG = 103; |
SPBRG = 103; |
495 |
|
strcpy(global_lcd_buffer[0],"Baud=2400 "); |
496 |
break; |
break; |
497 |
case Baud9600: |
case Baud9600: |
498 |
SPBRG = 25; |
SPBRG = 25; |
499 |
|
strcpy(global_lcd_buffer[0],"Baud=9600 "); |
500 |
break; |
break; |
501 |
case Baud19200: |
case Baud19200: |
502 |
SPBRG = 12; |
SPBRG = 12; |
503 |
|
strcpy(global_lcd_buffer[0],"Baud=19200"); |
504 |
break; |
break; |
505 |
default: |
default: |
506 |
|
strcpy(global_lcd_buffer[0],"Baud=9600 "); |
507 |
SPBRG = 25; // this should not be possible, but default to 9600 anyway |
SPBRG = 25; // this should not be possible, but default to 9600 anyway |
508 |
} |
} |
509 |
SPEN = 1; // enable the serial port again |
SPEN = 1; // enable the serial port again |
531 |
// initialisation completed and we are ready to recieve commands - enable serial reception |
// initialisation completed and we are ready to recieve commands - enable serial reception |
532 |
CREN = 1; |
CREN = 1; |
533 |
|
|
534 |
|
strcpy(global_lcd_buffer[0], "Baud=9600 "); |
535 |
while (1) |
while (1) |
536 |
{ |
{ |
537 |
if (global_comm_ready == 1) |
if (global_comm_ready == 1) |
544 |
if ( global_reset_baudrate == 1) |
if ( global_reset_baudrate == 1) |
545 |
{ |
{ |
546 |
reset_baudrate(); |
reset_baudrate(); |
547 |
|
global_reset_baudrate = 0; |
548 |
} |
} |
549 |
|
|
550 |
RB1 = global_led_0; |
RB1 = global_led_0; |
561 |
global_potmeter_lo = ADRESL; |
global_potmeter_lo = ADRESL; |
562 |
GODONE = 1; //start ny konverering |
GODONE = 1; //start ny konverering |
563 |
} |
} |
564 |
|
|
565 |
|
update_lcd(); |
566 |
} |
} |
567 |
} |
} |
568 |
|
|