📄 lcd_drv.c
字号:
/*C**************************************************************************
* $RCSfile: lcd_drv.c,v $
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE: $Name: DEMO_FAT_1_9_9 $
* REVISION: $Revision: 1.5 $
* FILE_CVSID: $Id: lcd_drv.c,v 1.5 2002/05/24 09:51:15 njourdan Exp $
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the 8-bit lcd driver routines
*
* NOTES:
* Driver Configuration:
* - LCD_CMD_ADD in board.h
* - LCD_DAT_ADD in board.h
* - FPER defined in config.h
* Global Variables:
* - None
*****************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h" /* lib configuration header */
#include "..\board.h" /* board definition */
#include "lcd_drv.h" /* lcd driver definition */
/*_____ M A C R O S ________________________________________________________*/
/*_____ D E F I N I T I O N ________________________________________________*/
xdata Byte lcd_cmd At(LCD_CMD_ADD);
xdata Byte lcd_data At(LCD_DAT_ADD);
static Byte lcd_line; /* save the cursor position */
/*_____ D E C L A R A T I O N ______________________________________________*/
static void lcd_wr_cmd (char);
static void lcd_wr_data (char);
/*F**************************************************************************
* NAME: lcd_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* LCD controller initialization and configuration
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function is called once to initialize the LCD display
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_init (void)
{
Uint16 data i;
for (i = 0; i < TEMPO_30MS; i++); /* initialization delay */
lcd_wr_cmd(LCD_FCTSET | LCD_8BIT | LCD_2_LINE | LCD_5x8DOTS);
lcd_wr_cmd(LCD_DISPLAY | LCD_DISP_ON | LCD_CURS_OFF | LCD_BLINK_OFF);
lcd_wr_cmd(LCD_SET | LCD_INC | LCD_RIGHT);
lcd_wr_cmd(LCD_CLR);
for (i = 0; i < TEMPO_1_5MS; i++); /* clear delay */
lcd_line = LCD_LINE0;
}
/*F**************************************************************************
* NAME: lcd_clr
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Clear display and set cusor to home
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* No delay is performed, it is to the attention of the user to take care
* of the clear time
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_clr (void)
{
lcd_wr_cmd(LCD_CLR);
lcd_line = LCD_LINE0;
}
/*F**************************************************************************
* NAME: lcd_set_cur
*----------------------------------------------------------------------------
* PARAMS:
* line: LCD_LINE0: cursor on line 0
* LCD_LINE1: cursor on line 1
* column: column number of the new position of the cursor
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Set the cursor position
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* Columns start from 0 (LCD_LINE0, 0) is home
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_set_cur (Byte line, Byte column)
{
lcd_line = line; /* update the line position */
lcd_wr_cmd(line | column); /* write the new cursor position */
}
/*F**************************************************************************
* NAME: lcd_putchar
*----------------------------------------------------------------------------
* PARAMS:
* c: character to display
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* LCD display interpreter
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_putchar (char c)
{
switch (c)
{
case C_R: /* Carriage Return */
{
lcd_set_cur(lcd_line, 0);
break;
}
case L_F: /* Line Feed + Carriage Return */
{
lcd_set_cur((lcd_line + LCD_LINE_OFFSET), 0);
break;
}
default:
{
lcd_wr_data(c); /* write the character to the display */
break;
}
}
}
/*F**************************************************************************
* NAME: lcd_wr_cmd
*----------------------------------------------------------------------------
* PARAMS:
* cmd: command to write on the LCD driver
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Write command on LCD
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_wr_cmd (char cmd)
{
Byte data i;
lcd_cmd = cmd;
for (i = 0; i < TEMPO_40US; i++);
}
/*F**************************************************************************
* NAME: lcd_wr_data
*----------------------------------------------------------------------------
* PARAMS:
* dat: data to write on the LCD driver
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Write data on LCD
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_wr_data (char dat)
{
Byte data i;
lcd_data = dat;
for (i = 0; i < TEMPO_40US - 4; i++);
}
/*F**************************************************************************
* NAME: lcd_wr_cgram
*----------------------------------------------------------------------------
* PARAMS:
* dat: data to write on the LCD driver
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Write data on LCD CGRAM
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_wr_cgram (char dat)
{
Byte data i;
lcd_data = dat;
for (i = 0; i < TEMPO_40US; i++);
}
/*F**************************************************************************
* NAME: lcd_cgram
*----------------------------------------------------------------------------
* PARAMS:
* address: character address in cgram
* pt_pattern: pointer on pattern in code segment
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* LCD controller Character Graphic RAM set-up
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function is called to re-define a graphic character
* The HD44780 controller contains 8 locations in RAM where user's
* characters can be defined
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void lcd_cgram (Byte address, Byte code *pt_pattern)
{
lcd_wr_cmd(LCD_CGRAM | address); /* select character in graphic RAM */
lcd_wr_cgram(pt_pattern[0]); /* load symbols */
lcd_wr_cgram(pt_pattern[1]);
lcd_wr_cgram(pt_pattern[2]);
lcd_wr_cgram(pt_pattern[3]);
lcd_wr_cgram(pt_pattern[4]);
lcd_wr_cgram(pt_pattern[5]);
lcd_wr_cgram(pt_pattern[6]);
lcd_wr_cgram(pt_pattern[7]);
lcd_wr_cmd(lcd_line); /* select display data RAM */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -