You are on page 1of 3

LCD Functions for displays with up to 2x40 characters

Page 1 of 3

LCD Functions for displays with up to 2x40 characters

Previous Top Next

The LCD Functions are intended for easy interfacing between C programs and alphanumeric LCD modules built with the Hitachi HD44780 controller or equivalent. The prototypes for these functions are placed in the file alcd.h, located in the .\INC subdirectory. This file must be #include -d before using the functions. For LCD modules that use the Samsung KS0073 controller the alcd_ks0073.h header file must be used. The LCD functions do support both the XMEGA and non-XMEGA chips. The following LCD formats are supported in alcd.h: 1x8, 2x12, 3x12, 1x16, 2x16, 2x20, 4x20, 2x24 and 2x40 characters. The allocation of LCD module signals to the I/O ports must be specified in the Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu. The LCD power supply and contrast control voltage must also be connected according to the module data sheet. The low level LCD Functions are: 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_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: ATmega8515 Memory Model: SMALL Data Stack Size: 128 bytes Use an 2x16 alphanumeric LCD connected to the STK600 PORTC header as follows: [LCD] 1 GND2 +5V3 VLC4 RS 5 RD 6 EN 11 D4 12 D5 13 D6 14 D7 [STK600 PORTC HEADER] 9 GND 10 VCC LCD HEADER Vo 1 PC0 2 PC1 3 PC2 5 PC4 6 PC5 7 PC6 8 PC7

The connections must be specified in the Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu */ /* include the LCD driver routines */ #include <alcd.h>

mk:@MSITStore:C:\cvavreval\BIN\cvavr.chm::/lcdfunctionsfordisplayswithupto2x40char... 2/19/2014

LCD Functions for displays with up to 2x40 characters

Page 2 of 3

typedef unsigned char byte; /* table for the user defined character arrow that points to the top right corner */ flash byte char0[8]={ 0b10000000, 0b10001111, 0b10000011, 0b10000101, 0b10001001, 0b10010000, 0b10100000, 0b11000000}; /* 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: void 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. 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.

mk:@MSITStore:C:\cvavreval\BIN\cvavr.chm::/lcdfunctionsfordisplayswithupto2x40char... 2/19/2014

LCD Functions for displays with up to 2x40 characters

Page 3 of 3

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 RAM. void lcd_putsf(char flash *str) displays at the current display position the string str, located in FLASH. void lcd_putse(char eeprom *str) displays at the current display position the string str, located in EEPROM.

mk:@MSITStore:C:\cvavreval\BIN\cvavr.chm::/lcdfunctionsfordisplayswithupto2x40char... 2/19/2014