/*==============================================*/ void clear_lcd () { lcd_put_command(LCD_CLR); //-- clear LCD display lcd_put_command(LCDHOME); //-- cursor go to 0x00 cursor_position = LINE_0_START; delay_millisec(5); }
//of initialisation, are still //in pseudo 8bit data mode int main() { initLCD(); initTimerAndInput(); while (1) { int m = 0; int s = 0; int h = 0; int i; for (i=0; i<1; i++){ displayTime(m, s, h); wait_for_user(); } while (! GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)){ if (h == 100) { s++; h = 0; delay_millisec(40); // make up for processing delays } if (s == 60){ m++; s=0; } h ++; displayTime(m, s, h); delay_millisec(7); //resetting display requires 2ms, 8ms delay results in stopwatch // running slow, 7ms with 40ms delay every second corrects this } wait_for_user(); //removes bounce effect for (i=0; i<1; i++){ displayTime(m, s, h); wait_for_user(); } } }
/* * FUNCTION : init_lcd() * PURPOSE : Initializes LCD * ACCEPTS : None * RETURNS : None * NOTES : Initializes LCD */ void init_lcd(void) // Init routine as per HD44780 data sheet { LCD_RS = COMMAND_RS; // RS = 0 LCD_RW = WRITE_RW; // RW = 0 delay_millisec(16); // Wait more than 15ms lcd_put_command(0x38); // Initialize for 8 bit , 2 line delay_millisec(5); // Wait more than 4.1ms lcd_put_command(0x38); delay_millisec(1); // Wait more than 0.1ms lcd_put_command(0x38); delay_millisec(1); // Wait more than 0.1ms lcd_put_command(0x0D); // Display On; Cursor Off; Blink on lcd_put_command(0x01); // Clear the display delay_millisec(5); // Wait more than 1.64ms start_busy_chk = TRUE; }
void wait_for_user() { while (! GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)); while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) { delay_millisec(2); } return; }
void displayTime(int m, int s, int h){ lcd_command(0x01); // clears display delay_millisec(2); lcd_putchar(div(m)); lcd_putchar(mod(m)); lcd_putchar(':'); lcd_putchar(div(s)); lcd_putchar(mod(s)); lcd_putchar(':'); lcd_putchar(div(h)); lcd_putchar(mod(h)); }