|
源程序
#include <REG51.H>
#define uint unsigned int
#define uchar unsigned char
uchar code DIS_SEG7[]={0xf9,0x92,0xb0,0xf9,0xc0,0xa4,0xf9,0xb0};//设置学号,共阳字形码
uchar code DIS_BIT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};// 8位数码管位选
sbit k1=P1^0;
sbit k2=P1^1;
void delay1ms(uint i)
{
uint j;
while(i--)
for(j=0;j<110;j++);
}
void main(void)
{
uchar cnt,ttt;
uchar DISP[]={0,1,2,3,4,5,6,7};
while(1)
{
for(ttt=0;ttt<100;ttt++)
for(cnt=0;cnt<8;cnt++)
{//点亮数码馆0-7
P2=0;
P0=DIS_SEG7[DISP[cnt]];
P2=~DIS_BIT[cnt];
if(k1==1&&k2==1)
delay1ms(1);
else {
if(k1==0&&k2==1)
delay1ms(2);
else{
if(k1==1&&k2==0)
delay1ms(3);
else{
if(k1==0&&k2==0)
delay1ms(4);
}
}
}
}
ttt=DISP[0];
DISP[0]=DISP[1];
DISP[1]=DISP[2];
DISP[2]=DISP[3];
DISP[3]=DISP[4];
DISP[4]=DISP[5];
DISP[5]=DISP[6];
DISP[6]=DISP[7];
DISP[7]=ttt;
}
}
|
|