#include "../delay/delay.h"
#include "lcd.h"
/*====================================================
判断写入命令/数据函数
=====================================================*/
void lcd_write(unsigned char byte, unsigned char flag)
{
if(flag)
{
RS = 1; //选择数据寄存器
}
else
{
RS = 0; //选择指令寄存器
}
RW = 0; //写
E = 1; //选中LCD
LCDPORT = byte;
delay_us(5); //稳定
E = 0; //失能LCD
}
/*====================================================
LCD初始化函数
=====================================================*/
void lcd_init()
{
delay_ms(15);
lcd_write(0x38,LCD_WRITE_COM); //显示8位数据接口,两行显示,5*7点阵字符
delay_ms(5);
lcd_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x08,LCD_WRITE_COM); //关闭显示,关闭光标的闪烁
delay_ms(5);
lcd_write(0x01,LCD_WRITE_COM); //清屏
delay_ms(5);
lcd_write(0x06,LCD_WRITE_COM); //设置指针方式,画面不平移
delay_ms(5);
lcd_write(0x0c,LCD_WRITE_COM); //打开显示
delay_ms(5);
}
/*====================================================================================
写入字符函数
函数原型:void lcd_dis_byte(unsigned char x, unsigned char y, unsigned char byte);
说明:x为行(1——2),y为列(1——8)。
=====================================================================================*/
void lcd_dis_byte(unsigned char x, unsigned char y, unsigned char byte)
{
unsigned char add;
if(((0 == x) || (x > 2)) || ((0 == y) || (y > 16)))
{
return ;
}
add = 0x80 + (x - 1) * 0x40 + (y - 1);
lcd_write(add,LCD_WRITE_COM);
lcd_write(byte,LCD_WRITE_DATA);
}
/*====================================================================================
写入字符串函数
函数原型:void lcd_dis_str(unsigned char x, unsigned char y, unsigned char *disdata);
说明:x为行(1——2),y为列(1——8)。
=====================================================================================*/
void lcd_dis_str(unsigned char x, unsigned char y, unsigned char *disdata)
{
unsigned char add;
if(((0 == x) || (x > 2)) || ((0 == y) || (y > 16)))
{
return ;
}
add = 0x80 + (x - 1) * 0x40 + (y - 1);
lcd_write(add,LCD_WRITE_COM);
while(*disdata != '\0')
{
lcd_write(*disdata,LCD_WRITE_DATA);
disdata++;
}
}
#if 0
/*===========================================================================
时间显示函数
============================================================================*/
void lcd_dis_time()
{
lcd_write(0x80 + 4,LCD_WRITE_COM);
lcd_write((hour / 10) + 0x30,LCD_WRITE_DATA);
lcd_write((hour % 10) + 0x30,LCD_WRITE_DATA);
lcd_write((min / 10) + 0x30,LCD_WRITE_DATA);
lcd_write((min % 10) + 0x30,LCD_WRITE_DATA);
lcd_write((sec / 10) + 0x30,LCD_WRITE_DATA);
lcd_write((sec % 10) + 0x30,LCD_WRITE_DATA);
}
#endif
上一篇:单片机实验——4X4矩阵键盘识别技术
下一篇:基于51单片机的LCD液晶屏
推荐阅读最新更新时间:2024-03-16 16:06