是個9999倒計時的,由于本論壇禁止直接求程序,禁止伸手黨,所以向大家請教一下大致的實現(xiàn)方法與思路,理清頭緒后我自己來寫程序去實現(xiàn)
#include <reg51.h>
sbit DGT0=P2^3;
sbit DGT1=P2^2;
sbit DGT2=P2^1;
sbit DGT3=P2^0;
unsigned char code LedChar[]={
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned char LedBuff[4]={0x90,0x90,0x90,0x90};
unsigned char flagls=0;
unsigned int cnt=0;
unsigned char i=0;
void main()
{
unsigned int sec=10000;
TMOD=0x01;//MOV TMOD,#01H
TH0=0xFC;
TL0=0x18;
TR0=1;
EA=1;
ET0=1;
while(1)
{
if(flagls==1)
{
flagls=0;
sec--;
LedBuff[0]=LedChar[sec%10];
LedBuff[1]=LedChar[sec%1000%100/10];
LedBuff[2]=LedChar[sec%1000/100];
LedBuff[3]=LedChar[sec/1000];
}
}
}
void InterruptTime0() interrupt 1
{
TH0=0xFC;
TL0=0x18;
cnt++;
if (cnt>=1000)
{
cnt=0;
flagls=1;
}
P0=0xFF;
switch (i)
{
case 0:DGT3=0;DGT2=0;DGT1=0;DGT0=1;i++;P0=LedBuff[0];break;
case 1:DGT3=0;DGT2=0;DGT1=1;DGT0=0;i++;P0=LedBuff[1];break;
case 2:DGT3=0;DGT2=1;DGT1=0;DGT0=0;i++;P0=LedBuff[2];break;
case 3:DGT3=1;DGT2=0;DGT1=0;DGT0=0;i=0;P0=LedBuff[3];break;
}
} |