The LCD Functions are intended for easy interfacing between C programs and alphanumeric LCD modules built with the Hitachi HD44780 chip or equivalent. The prototypes for these functions are placed in the file lcd.h, located in the ..\INC subdirectory. This file must be #include -ed before using the functions. Prior to #include -ing the lcd.h file, you must declare which microcontroller port is used for communication with the LCD module. The following LCD formats are supported in lcd.h: 1x8, 2x12, 3x12, 1x16, 2x16, 2x20, 4x20, 2x24 and 2x40 characters. Example: /* the LCD module is connected to PORTC */ #asm .equ __lcd_port=0x15 #endasm /* now you can include the LCD Functions */ #include The LCD module must be connected to the port bits as follows: [LCD] [AVR Port] RS (pin4) ------ bit 0 RD (pin 5) ------ bit 1 EN (pin 6) ------ bit 2 DB4 (pin 11) --- bit 4 DB5 (pin 12) --- bit 5 DB6 (pin 13) --- bit 6 DB7 (pin 14) --- bit 7 You must also connect the LCD power supply and contrast control voltage, according to the data sheet. The low level LCD Functions are: void _lcd_ready(void) waits until the LCD module is ready to receive data. This function must be called prior to writing data to the LCD with the _lcd_write_data function. void _lcd_write_data(unsigned char data) writes the byte data to the LCD instruction register. This function may be used for modifying the LCD configuration. Example: /* enables the displaying of the cursor */ _lcd_ready(); _lcd_write_data(0xe); void lcd_write_byte(unsigned char addr, unsigned char data); writes a byte to the LCD character generator or display RAM. Example: /* LCD user defined characters Chip: AT90S8515 Memory Model: SMALL Data Stack Size: 128 bytes Use an 2x16 alphanumeric LCD connected to the STK200+ PORTC header as follows: [LCD] [STK200+ PORTC HEADER] 1 GND- 9 GND 2 +5V- 10 VCC 3 VLC- LCD HEADER Vo 4 RS - 1 PC0 5 RD - 2 PC1 6 EN - 3 PC2 11 D4 - 5 PC4 12 D5 - 6 PC5 13 D6 - 7 PC6 14 D7 - 8 PC7 */ /* the LCD is connected to PORTC outputs */ #asm .equ __lcd_port=0x15 ;PORTC #endasm /* include the LCD driver routines */ #include typedef unsigned char byte; /* table for the user defined character arrow that points to the top right corner */ flash byte char0[8]={ 0b0000000, 0b0001111, 0b0000011, 0b0000101, 0b0001001, 0b0010000, 0b0100000, 0b1000000}; /* function used to define user characters */ void define_char(byte flash *pc,byte char_code) { byte i,a; a=(char_code<<3) | 0x40; for (i=0; i<8; i++) lcd_write_byte(a++,*pc++); } void main(void) { /* initialize the LCD for 2 lines & 16 columns */ lcd_init(16); /* define user character 0 */ define_char(char0,0); /* switch to writing in Display RAM */ lcd_gotoxy(0,0); lcd_putsf("User char 0:"); /* display used defined char 0 */ lcd_putchar(0); while (1); /* loop forever */ } unsigned char lcd_read_byte(unsigned char addr); reads a byte from the LCD character generator or display RAM. The high level LCD Functions are: unsigned char lcd_init(unsigned char lcd_columns) initializes the LCD module, clears the display and sets the printing character position at row 0 and column 0. The numbers of columns of the LCD must be specified (e.g. 16). No cursor is displayed. The function returns 1 if the LCD module is detected and 0 if it is not. This is the first function that must be called before using the other high level LCD Functions. void lcd_clear(void) clears the LCD and sets the printing character position at row 0 and column 0. void lcd_gotoxy(unsigned char x, unsigned char y) sets the current display position at column x and row y. The row and column numbering starts from 0. void lcd_putchar(char c) displays the character c at the current display position. void lcd_puts(char *str) displays at the current display position the string str, located in SRAM. void lcd_putsf(char flash *str) displays at the current display position the string str, located in FLASH.