lcd.c
来自「单片机仿真电路里面对于初学者很有帮助」· C语言 代码 · 共 151 行
C
151 行
/************************************************************
Copyright (C) Xiong,Hui at www.51embed.com
FileName: lcd.c
Author: Xiong,Hui huixiong73@gmail.com
Date:08/3/24
Description:
Version: 1.0
Function List:
1. lcd_disp();
2. lcd_init();
3. lcd_sta();
4. lcd_data();
5. lcd_clr();
History:
1. Huixiong 08/3/24 1.0 build this moudle
***********************************************************/
#include "at89x52.H"
#include <absacc.h>
#include <intrins.h>
#include "lcd.h"
/*************************************************************
* Function:lcd_disp()
* Description:
* Calls:
* Called by:
* Input:
* Output:
* Return:
* Others:
* History:
1.Huixiong 08/3/24 created
*************************************************************/
void lcd_disp(unsigned char data page,unsigned char data line,unsigned char *character)
{
unsigned char data i;
LCS1 = 1;
LCS2 = 0;
if(line >= 0x80){
LCS1 = 0;
LCS2 = 1;
line = line-0x40;
}
lcd_sta(page);
lcd_sta(line);
for(i=0;i<16;i++){
lcd_data(character[i]);
}
lcd_sta(page+1);
lcd_sta(line);
for(i=16;i<32;i++){
lcd_data(character[i]);
}
}
/*************************************************************
* Function:lcd_init()
* Description:test the busy bit of LCD status,b7
* Calls:
* Called by: lcd_disp()
* Input:
* Output:
* Return:
* Others:
* History:
1.Huixiong 08/3/24 created.
*************************************************************/
void lcd_init(void)
{
LCDRST = 0;
_nop_();
_nop_();
_nop_();
LCDRST = 1; //reset the lcd module
LCS1 = 0;
LCS2 = 0;
lcd_sta(0x3f); //turn on the display
lcd_sta(0xc0); //display the first line
lcd_clr(); //clear the LCD display
}
/*************************************************************
* Function:lcd_sta()
* Description:write the command into the LCD
* Calls:
* Called by: lcd_disp()
* Input:
* Output:
* Return:
* Others:because the status of LCD cannot be read,so the BUSY status has not been processed
it works in the proteus'simulation,but the following code may need time delay between instructions
in real circuits.
* History:
1.Huixiong 08/3/24 created.
*************************************************************/
void lcd_sta(unsigned char data sta)
{
XBYTE[CS5]=sta;
EN = 1;
RW = 0;
RS = 0;
EN = 0;
}
/*************************************************************
* Function:lcd_data()
* Description:write the data into the LCD
* Calls:
* Called by: lcd_disp()
* Input:
* Output:
* Return:
* Others:
* History:
1.Huixiong 08/3/24 created.
*************************************************************/
void lcd_data(unsigned char data dat)
{
XBYTE[CS5]=dat;
EN = 1;
RS = 1;
RW = 0;
EN = 0;
}
/*************************************************************
* Function:lcd_clr()
* Description:clear the LCD
* Calls:
* Called by: lcd_init()
* Input:
* Output:
* Return:
* Others:
* History:
1.Huixiong 08/3/24 created.
*************************************************************/
void lcd_clr(void)
{
unsigned char data i,j,m;
for(i=0;i<8;i++){
m = i;
m = m | 0xb8;
lcd_sta(m);
lcd_sta(0x40);
for(j=0;j<64;j++){
lcd_data(0x00);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?