LCD 6800几口并口驱动
时间: 2023-11-26 17:48:16 浏览: 21
根据提供的引用内容,我可以为您介绍LCD 6800并口驱动的相关知识和方法。
LCD 6800并口驱动是一种常见的液晶屏驱动方式,它使用8位数据总线和3条控制线(RS、WR、EN)来控制液晶屏的显示。下面是一个简单的LCD 6800并口驱动的示例代码:
```c
#include <reg52.h>
#define LCD_DATA_PORT P0
sbit RS = P2^0;
sbit WR = P2^1;
sbit EN = P2^2;
void LcdWriteCmd(unsigned char cmd)
{
RS = 0;
LCD_DATA_PORT = cmd;
WR = 0;
WR = 1;
}
void LcdWriteData(unsigned char dat)
{
RS = 1;
LCD_DATA_PORT = dat;
WR = 0;
WR = 1;
}
void LcdInit()
{
LcdWriteCmd(0x38); // 设置8位数据总线,2行显示,5x7点阵字符
LcdWriteCmd(0x0c); // 开启显示,关闭光标
LcdWriteCmd(0x06); // 光标右移,字符不移动
LcdWriteCmd(0x01); // 清屏
}
void LcdDisplayString(unsigned char x, unsigned char y, unsigned char *str)
{
unsigned char i = 0;
if (y == 0) {
LcdWriteCmd(0x80 + x);
} else {
LcdWriteCmd(0x80 + 0x40 + x); }
while (str[i] != '\0') {
LcdWriteData(str[i]);
i++;
}
}
void main()
{
LcdInit();
LcdDisplayString(0, 0, "Hello, world!");
while (1);
}
```
上述代码使用了P0口作为数据总线,P2口的0、1、2号引脚分别作为RS、WR、EN控制线。在LcdInit函数中,我们设置了LCD的显示模式,并开启了显示。在LcdDisplayString函数中,我们可以通过指定x、y坐标和字符串来在LCD上显示字符串。