smg2=P2^1;
sbit smg3=P2^2;
sbit smg4=P2^3;
sbit k1=P1^0;//按鈕
sbit k2=P1^1;
sbit k3=P1^2;
sbit k4=P1^3;
sbit k5=P1^4;
sbit beep=P1^7;//蜂鳴器
uchar code smgduan0[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//顯示0~9,無小數(shù)點(diǎn)
uchar code smgduan1[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//顯示0~9,有小數(shù)點(diǎn)
uchar time=0,mode=0,flag=0;//系統(tǒng)變量
uchar miao=0,fen=0;//計時
uchar set1=20,set2=0;//倒計時設(shè)置
uchar save1[]={0,0,0,0,0,0,0,0,0,0};//存儲
uchar save2[]={0,0,0,0,0,0,0,0,0,0};
uchar num=0,cha=0;//查看
uint beep_time=0;
//延時
void delay(uint i)
{
while(i--);
}
//主函數(shù)
void main()
{
uchar k=0;
TMOD|=0X11;//初始化定時器
TH0=0X3C;
TL0=0XB0;
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
ET1=1;
TR1=1;
ET0=1;//打開定時器0中斷允許
EA=1;//打開總中斷
TR0=1;//打開定時器
while(1)
{
if(mode==0)//正計數(shù)模式
{
if(!k1 &&(k!=1))//設(shè)置
{
k=1;
if(mode!=3)
mode=3;
else
mode=0;
}
if(!k2 && (k!=2)) //計數(shù)控制
{
k=2;
if(flag<2)
flag++;
else
flag=0;
if(flag==0)
{
miao=0;
fen=0;
}
}
if(!k3 &&(k!=3))//倒計數(shù)
{
k=3;
mode=1;
miao=set1;fen=set2;
}
if(!k4 &&(k!=4))//存儲
{
k=4;
save1[num]=fen;
save2[num]=miao;
if(num<9)
num++;
else
num=0;
}
if(!k5 &&(k!=5))//查看
{
k=5;
mode=2;
cha=0;
}
}
if(mode==1)//倒計數(shù)模式
{
if(!k1 &&(k!=1))//設(shè)置
{
k=1;
if(mode!=3)
mode=3;
else
mode=0;
}
if(!k2 && (k!=2)) //正計數(shù)
{
k=2;
mode=0;flag=0;
miao=0;
fen=0;
}
if(!k3 && (k!=3)) //計數(shù)控制
{
k=3;
if(flag<2)
flag++;
else
flag=0;
if(flag==0)
{
miao=set1;fen=set2;
}
}
if(!k4 &&(k!=4))//存儲
{
k=4;
save1[num]=fen;
save2[num]=miao;
if(num<9)
num++;
else
num=0;
}
if(!k5 &&(k!=5))//查看
{
k=5;
mode=2;
cha=0;
}
}
if(mode==2)//查看
{
if(!k5 &&(k!=5))//下一個
{
資料借鑒于此紛傳
閱讀全文