数码管动态扫描显示01234567程序二——51单片机动态显示共阳数码管01234567
原理图
c语言程序
程序如下:
#include
#define uint unsigned int
#define uchar unsigned char
//共阳数码管段码表0-F
uchar code smg_dw[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
//数码管段位码表0-F
//uchar code smg_wm[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //显示01234567
uchar code smg_wm[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//显示76543210
void delay_ms(uint); //延时子函数声明
void main()
{
uchar i;
while(1)
{
for(i=0;i<8;i++)
{
P2=smg_wm[i];//选位码
P0=smg_dw[i];//选段码
delay_ms(5);//延时5ms
}
}
}
void delay_ms(uint z) //带参数延时子函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}