显示屏的驱动芯片作用(最简单的显示屏)
显示屏的驱动芯片作用(最简单的显示屏)
数字2的段码查询
//数码管显示程序
//事先输入查询好的各个字符的段码
uint8_t SEGPLAY[] = { 0xC0 //"0"
0xF9 //"1"
0xA4 //"2"
0xB0 //"3"
0x99 //"4"
0x92 //"5"
0x82 //"6"
0xF8 //"7"
0x80 //"8"
0x90 //"9"
// 0x88 //"A"
// 0x83 //"B"
// 0xC6 //"C"
// 0xA1 //"D"
// 0x86 //"E"
// 0x8E //"F"
// 0x89 //"H"
// 0xC7 //"L"
// 0xC8 //"n"
// 0xC1 //"u"
// 0x8C //"P"
// 0xA3 //"o"
// 0xBF //"-"
// 0xFF //熄灭
// 0xFF //自定义
};
//定义位码,也就是1到8位的数码管的代码
uint8_t DIG[] = {0b10000000
0b01000000
0b00100000
0b00010000
0b00001000
0b00000100
0b00000010
0b00000001
};
//定义三个引脚
#define latchPin 10
#define clockPin 11
#define dataPin 12
void setup() {
//定义三个引脚为输出
pinMode(latchPin OUTPUT);
pinMode(clockPin OUTPUT);
pinMode(dataPin OUTPUT);
}
void loop()
{
playnum (1308 5014); //显示 13085014
delay(20);
}
//
//函数作用:用于两个四位数码管显示数字
//输入值:unsigned int 范围0-9999 //
//返回值: 无 //
void playnum (unsigned int i unsigned int j)
{
SegDisplay(i / 1000 0);
SegDisplay((i % 1000) / 100 1);
SegDisplay((i % 100) / 10 2);
SegDisplay((i % 10) 3);
SegDisplay( j / 1000 4);
SegDisplay((j % 1000) / 100 5);
SegDisplay((j % 100) / 10 6);
SegDisplay((j % 10) 7);
}
//
//函数作用:用于单位数码管显示数字
//输入值:i 范围0-11 //
// 显示位置 1-4 //
//返回值: 无 //
void SegDisplay(int i int j)
{
digitalWrite(latchPin LOW);
shiftOut(dataPin clockPin LSBFIRST DIG[j]); //位选
shiftOut(dataPin clockPin MSBFIRST SEGPLAY[i]);//段选
digitalWrite(latchPin HIGH);
delayMicroseconds(500);//调节这个和下面的参数可以调整显示亮度,建议这两个数加起来为860。这样是为了显示时间准确
// delayMicroseconds(360);
}