stc89c52lcd1602驱动代码
时间: 2023-10-06 21:08:22 浏览: 74
下面是一个简单的stc89c52+lcd1602的驱动代码,你可以参考一下:
```c
#include <reg52.h>
#define LCD_DAT P2
sbit LCD_RS = P1^0;
sbit LCD_RW = P1^1;
sbit LCD_EN = P1^2;
void initLcd1602();
void writeCommand(unsigned char cmd);
void writeData(unsigned char dat);
void delay(unsigned int i);
void main()
{
initLcd1602();
writeCommand(0x80); // 设置光标位置
writeData('H');
writeData('e');
writeData('l');
writeData('l');
writeData('o');
writeData(',');
writeData('W');
writeData('o');
writeData('r');
writeData('l');
writeData('d');
while(1);
}
void initLcd1602()
{
writeCommand(0x38); // 8位数据,2行显示,5*7点阵
writeCommand(0x0C); // 显示开、光标不可见、光标闪烁关闭
writeCommand(0x06); // 数据写入后光标右移,地址自动加1
writeCommand(0x01); // 清屏
}
void writeCommand(unsigned char cmd)
{
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
LCD_DAT = cmd;
delay(1);
LCD_EN = 1;
delay(1);
LCD_EN = 0;
}
void writeData(unsigned char dat)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
LCD_DAT = dat;
delay(1);
LCD_EN = 1;
delay(1);
LCD_EN = 0;
}
void delay(unsigned int i)
{
while(i--);
}
```
注:这只是一个简单的示例代码,实际应用可能需要根据具体情况进行修改。
阅读全文