静态数码管
-
小知识点:看懂pdf文件,这个数码管由128译码器和数码管构成。选中LED几亮(如LED5)。看译码器LED5对应Y4,P22、P23、P24由他们决定。4 = 0x100 所以24=1,23和22=0。这个确定是那个数码管显示。
-
数字的显示:由数码管的八跟线abcdefg和dp(小数点)决定,是顺时针排序的。如果要显示6,就是b和dp不亮即可。0111 1101(7D)即可。
-
//一位数字显示 #include <REGX52.H> void show(unsigned int wz , dx){ int x[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; switch(wz) { case 1:P2_4 = 0; P2_3 = 0; P2_2 = 0; break; case 2:P2_4 = 0; P2_3 = 0; P2_2 = 1; break; case 3:P2_4 = 0; P2_3 = 1; P2_2 = 0; break; case 4:P2_4 = 0; P2_3 = 1; P2_2 = 1; break; case 5:P2_4 = 1; P2_3 = 0; P2_2 = 0; break; case 6:P2_4 = 1; P2_3 = 0; P2_2 = 1; break; case 7:P2_4 = 1; P2_3 = 1; P2_2 = 0; break; case 8:P2_4 = 1; P2_3 = 1; P2_2 = 1; break; } P0 = x[dx]; } void main(){ show(5,2); while(1){ } }
-
单片机直接扫描:硬件设备简单,但会耗费大量的单片机CPU时间。专用驱动芯片:内部自带显存、扫描电路,单片机只需告诉它显示什么即可。
-
多位显示,我这里用的是不断的去扫描显示出来的。
-
#include <REGX52.H> void Delayms(unsigned int xms) { unsigned char i, j; while(xms--){ i = 2; j = 239; do { while (--j); } while (--i); } } void show(unsigned int wz , dx){ int x[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; switch(wz) { case 1:P2_4 = 0; P2_3 = 0; P2_2 = 0; break; case 2:P2_4 = 0; P2_3 = 0; P2_2 = 1; break; case 3:P2_4 = 0; P2_3 = 1; P2_2 = 0; break; case 4:P2_4 = 0; P2_3 = 1; P2_2 = 1; break; case 5:P2_4 = 1; P2_3 = 0; P2_2 = 0; break; case 6:P2_4 = 1; P2_3 = 0; P2_2 = 1; break; case 7:P2_4 = 1; P2_3 = 1; P2_2 = 0; break; case 8:P2_4 = 1; P2_3 = 1; P2_2 = 1; break; } P0 = x[dx]; Delayms(1); //这里是为了消影。 P0 = 0x00; } void main(){ while(1){ show(8,1); Delayms(2); show(7,2); Delayms(2); show(6,3); Delayms(2); } }