/**
* Wire connection
* MCU Pin: COM3 COM2 COM1 COM0 SEG0 SEG5 SEG4 SEG3 SEG2 SEG1
* MCU Pin: P10 P11 P12 P13 P40 P45 P44 P43 P42 P41
* LCD Pin: 1 2 3 4 5 6 7 8 9 10
* --------------------------------------------------------------
* COM1 COM1 4G 1A 4D 2A 4A 3A
* COM2 COM2 1F 1B 2F 2B 3F 3B
* COM3 COM3 1G 1C 2G 2C 3G 3C
* COM4 COM4 1E 1D 2E 2D 3E 3D
*/
void ShowDigitFor888E(UINT8 digitPlace, UINT8 num, UINT8 tempUnit) {
UINT8 segABCD = 0;
UINT8 segEFG = 0;
// 参数检查
if ((digitPlace < 1 || digitPlace > 3) ||
(num > 9)) {
return;
}
// MCU's SEG0-5 Enable
// SEG0-SEG7 由 LCDSEG0 寄存器管理
LCDSEG0 = SET_BIT0 | SET_BIT1 | SET_BIT2 | SET_BIT3 | SET_BIT4 | SET_BIT5;
// 根据实际的引脚连接,以及LCD模块的段码表,确定改变哪些SEG的数据
// 每个SEG是一个8位数据,1/4Duty时,高4位不使用,低4位的数据就是段码表的COM1-4的数据
switch (digitPlace)
{
case 1:
segABCD = 5;
segEFG = 0;
break;
case 2:
segABCD = 3;
segEFG = 4;
break;
case 3:
segABCD = 1;
segEFG = 2;
break;
default:
break;
}
// 确定了SEG以后,开始设置数字各段数据(其实可以全部计算出来结果放在一个code数组里即可)
// 设置ABCD段数据(COM0-A,COM1-B,COM2-C,COM3-D)
LCDPTR = segABCD;
switch (num)
{
case 0:
LCDDAT = COM0 | COM1 | COM2 | COM3;
break;
case 1:
LCDDAT = COM1 | COM2;
break;
case 2:
LCDDAT = COM0 | COM1 | COM3;
break;
case 3:
LCDDAT = COM0 | COM1 | COM2 | COM3;
break;
case 4:
LCDDAT = COM1 | COM2;
break;
case 5:
LCDDAT = COM0 | COM2 | COM3;
break;
case 6:
LCDDAT = COM0 | COM2 | COM3;
break;
case 7:
LCDDAT = COM0 | COM1 | COM2;
break;
case 8:
LCDDAT = COM0 | COM1 | COM2 | COM3;
break;
case 9:
LCDDAT = COM0 | COM1 | COM2 | COM3;
break;
default:
break;
}
// 设置EFG段数据(COM1-F,COM2-G,COM3-E)
LCDPTR = segEFG;
switch (num)
{
case 0:
LCDDAT = COM1 | COM3;
break;
case 1:
LCDDAT = 0x00;
break;
case 2:
LCDDAT = COM2 | COM3;
break;
case 3:
LCDDAT = COM2;
break;
case 4:
LCDDAT = COM1 | COM2;
break;
case 5:
LCDDAT = COM1 | COM2;
break;
case 6:
LCDDAT = COM1 | COM2 | COM3;
break;
case 7:
LCDDAT = 0x00;
break;
case 8:
LCDDAT = COM1 | COM2 | COM3;
break;
case 9:
LCDDAT = COM1 | COM2;
break;
default:
break;
}
// 设置摄氏度符号段数据(COM0-SEG0,2,4)
// 注意这里要用或计算,不然会覆盖之前设置好的数字部分的段码数据
switch (tempUnit)
{
case 0xC:
LCDPTR = 2; // 4A段 set
LCDDAT |= COM0;
LCDPTR = 4; // 4D段 set
LCDDAT |= COM0;
LCDPTR = 0; // 4G段 clear
LCDDAT &= ~COM0;
break;
case 0xF:
LCDPTR = 2; // 4A段 set
LCDDAT |= COM0;
LCDPTR = 4; // 4D段 clear
LCDDAT &= ~COM0;
LCDPTR = 0; // 4G段 set
LCDDAT |= COM0;
break;
default:
LCDPTR = 2; // 4A段 clear
LCDDAT &= ~COM0;
LCDPTR = 4; // 4D段 clear
LCDDAT &= ~COM0;
LCDPTR = 0; // 4G段 clear
LCDDAT &= ~COM0;
break;
}
}
|