LED旋轉(zhuǎn)時鐘制作(有源代碼)
disp1=BUFFER[2]/10;disp2=BUFFER[5]-(BUFFER[5]/10)*10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[2]-disp1*10;disp2=BUFFER[5]/10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
ii=160;jj=160;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[1]/10;disp2=BUFFER[6]-(BUFFER[6]/10)*10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
disp1=BUFFER[1]-disp1*10;disp2=BUFFER[6]/10;
ii=disp1*16;jj=disp2*16;
num_led(ii,jj);
P2=0xff;P1=0xff;Delay(60);
}
void timer0(void) interrupt 1 using 1
{
TMOD=0x11;
TH0=-(5000/256);
TL0=-(5000%256);
TR0=1;
BUFFER[0]=BUFFER[0]+1;
if (BUFFER[6]%4==0) M[1]=M[1]+1;
if (BUFFER[0]>201+xz){
BUFFER[0]=0;
BUFFER[1]=BUFFER[1]+1;
if (BUFFER[1]==60){
BUFFER[1]=0;
BUFFER[2]=BUFFER[2]+1;
if (BUFFER[2]==60){
BUFFER[2]=0;
BUFFER[3]=BUFFER[3]+1;
if (BUFFER[3]==24){
BUFFER[3]=0;
BUFFER[4]=BUFFER[4]+1;
if (BUFFER[4]>M[BUFFER[5]-1]){
BUFFER[4]=1;
BUFFER[5]=BUFFER[5]+1;
if (BUFFER[5]>12){
BUFFER[5]=1;
BUFFER[6]=BUFFER[6]+1;
if(BUFFER[6]>99) {
BUFFER[6]=0;
M[1]=M[1]-1;
}
}
}
}
}
}
}
}
void intersvr0(void) interrupt 0
{
sw=1;
}
void main(void)
{
xz=8;
key1=1;key2=0;
EA=1;
IT0=1;EX0=1;
IT1=1;ET0=1;
TMOD=0x11;
TH0=-5000/256; TL0=-5000%256;
TR0=1;
for(;;){
Delay(10);
if(sw==1) {display_clock();sw=0;}
}
}
評論