/* *************** LCD12.C ****************************** LCD Display (HD44780) on PortH, PORTJ sizes range from 1*16 to 4*40 ground = pin 1 Vss power = pin 2 Vdd +5V 10Kpot = pin 3 Vlc contrast adjust 0 to +5V PJ2 = pin 6 E (enable) PJ1 = pin 5 R/W (1 for read, 0 for write) PJ0 = pin 4 RS (1 for data, 0 for control/status) PH0-7 = pins7-14 DB0-7 (8 bit data)*/ // Last modified 1/3/03 by Jonathan W. Valvano // Copyright 2003 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu // You may use, edit, run or distribute this file // as long as the above copyright notice remains #define LCDDATA 1 // PJ0=RS=1 #define LCDCSR 0 // PJ0=RS=0 #define LCDREAD 2 // PJ1=R/W=1 #define LCDWRITE 0 // PJ1=R/W=0 #define LCDENABLE 4 // PJ2=E=1 #define LCDDISABLE 0 // PJ2=E=0 void static cycwait(unsigned int cycles){ TC5 = TCNT+cycles; // number of 500ns cycles to wait TFLG1 = 0x20; // clear C5F while((TFLG1&0x20)==0){}; } void LCD_OutChar(char letter){ // letter is ASCII code PORTH = letter; PORTJ = LCDDISABLE+LCDWRITE+LCDDATA; PORTJ = LCDENABLE+LCDWRITE+LCDDATA; // E goes 0,1 PORTJ = LCDDISABLE+LCDWRITE+LCDDATA; // E goes 1,0 cycwait(180); // 90 us wait, clear C5F } void LCD_OutCsr(char command){ PORTH = command; PORTJ = LCDDISABLE+LCDWRITE+LCDCSR; PORTJ = LCDENABLE+LCDWRITE+LCDCSR; // E goes 0,1 PORTJ = LCDDISABLE+LCDWRITE+LCDCSR; // E goes 1,0 cycwait(180); // 90 us wait, clear C5F } void LCD_Clear(void){ LCD_OutCsr(0x01); // Clear Display cycwait(3280); // 1.64ms wait LCD_OutCsr(0x02); // Cursor to home cycwait(3280); // 1.64ms wait } void LCD_Init(void){ DDRH = 0xFF; DDRJ = 0xFF; TIOS |= 0x20; // enable OC5 TSCR = 0x80; // enable, no fast clear TMSK2 = 0x22; // to specify 500 ns clock // Be careful, TMSK2 and TSCR maybe set in other rituals LCD_OutCsr(0x06); // I/D=1 Increment, S=0 nodisplayshift LCD_OutCsr(0x0C); // D=1 displayon, C=0 cursoroff, B=0 blinkoff LCD_OutCsr(0x14); // S/C=0 cursormove, R/L=0 shiftright LCD_OutCsr(0x38); // DL=1 8bit, N=0 1 line, F=0 5by7dots LCD_Clear(); } // clear display //---------------------LCD_OutString-------------- // Output String (NULL termination) void LCD_OutString(char *pt){ char letter; while (letter=*pt++){ LCD_OutChar(letter); } }