#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit AB=P3^0; //串行输入端
sbit CLK=P3^1; //时钟脉冲输入端,上升沿(高电平)有效
sbit CLR=P3^2; //清零端
uchar code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共阴0~9
void delaynms(uint z)
{
uchar i,k;
while(z--)
{
for(i=2;i>0;i--)
{
for(k=250;k>0;k--);
}
}
}
void display(uchar h) //数码管显示
{
uchar num,j;
CLR=1;
num=dispcode[h];
for(j=0;j<8;j++)
{
CLK=0;
AB=num&0x01; //每一位的输出
CLK=1; //每一次上升沿,输出一位数据
num=num>>1; //右移位赋值 ,以供下一位的输出
}
}
void main()
{
uchar h;
while(1)
{
for(h=0;h<10;h++)
{
display(h);
delaynms(500);
}
h=0;
}
}
|