10秒的秒表程序,帶暫停
unsigned char code seg7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}//數(shù)碼管碼表
unsigned char code tab[]={0xfe,0xfd}; //數(shù)碼管位選
unsigned char cnt=0;//位選變量
unsigned char deta=0,sec=0; //0.01秒變量,和秒變量
sbit stop=P3^3; //暫停鍵
void init() //定時初始化
{
TMOD=0x11;
TH1=0xd8;
TL1=0xf0;
TR1=1;
TH0=0xfc;
TL0=0x18;
TR0=1;
ET1=1;
ET0=1;
EA=1;
}
void time10ms()interrupt 3
{
TH1=0xd8;
TL1=0xf0;
deta++;
}
void show()interrupt 1 //掃描顯示2位adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=f63b6e57c5e8b407&k=%CA%FD%C2%EB%B9%DC&k0=%CA%FD%C2%EB%B9%DC&kdi0=0&luki=2&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=7b4e8c5576e3bf6&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2184%2Ehtml&urlid=0" id="0_nwl" mpid="0" target="_blank">數(shù)碼管
{
TH0=0xfc;
TL0=0x18;
++cnt;
if(cnt>1)cnt=0;
switch (cnt)
{
case 0: P0=seg7[sec%10];P2=tab[0];break;
case 1: P0=seg7[sec/10];P2=tab[1];break;
default:break;
}
}
void showtime() //時間顯示
{
if((deta>10)&&stop){sec++;deta=0;} //如果P3^3不按下,則為高電平,不暫停時間。
if(sec==99)sec=0;
}
void main()
{
init();
while(1)
{
showtime();
}
}
評論