//以lcd段码屏驱动芯片TM1621D为例子
//
typedef union{
struct{
uint8_t a :1;
uint8_t b :1;
uint8_t c :1;
uint8_t d :1;
uint8_t e :1;
uint8_t f :1;
uint8_t g :1;
uint8_t dp :1;
}Bits;
uint8_t Value;
}unionByte;//一位数码管显示共用体
typedef union{
struct{
uint8_t _0 :1;
uint8_t _1 :1;
uint8_t _2 :1;
uint8_t _3 :1;
uint8_t _4 :1;
uint8_t _5 :1;
uint8_t _6 :1;
uint8_t _7 :1;
}Bits;
uint8_t Value;
}unionSegByte;//一位数码管段位转换共用体
//定义LCD屏驱动数据 根据驱动芯片 四位数内容数据
unionSegByte unionSegByte1;
unionSegByte unionSegByte2;
unionSegByte unionSegByte3;
unionSegByte unionSegByte4;
unionSegByte unionSegByte5;
unionByte Byte[4];//定义四位数显示码值 如第一位显示‘0’则将码表数组中第0个元素0x3f赋给Byte[0]
uint8_t table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //0-F 码表值 共阴 因为点亮其中一段需要写1
//lcd驱动数据 加载 转换
void lcd_data_load_conver(uint8_t *pdata)
{
Byte[0].Value = table[pdata[0]];//将显示内容通过码表转换出对应码值 通过定义的共用体 对应的位将会自动转换成1或0
Byte[1].Value = table[pdata[1]];
Byte[2].Value = table[pdata[2]];
Byte[3].Value = table[pdata[3]];
//以下转换关系需根据段码屏真值表一一对应 数据高位先发
unionSegByte1.Value = 0;//清零显示数据
unionSegByte1.Bits._6 = 0;//PM
unionSegByte1.Bits._5 = (Byte[0].Bits.a | Byte[0].Bits.d | Byte[0].Bits.e | Byte[0].Bits.g);//1ADEG
unionSegByte1.Bits._3 = Byte[0].Bits.b;//1B
unionSegByte1.Bits._2 = Byte[0].Bits.c;//1C
unionSegByte1.Bits._1 = Byte[1].Bits.e;//
unionSegByte2.Value = 0;
unionSegByte2.Bits._7 = Byte[1].Bits.f;//2F
unionSegByte2.Bits._6 = Byte[1].Bits.g;//2G
unionSegByte2.Bits._5 = Byte[1].Bits.d;//2D
unionSegByte2.Bits._3 = Byte[1].Bits.a;//2A
unionSegByte2.Bits._2 = Byte[1].Bits.b;//2B
unionSegByte2.Bits._1 = Byte[1].Bits.c;//2C
unionSegByte3.Value = 0;
unionSegByte3.Bits._7 = state;//COL
unionSegByte3.Bits._6 = 0;//AL
unionSegByte3.Bits._5 = Byte[3].Bits.e;//4E
unionSegByte3.Bits._3 = Byte[2].Bits.f;//3F
unionSegByte3.Bits._2 = Byte[2].Bits.g;//3G
unionSegByte3.Bits._1 = Byte[2].Bits.e;//3E
unionSegByte4.Value = 0;
unionSegByte4.Bits._7 = (Byte[2].Bits.a | Byte[2].Bits.d);//3AD
unionSegByte4.Bits._6 = Byte[2].Bits.b;//3B
unionSegByte4.Bits._5 = Byte[2].Bits.c;//3C
unionSegByte4.Bits._3 = Byte[3].Bits.f;//4F
unionSegByte4.Bits._2 = Byte[3].Bits.g;//4G
unionSegByte4.Bits._1 = Byte[3].Bits.d;//4D
unionSegByte5.Value = 0;
unionSegByte5.Bits._7 = Byte[3].Bits.a;//4A
unionSegByte5.Bits._6 = Byte[3].Bits.b;//4B
unionSegByte5.Bits._5 = Byte[3].Bits.c;//4C
LCD_DisplayBuf[0] = unionSegByte1.Value;
LCD_DisplayBuf[1] = unionSegByte2.Value;
LCD_DisplayBuf[2] = unionSegByte3.Value;
LCD_DisplayBuf[3] = unionSegByte4.Value;
LCD_DisplayBuf[4] = unionSegByte5.Value;
}
LCD段码屏 真值表转换
最新推荐文章于 2024-12-19 11:22:01 发布