如下图所示,段码屏的逻辑设计其实与驱动芯片是匹配的。
请问大家有没有做过类似设计,一般显示层怎么转换呢?
LCD段码屏如何比较好地编写驱动程序或中间件?
我公司商业级别的源码,10多年前两次过很多,楼主自己慢慢看吧!
ht1621.h
#ifndef __HT1621B_H_
#define __HT1621B_H_
#define LCD_BIT_BUF_LEN 6
#define LCD_START_ADDR (21)
extern uint8 LCD_BitBuf[LCD_BIT_BUF_LEN];
#define LCD_WR_1 {O_1621_WR_1;}
#define LCD_WR_0 {O_1621_WR_0;}
#define LCD_DAT_1 {O_1621_DAT_1;}
#define LCD_DAT_0 {O_1621_DAT_0;}
#define LCD_CS_1 {O_1621_CS_1;}
#define LCD_CS_0 {O_1621_CS_0;}
void LCD_WriteCMD(uint8 cmd);
void LCD_WriteDAT(uint8 addr,uint8 dat);
#define CMD_SYS_DIS 0x00
#define CMD_SYS_EN 0x01
#define CMD_LCD_OFF 0x02
#define CMD_LCD_ON 0x03
#define CMD_TIMER_DIS 0x04
#define CMD_WDT_DIS 0x05
#define CMD_TIMER_EN 0x06
#define CMD_WDT_EN 0x07
#define CMD_TONE_OFF 0x08
#define CMD_TONE_ON 0x09
#define CMD_CLR_TIMER 0x0c
#define CMD_CLR_WDT 0x0e
#define CMD_XTAL_32K 0x16
#define CMD_RC_256K 0x18
#define CMD_EXT_256K 0x1c
#define CMD_BIAS_1_2_O2 0x20
#define CMD_BIAS_1_2_O3 0x24
#define CMD_BIAS_1_2_O4 0x28
#define CMD_BIAS_1_3_O2 0x21
#define CMD_BIAS_1_3_O3 0x25
#define CMD_BIAS_1_3_O4 0x29
#define CMD_IRQ_DIS 0x80
#define CMD_IRQ_EN 0x88
#define CMD_NORMAL 0xe3
void LCD_IO_init(void);
void LCD_init(void);
void LCD_WriteBuf(void);
void LCD_SetBit(uint8 b);
void LCD_ClrBit(uint8 b);
void LCD_SetFullScr(uint8 dat);
void LCD_ClrBuf(void);
void LCD_ClrScr(void);
uint8 LCD_GetBit(uint8 b);
void LCD_BL_ON(void);
void LCD_BL_OFF(void);
//++++++++++++++++++++++++++ LCD 笔画定义 +++++++++++++++++++++++++++++//
#if 0
#define COM1 0
#define COM2 1
#define COM3 2
#define COM4 3
#define SEG1 0
#define SEG2 0x04
#define SEG3 0x10
#define SEG4 0x14
#define SEG5 0x20
#define SEG6 0x24
#define SEG7 0x30
#define SEG8 0x34
#define SEG9 0x40
#define SEG10 0x44
#define SEG11 0x50
#define SEG_12 0x54
#endif
#define COM1 0
#define COM2 1
#define COM3 2
#define COM4 3
#define SEG1 0
#define SEG2 4
#define SEG3 8
#define SEG4 12
#define SEG5 16
#define SEG6 20
#define SEG7 24
#define SEG8 28
#define SEG9 32
#define SEG10 36
#define SEG11 40
#define SEG_12 44
#define LCD_ICON_SLEEP (SEG2+COM4)
#define LCD_ICON_TIMER (SEG6+COM4)
#define LCD_ICON_HEAT (SEG8+COM4)
#define LCD_ICON_SWING (SEG9+COM4)
#define LCD_ICON_FAN_1 (SEG11+COM3)
#define LCD_ICON_FAN_2 (SEG11+COM2)
#define LCD_ICON_FAN_3 (SEG11+COM1)
#define LCD_ICON_DRY (SEG11+COM4)
#define LCD_ICON_COLD (SEG9+COM1)
#define LCD_ICON_WIND_X (SEG10+COM1)
#define LCD_ICON_WIND_Y (SEG10+COM2)
#define LCD_ICON_WIND_Z (SEG10+COM4)
#define LCD_ICON_WIND_R (SEG10+COM3)
#define LCD_ICON_CLK (SEG4+COM4)
#define LCD_1stNUM_a (SEG1+COM4)
#define LCD_1stNUM_b (SEG2+COM3)
#define LCD_1stNUM_c (SEG2+COM2)
#define LCD_1stNUM_d (SEG2+COM1)
#define LCD_1stNUM_e (SEG1+COM1)
#define LCD_1stNUM_f (SEG1+COM3)
#define LCD_1stNUM_g (SEG1+COM2)
#define LCD_2ndNUM_a (SEG3+COM4)
#define LCD_2ndNUM_b (SEG4+COM3)
#define LCD_2ndNUM_c (SEG4+COM2)
#define LCD_2ndNUM_d (SEG4+COM1)
#define LCD_2ndNUM_e (SEG3+COM1)
#define LCD_2ndNUM_f (SEG3+COM3)
#define LCD_2ndNUM_g (SEG3+COM2)
#define LCD_3ndNUM_a (SEG5+COM4)
#define LCD_3ndNUM_b (SEG6+COM3)
#define LCD_3ndNUM_c (SEG6+COM2)
#define LCD_3ndNUM_d (SEG6+COM1)
#define LCD_3ndNUM_e (SEG5+COM1)
#define LCD_3ndNUM_f (SEG5+COM3)
#define LCD_3ndNUM_g (SEG5+COM2)
#define LCD_4ndNUM_a (SEG7+COM4)
#define LCD_4ndNUM_b (SEG8+COM3)
#define LCD_4ndNUM_c (SEG8+COM2)
#define LCD_4ndNUM_d (SEG8+COM1)
#define LCD_4ndNUM_e (SEG7+COM1)
#define LCD_4ndNUM_f (SEG7+COM3)
#define LCD_4ndNUM_g (SEG7+COM2)
#if 0
#define LCD_ICON_SLEEP 8
#define LCD_ICON_TIMER 24
#define LCD_ICON_HEAT 32
#define LCD_ICON_SWING 36
#define LCD_ICON_FAN_1 43
#define LCD_ICON_FAN_2 42
#define LCD_ICON_FAN_3 41
#define LCD_ICON_DRY 44
#define LCD_ICON_COLD 33
#define LCD_ICON_WIND_X 37
#define LCD_ICON_WIND_Y 38
#define LCD_ICON_WIND_Z 40
#define LCD_ICON_WIND_R 39
#define LCD_ICON_CLK 16
#define LCD_1stNUM_a 4
#define LCD_1stNUM_b 7
#define LCD_1stNUM_c 6
#define LCD_1stNUM_d 5
#define LCD_1stNUM_e 0 (SEG_1+COM_1)
#define LCD_1stNUM_f 3
#define LCD_1stNUM_g 1
#define LCD_2ndNUM_a 12
#define LCD_2ndNUM_b 15
#define LCD_2ndNUM_c 14
#define LCD_2ndNUM_d 13
#define LCD_2ndNUM_e 9
#define LCD_2ndNUM_f 11
#define LCD_2ndNUM_g 10
#define LCD_3ndNUM_a 20
#define LCD_3ndNUM_b 23
#define LCD_3ndNUM_c 22
#define LCD_3ndNUM_d 21
#define LCD_3ndNUM_e 17
#define LCD_3ndNUM_f 19
#define LCD_3ndNUM_g 18
#define LCD_4ndNUM_a 28
#define LCD_4ndNUM_b 31
#define LCD_4ndNUM_c 30
#define LCD_4ndNUM_d 29
#define LCD_4ndNUM_e 25
#define LCD_4ndNUM_f 27
#define LCD_4ndNUM_g 26
#endif
#define LCD_NULL 0xff
//-------------------------- LCD 笔画定义 -----------------------------//
void LCD_Num(uint8 x,uint8 num);
void LCD_ClrNum(uint8 x);
void LCD_BCD(uint16 num);
void LCD_BCD12(uint8 num);
void LCD_BCD34(uint8 num);
void LCD_HEX12(uint8 num);
void LCD_HEX34(uint8 num);
#endif
ht1621.c
uint8 LCD_BitBuf[LCD_BIT_BUF_LEN]={0,0,0,0,0,0};
#if 0
void _LCD_Delay(void){
uint8 i=10;
while(i>0) i--;
}
#else
#define _LCD_Delay() {asm("nop");}
#endif
void __LCD_WriteBit(uint8 dat,uint8 bitnum){
uint8 i;
dat<<=(8-bitnum);
for(i=0;i<bitnum;i++){
LCD_WR_0;
if(dat&0x80){
LCD_DAT_1;
}else{
LCD_DAT_0;
}
dat<<=1;
_LCD_Delay();
LCD_WR_1;
_LCD_Delay();
}
}
void LCD_WriteCMD(uint8 cmd){
//uint8 i;
LCD_CS_1;
LCD_WR_1;
LCD_DAT_1;
_LCD_Delay();
LCD_CS_0;
_LCD_Delay();
__LCD_WriteBit(0x04, 3);
__LCD_WriteBit(cmd,8);
__LCD_WriteBit(0,1);
LCD_CS_1;
LCD_DAT_1;
LCD_WR_1;
}
void __LCD_WriteBuf(uint8 addr,uint8 isClr){
uint8 bufPt,cTmp;
LCD_CS_1;
LCD_WR_1;
LCD_DAT_1;
_LCD_Delay();
LCD_CS_0;
_LCD_Delay();
__LCD_WriteBit(0x5,3);
__LCD_WriteBit(addr,6);
for(bufPt=0;bufPt<LCD_BIT_BUF_LEN;bufPt++){
if(isClr){
cTmp=0;
}
else{
cTmp=LCD_BitBuf[bufPt];
}
__LCD_WriteBit(cTmp,8);
}
LCD_CS_1;
LCD_DAT_1;
LCD_WR_1;
}
void LCD_WriteBuf(void){
__LCD_WriteBuf(LCD_START_ADDR,0);
}
#if 1
void LCD_SetBit(uint8 b){
uint8 tmp;
//if(b>=LCD_BIT_BUF_LEN*8) return;
tmp=7-(b%8);
LCD_BitBuf[b/8]|=(uint8)(1<<tmp);
}
void LCD_ClrBit(uint8 b){
uint8 tmp;
//if(b>=LCD_BIT_BUF_LEN*8) return;
tmp=7-(b%8);
LCD_BitBuf[b/8]&=(uint8)(~(1<<tmp));
}
uint8 LCD_GetBit(uint8 b){
if(LCD_BitBuf[b/8] & (1<<(7-(b%8)))){
return 1;
}
return 0;
}
#endif
#if 0
void LCD_SetBit(uint8 b){
LCD_BitBuf[b>>4]|=BIT(b&0x0f);
}
void LCD_ClrBit(uint8 b){
LCD_BitBuf[b>>4]&=(~ BIT(b&0x0f));
}
#endif
void LCD_SetFullScr(uint8 dat){
//memset(LCD_BitBuf,dat,LCD_BIT_BUF_LEN);
uint8 i;
for(i=0;i<LCD_BIT_BUF_LEN;i++){
LCD_BitBuf[i]=dat;
}
LCD_WriteBuf();
}
#if 0
void LCD_ClrBuf(void){
memset(LCD_BitBuf,0,LCD_BIT_BUF_LEN);
}
#endif
void LCD_ClrScr(void){
__LCD_WriteBuf(16,1);
}
#if 0
const uint8 LCD_NumPos[] @ 0x0002={
LCD_1stNUM_a,
LCD_1stNUM_b,
LCD_1stNUM_c,
LCD_1stNUM_d,
LCD_1stNUM_e,
LCD_1stNUM_f,
LCD_1stNUM_g,
LCD_2ndNUM_a,
LCD_2ndNUM_b,
LCD_2ndNUM_c,
LCD_2ndNUM_d,
LCD_2ndNUM_e,
LCD_2ndNUM_f,
LCD_2ndNUM_g,
LCD_3ndNUM_a,
LCD_3ndNUM_b,
LCD_3ndNUM_c,
LCD_3ndNUM_d,
LCD_3ndNUM_e,
LCD_3ndNUM_f,
LCD_3ndNUM_g,
LCD_4ndNUM_a,
LCD_4ndNUM_b,
LCD_4ndNUM_c,
LCD_4ndNUM_d,
LCD_4ndNUM_e,
LCD_4ndNUM_f,
LCD_4ndNUM_g,
};
const uint8 LCD_NumModel[] @ 0x001e={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, // 0--9
0x77, //10: A
0x7c,//11:b
0x39,//12:C
0x5e,//13:d
0x79,//14:E
0x71,//15:F
0x00, //16:NULL
0x38,//17:L
0x76,//18:H
0x63, //19:o
0x73, //20:P
};
void LCD_Num(uint8 x,uint8 num){
uint8 cTmp;
uint8 i;
cTmp=LCD_NumModel[num];
for(i=0;i<7;i++){
#if 1
if(cTmp&0x01){
LCD_SetBit(LCD_NumPos[(x*7)+i]);
}
else{
LCD_ClrBit(LCD_NumPos[(x*7)+i]);
}
#endif
cTmp>>=1;
}
}
#endif
#if 1
const uint8 LCD_NumModel[] @ 0x00e3={
0xbe,0x06,0xda,0x5e,0x66,0x7c,0xfc,0x16,0xfe,0x7e, // 0--9
0xf6, //10: A
0xec,//11:b
0xb8,//12:C
0xce,//13:d
0xf8,//14:E
0xf0,//15:F
0x00, //16:NULL
0xa8,//17:L
0xe6,//18:H
0x72, //19:o
0xf2, //20:P
0x40, //21:-
};
void LCD_Num(uint8 x,uint8 num){
uint8 cTmp;
cTmp=LCD_NumModel[num];
LCD_BitBuf[x]=cTmp;
}
#endif
void LCD_ClrBuf(void){
uint8 i;
for(i=0;i<LCD_BIT_BUF_LEN;i++){
LCD_BitBuf[i]=0;
}
}
#if 0
void LCD_ClrNum(uint8 x){
uint8 i;
for(i=0;i<7;i++){
LCD_ClrBit(LCD_NumPos[(x*7)+i]);
}
}
void LCD_BCD(uint16 num){
LCD_Num(3, num%10);
num/=10;
LCD_Num(2, num%10);
num/=10;
LCD_Num(1, num%10);
num/=10;
LCD_Num(0, num%10);
LCD_WriteBuf();
}
void LCD_BCD12(uint8 num){
LCD_Num(1, num%10);
num/=10;
LCD_Num(0, num%10);
LCD_WriteBuf();
}
void LCD_BCD34(uint8 num){
LCD_Num(3, num%10);
num/=10;
LCD_Num(2, num%10);
LCD_WriteBuf();
}
void LCD_HEX12(uint8 num){
LCD_Num(1,num&0x0f);
LCD_Num(0,num>>4);
LCD_WriteBuf();
}
void LCD_HEX34(uint8 num){
LCD_Num(3,num&0x0f);
LCD_Num(2,num>>4);
LCD_WriteBuf();
}
#endif
void LCD_init(void){
//uint8 i;
//LCD_CS_1;
LCD_WriteCMD(CMD_LCD_ON);
LCD_WriteCMD(CMD_SYS_EN);
LCD_WriteCMD(CMD_BIAS_1_3_O4);
LCD_WriteCMD(CMD_NORMAL);
LCD_WriteCMD(CMD_RC_256K);
LCD_WriteCMD(CMD_WDT_EN);
LCD_SetFullScr(0xff);
//memset(LCD_BitBuf,0xff,LCD_BIT_BUF_LEN);
//LCD_WriteBuf();
//LCD_Num(3,1);
//LCD_Num(2,2);
//LCD_Num(1,3);
//LCD_Num(0,4);
//LCD_WriteBuf();
}
void LCD_BL_ON(void){
LCD_WriteCMD(CMD_IRQ_EN);
}
void LCD_BL_OFF(void){
LCD_WriteCMD(CMD_IRQ_DIS);
}
回复
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |