/**************************************************************************** Title : C file for the LCD functions (lcd.c) Author: Sara Keen Date: July/24/2006 Software: AVR-GCC Target: Atmega 128 Comments: To be used with the micro-p 4 bit LCD *****************************************************************************/ //port A is input to LCD //pin0= no connect //pin1=RS //pin2=R/W //pin3=EN //pin4=DB4 //pin5=DB5 //pin6=DB6 //pin7=DB7 #include #include "lcd.h" //LCD Variables int init[] = {0x38, 0x38, 0x38, 0x28, 0x28, 0x88, 0x08, 0xF8, 0x08, 0x18}; int temp; int temp2; int clear[] = {0x08, 0x18}; int temp3; void small_delay(void) { int wait; for(wait = 0; wait < 5; wait++); } void DELAY(void) { volatile uint16_t time1; for(time1 = 0; time1 < 2000; time1++); } void lcd_init(void) // Initializes the LCD { int lcd1; for(lcd1 = 0; lcd1 < 10; lcd1++) { temp = init[lcd1]; PORTA = temp; DELAY(); temp = temp & 0xF0; PORTA = temp; DELAY(); } } void lcd_clr(void) // Clears the LCD display { int clr; for(clr = 0; clr < 2; clr++) { temp3 = clear[clr]; PORTA = temp3; DELAY(); temp3 = temp3 & 0xF0; PORTA = temp3; DELAY(); } } int def_putc(char ch) // Displays a character to the LCD screen { //display one character on screen int temp; temp = ch & 0xF0; temp = temp | 0x0A; PORTA = temp; DELAY(); temp = temp & 0xF0; temp = temp | 0x02; PORTA = temp; DELAY(); //send same data with enable high and then low temp = (ch<<4); temp = temp & 0xF0; temp = temp | 0x0A; PORTA = temp; DELAY(); temp = temp & 0xF0; temp = temp | 0x02; PORTA = temp; DELAY(); return ch; }