CT107D 数码管动态显示
#include<reg52.h>
#include<intrins.h>
void hdw_init();
void smg_refresh();
void Delay1ms();
unsigned char num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char duan[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char smg[8]={1,2,3,4,5,6,7,8};
unsigned char x;
void main()
{
hdw_init();
while(1)
{
smg_refresh();
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 12;
j = 169;
do
{
while (--j);
} while (--i);
}
void hdw_init()
{
P2=0xA0;
P0=0x00;
P2=0x00;
P2=0x80;
P0=0xFF;
P2=0x00;
}
void smg_refresh()
{
for(x=0;x<8;x++)
{
P2=0xC0;
P0=duan[x];
P2=0x00;
P2=0xE0;
P0=num[smg[x]];
Delay1ms();
P0=0xFF;
P2=0x00;
}
}核心代码讲解
void smg_refresh()
{
for(x=0;x<8;x++)
{
P2=0xC0;
P0=duan[x];
P2=0x00;
P2=0xE0;
P0=num[smg[x]];
Delay1ms();
P0=0xFF;
P2=0x00;
}
}P2=0xC0;使得Y6C被选通,然后就可以选择指定的数码管进行显示
P2=0xE0; 使得Y7C被选通,然后就可以发送需要显示的值到指定的数码管
P0=num[smg[x]]; Delay1ms(); P0=0xFF; P2=0x00;



