Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CodeVision AVR 1.25.7, user manual.pdf
Скачиваний:
236
Добавлен:
12.08.2013
Размер:
1.22 Mб
Скачать

CodeVisionAVR

4.11.3 LCD Functions for displays connected in 8 bit memory mapped mode

These LCD Functions are intended for easy interfacing between C programs and alphanumeric LCD modules built with the Hitachi HD44780 chip or equivalent.

The LCD is connected to the AVR external data and address buses as an 8 bit peripheral.

This type of connection is used in the Kanda Systems STK200+ and STK300 development boards. For the LCD connection, please consult the documentation that came with your development board.

These functions can be used only with AVR chips that allow using external memory devices.

The prototypes for these functions are placed in the file lcdstk.h, located in the ..\INC subdirectory. This file must be #include -ed before using the functions.

The following LCD formats are supported in lcdstk.h: 1x8, 2x12, 3x12, 1x16, 2x16, 2x20, 4x20, 2x24 and 2x40 characters.

The 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_RS0 and _LCD_RS1 macros.

Example:

/* enables the displaying of the cursor */ _lcd_ready();

_LCD_RS0=0xe;

The _LCD_RS0, respectively _LCD_RS1, macros are used for accessing the LCD Instruction Register with RS=0, respectively RS=1.

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+ LCD connector */

/* include the LCD driver routines */ #include <lcdstk.h>

typedef unsigned char byte;

© 1998-2007 HP InfoTech S.R.L.

Page 137

CodeVisionAVR

/* 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.

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.

© 1998-2007 HP InfoTech S.R.L.

Page 138