#include <reg51.h>
#define uchar unsigned char //0--255
#define uint unsigned int //0--65535 0.065S
uint n;
uchar ge,shi,bai,qian,wan;
sbit w1= P2^0;
sbit w2= P2^1;
sbit w3= P2^2;
sbit w4= P2^3;
sbit w5= P2^4;
sbit w6= P2^5;
uchar code shuzi[ ]={ 0Xc0,0Xf9 ,0Xa4 , 0Xb0, 0X99,0X92,0X82, 0Xf8, 0X80,0X90};
// 0 1 2 3 4 5 6
//===================
void delay(uint tt) //延时tt ms
{uchar j;
for(tt;tt>0;tt-- )
for(j=123;j>0;j++ );//1ms
}
void shuju( )
{
ge=n%10;//1
shi=n/10%10;//2
bai=n/100%10;//2
qian=n/1000%10;
wan=n/10000%10;
}
//===================
void disp( )
{
w1=0; //开位码
P0=~shuzi[ge ];//送段码
delay(10); // 延时
w1=1; //关闭位
w2=0;
P0=~shuzi[shi ];//0111 1110
delay(10);
w2=1;
w3=0;
P0=~shuzi[bai ];//0111 1110
delay(10);
w3=1;
w4=0;
P0=~shuzi[qian ];//0111 1110
delay(10);
w4=1;
w5=0;
P0=~shuzi[wan ];//0111 1110
delay(10);
w5=1;
}
//===================
//===================
void main()
{ n=65000;
while(1)
{
shuju( );
disp( );
n++;
// n++;//n=n+1
//if(++n>9)n=0;
}
}
|