熟女俱乐部五十路二区av,又爽又黄禁片视频1000免费,国产卡一卡二卡三无线乱码新区,中文无码一区二区不卡αv,中文在线中文a

新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 用定時器中斷設計秒表 用數(shù)碼管顯示

用定時器中斷設計秒表 用數(shù)碼管顯示

作者: 時間:2016-11-28 來源:網(wǎng)絡 收藏
//此秒表有時分秒和毫秒位,最多可以記小時,有暫停和繼續(xù)計時功能,獨立鍵盤上key1為暫停和繼續(xù)鍵,key3為復位和開始計時鍵

//由于ms中斷時間很短,所以如果中斷和顯示延遲關系處理不好,秒表走時不準,應注意

本文引用地址:http://www.bjwjmy.cn/article/201611/322834.htm

#include

#defineucharunsignedchar

#defineuintunsignedint

uchar code table[]={0x 3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

uchar code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//時分秒的個位顯示后帶小數(shù)點

uchar ms,s,m,h,count,count1;

sbit k1=P3^0;

sbit k3=P3^2;

voiddelay(uint z)

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

voiddisplays(uchar temp)//數(shù)碼管動態(tài)顯示秒位函數(shù)

{

uchar shi,ge,i;

i=0;

shi=temp/10;

ge=temp;

P0=0xef;

P1=table[shi];

delay(1);//必須要有延遲,動態(tài)掃描,為了不影響整個秒表八位數(shù)的掃描速率提高顯示效果,延遲又不要太高,ms比較合適

P0=0xdf;

P1=table1[ge];

i=0;

delay(1);

}

voiddisplayms(uchar temp)//數(shù)碼管動態(tài)顯示毫秒位函數(shù)

{

uchar shi,ge,i;

i=0;

shi=temp/10;

ge=temp;

P0=0xbf;

P1=table[shi];

delay(1);

P0=0x7f;

P1=table[ge];

i=0;

delay(1);

}

voiddisplaym(uchar temp)//數(shù)碼管動態(tài)顯示分位函數(shù)

{

uchar shi,ge,i;

i=0;

shi=temp/10;

ge=temp;

P0=0xfb;

P1=table[shi];

delay(1);

P0=0xf7;

P1=table1[ge];

i=0;

delay(1);

}

voiddisplayh(uchar temp)//數(shù)碼管動態(tài)顯示小時位函數(shù)

{

uchar shi,ge,i;

i=0;

shi=temp/10;

ge=temp;

P0=0xfe;

P1=table[shi];

delay(1);

P0=0xfd;

P1=table1[ge];

i=0;

delay(1);

}

voidkeyscan()//鍵盤掃描函數(shù)

{

if(k1==0)

{

delay(5);

if(k1==0)//檢測k1確實被按下防抖動

{

count++;

while(!k1);//檢測松手

delay(1);//檢測確實松手

while(!k1);

if(count==1)

TR0=0;//暫停定時器

if(count==2)

{

TR0=1;//定時器繼續(xù)計時

count=0;

}

}

}

if(k3==0)

{

delay(5);

if(k3==0)

{

count1++;

while(!k3);

delay(1);

while(!k3);

if(count1==1)//復位秒表

{

TR0=0;

ms=0;

s=0;

m=0;

h=0;

}

if(count1==2)//重新開始計時

{

TR0=1;

count1=0;

}

}

}

}

voidmain()

{

TMOD=0x01;

EA=1;

ET0=1;

TR0=1;

TH0=(65536-10000)/256;//設定定時器初值

TL0=(65536-10000)%6;//12M晶振時ms數(shù)為

while(1)

{

keyscan();

displays(s);//數(shù)碼管動態(tài)掃描秒位顯示

displayms(ms);//數(shù)碼管動態(tài)掃描毫秒位顯示

displaym(m);//數(shù)碼管動態(tài)掃描秒分顯示

displayh(h);//數(shù)碼管動態(tài)掃描秒小時顯示

}

}

voidtimer0() interrupt 1//中斷服務程序

{

TH0=(65536-10000)/256;

TL0=(65536-10000)%6;

ms++;

if(ms==100)//定時器中斷次為s

{//把這部分放在中斷中,能減少程序執(zhí)行時間對中斷時間的影響

ms=0;

s++;

if(s==60)

{

s=0;

m++;

}

if(m==60)

{

m=0;

h++;

}

if(h==24)

{

h=0;

}

}

}



評論


技術專區(qū)

關閉