1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
const char TIMER_START_VALUE = 8;
const char TIMER_RELOAD_VALUE = 125;
char sec, updateDisplay, reload;
long bat;
char bat_str [] = " ";
// LCD module connections
sbit LCD_RW at RB2_bit;
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RW_Direction at TRISB2_bit;
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
void main() {
TrisA = 0xFF;
TrisC = 0;
PortC = 0;
TrisD = 0;
PortD = 0;
ADCON0 = 0;
ADCON1 = 0x0F;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);// Cursor off
Lcd_Out(1,1,"Wireless ECG");
delay_ms(4000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
LCD_Out(1,1,"Heartbeats :"); // Write text in first row
updateDisplay = 0; sec = 0; reload = 0; bat = 0;
INTCON = 0xC0; // Set GIE, PEIE
INT0IE_bit = 1;
TMR0ON_bit = 0; // turn off the timer during setup
TMR0IE_bit = 1; // Enable TMRO interrupt
T08BIT_bit = 1; // Enable 8 bit control (as opposed to 16-bit)
T0CS_bit = 0; // use internal clock to trigger timer to count
PSA_bit = 0; // Use the prescaler to slow the timer down
T0PS0_bit = 1;
T0PS1_bit = 0;
T0PS2_bit = 1;
TMR0L = TIMER_START_VALUE;
reload = TIMER_RELOAD_VALUE;
TMR0ON_bit = 1; // start the timer
while (1) {
if (UpdateDisplay == 1) {
UpdateDisplay = 0;
WordToStr (bat, bat_str); bat = 0;
LCD_Out(2,1,bat_str);
}
}
}
void Interrupt (void) {
if (INTCON.TMR0IF) {
TMR0L = TIMER_START_VALUE;
T0IF_bit = 0;
if(reload == 0) {
reload = TIMER_RELOAD_VALUE + 1;
sec = sec + 1;
if (sec == 15) {
updateDisplay = 1; sec = 0;
}
}
reload = reload - 1;
}
if (INTCON.INT0IF) {
bat = bat + 1; INT0IF_bit = 0;
}
} |
Partager