/** * A Mega644 LCD Test * * Written by Ruibing Wang (rw98@cornell.edu) * Slight mods for 644 by brl4@cornell.edu */ /** * Use an 2x16 alphanumeric LCD connected to PORTC as follows: * * [LCD] - [Mega644 Pin] * 1 GND - GND * 2 +5V - VCC * 3 VLC 10k trimpot wiper (trimpot ends go to +5 and gnd) * 4 RS - PC0 * 5 RD - PC1 * 6 EN - PC2 * 11 D4 - PC4 * 12 D5 - PC5 * 13 D6 - PC6 * 14 D7 - PC7 */ #include #include #include #include #include #include #include "lcd_lib.h" const int8_t LCD_initialize[] PROGMEM = "LCD Initialized\0"; const int8_t LCD_line[] PROGMEM = "line 1\0"; const int8_t LCD_number[] PROGMEM = "Number=\0"; int8_t lcd_buffer[17]; // LCD display buffer uint16_t count; // a number to display on the LCD uint8_t anipos, dir; // move a character around void init_lcd(void); int main(void) { init_lcd(); _delay_ms(500); LCDclr(); CopyStringtoLCD(LCD_line, 8, 1); // start at char=8 line=1 CopyStringtoLCD(LCD_number, 0, 0); // atart at char=0 line=0 count=0; anipos = 0; LCDGotoXY(anipos,1); //second line LCDsendChar('o'); while (1) { sprintf(lcd_buffer,"%-i",count++); //increment and format string LCDGotoXY(7, 0); LCDstring(lcd_buffer, strlen(lcd_buffer)); // display the count // now move a char left and right LCDGotoXY(anipos,1); //second line LCDsendChar(' '); if (anipos>=7) dir=-1; if (anipos<=0 ) dir=1; anipos=anipos+dir; LCDGotoXY(anipos,1); //second line LCDsendChar('o'); _delay_ms(200); //never do this in a realtime program } } void init_lcd(void) { LCDinit(); //initialize the display LCDcursorOFF(); LCDclr(); //clear the display LCDGotoXY(0,0); CopyStringtoLCD(LCD_initialize, 0, 0); }