HT1621段式液晶驱动代码
时间: 2023-08-03 22:09:33 浏览: 316
HT1621显示驱动代码
HT1621是一种常见的段式液晶驱动芯片,其驱动代码如下:
```c
#include <ht1621.h>
#define HT1621_WR 2 // HT1621写入引脚
#define HT1621_RD 3 // HT1621读取引脚
#define HT1621_CS 4 // HT1621片选引脚
void HT1621_Write(unsigned char data, unsigned char cnt)
{
unsigned char i;
pinMode(HT1621_WR, OUTPUT);
pinMode(HT1621_RD, OUTPUT);
pinMode(HT1621_CS, OUTPUT);
digitalWrite(HT1621_CS, LOW);
for (i = 0; i < cnt; i++)
{
digitalWrite(HT1621_WR, LOW);
shiftOut(HT1621_WR, HT1621_RD, MSBFIRST, data);
digitalWrite(HT1621_WR, HIGH);
data >>= 1;
}
digitalWrite(HT1621_CS, HIGH);
}
void HT1621_Init(void)
{
HT1621_Write(0x52, 4); // 启动系统振荡器
HT1621_Write(0x80, 3); // 设置系统时钟,1/3Duty,4COM,Bias=1/2
HT1621_Write(0xA4, 3); // 停止显示
HT1621_Write(0xEB, 4); // 设置LCD偏压电压
HT1621_Write(0x40, 8); // 初始化显示RAM
HT1621_Write(0xA6, 3); // 正常显示,不反转
}
void HT1621_Display(unsigned char *buffer, unsigned char cnt)
{
unsigned char i;
HT1621_Write(0xA4, 3); // 停止显示
HT1621_Write(0x40, 8); // 初始化显示RAM
for (i = 0; i < cnt; i++)
{
HT1621_Write(buffer[i], 4);
}
HT1621_Write(0xA2, 3); // 打开显示,不闪烁
}
```
其中,`HT1621_Write`函数用于向HT1621芯片写入数据,`HT1621_Init`函数用于初始化HT1621芯片,`HT1621_Display`函数用于显示数据。在使用HT1621芯片时,需要先调用`HT1621_Init`函数进行初始化,然后再调用`HT1621_Display`函数显示数据。
阅读全文