初学数码管的时候,曾经被数码管显示的亮度折磨过一段时间,现在来总结一遍自己对数码管的理解。
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
---|
0xC0 | 0xF9 | 0xA4 | 0xB0 | 0x99 | 0x92 | 0x82 | 0xF8 | 0x80 | 0x90 | 0x88 | 0x83 | 0xC6 | 0xA1 | 0x86 | 0x8E |
数码管又称 「 八位共阴/共阳数码管 」,简单来说就是一位数码管由八段组成,而让每段亮灭需要根据是共阳还是共阴来操作。
蓝桥杯的SMG是共阳极数码管
网上关于smg的讲解太多了,我就不讲了,依旧是从模板的角度出发,直接上代码分析记录
| 无小数点SmgNoDot | 有小数点SmgDot |
---|
共阳数码管 | 0xc0,0xf9,0xa4,0xb0,0x99, 0x92,0x82,0xf8,0x80,0x90, 0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf | 0x40,0x79,0x24,0x30, 0x19,0x12,0x02,0x78 0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e,0x3f | 共阴数码管 | 0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f, 0x77,0x7c,0x39,0x5e,0x79,0x71 | 0xbf,0x86,0xdb,0xcf,0xe6 0xed,0xfd,0x87,0xff,0x6f, 0xf7,0xfc,0xb9,0xde,0xf9,0xf1 |
代码仿照小蜜蜂 这部分数组代码蓝桥杯有专门文件会提供哦,不用担心现写写错
共阳数码管(无小数):unsigned char code smg[]={0xc0,0xf9,0xa4,0xb0,0x99, 0x92,0x82,0xf8,0x80,0x90, 0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};
共阴数码管(无小数):unsigned char code smg[]={0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f, 0x77,0x7c,0x39,0x5e,0x79,0x71};
共阳数码管(有小数):unsigned char code smg[] = {0x40,0x79,0x24,0x30, 0x19,0x12,0x02,0x78 ,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e,0x3f};
共阴数码管(有小数):unsigned char code smg[] = {0xbf,0x86,0xdb,0xcf,0xe6 0xed,0xfd,0x87,0xff,0x6f, 0xf7,0xfc,0xb9,0xde,0xf9,0xf1};
静态显示Static_show()
#include"reg52.h"
unsigned char code SmgNoDot[18] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
void delay(unsigned int t)
{
while(t--);
}
void Show_bit(unsigned char value,unsigned char pos)
{
P2 = (P2 & 0x1f)| 0xc0;P0 = 0x01 << pos;P2 &= 0x1f;
P2 = (P2 & 0x1f)| 0xe0;P0 = value;P2 &= 0x1f;
}
void Static_show()
{
char i,j;
for(i = 0;i < 8;i++)
{
for(j = 0;j < 10;j++)
{
Show_bit(SMG_D[j],i);
delay(60000);
}
}
P2 = P2 & 0x1f | 0xc0;P0 = 0xff;P2 &= 0x1f;
for(i = 0;i < 16;i++)
{
P2 = P2 & 0x1f | 0xe0;P0 = SMG_D[i];P2 &= 0x1f;
delay(60000);
}
}
void main()
{
P2 = P2 & 0x1f | 0xa0;P0 = 0;P2 &= 0x1f;
while(1)
{
static_show();
}
}
动态显示
void SMG_Delay(){
unsigned int t = 500;
while(t--);
}
void SMG_ShowBit(unsigned int value,unsigned int pos){
Init74HC138(6);
P0 = (0x01 << pos);
Init74HC138(7);
P0 = value;
}
void Dynamic_show(unsigned int dat){
SMG_ShowBit(SMG_NoDot[2],0);SMG_Delay();
SMG_ShowBit(SMG_NoDot[0],1);SMG_Delay();
SMG_ShowBit(SMG_NoDot[2],2);SMG_Delay();
SMG_ShowBit(SMG_NoDot[1],3);SMG_Delay();
SMG_ShowBit(SMG_NoDot[1],4);SMG_Delay();
SMG_ShowBit(SMG_NoDot[3],5);SMG_Delay();
SMG_ShowBit(SMG_NoDot[1],6);SMG_Delay();
SMG_ShowBit(SMG_NoDot[4],7);SMG_Delay();
}
|