![]() |
發(fā)布時(shí)間: 2022-2-3 07:12
正文摘要:xianfajushi:51單片機(jī)一個(gè)8*8點(diǎn)陣數(shù)據(jù)如何滾動(dòng)起來 一片595+一組IO [51單片機(jī)點(diǎn)陣逐行點(diǎn)亮595+IO組]2022-2-1 #include "REG52.h" sbit ds=P1^0; // 數(shù)據(jù)線 595的14腳 sbit shcp=P1^1; // 數(shù) ... |
頂一下 |
xianfajushi: 精準(zhǔn)到0.1秒的單片機(jī)秒表 sbit Qitin = P3^0; //啟停按鍵 sbit duan = P2^6; //數(shù)碼段 sbit wei = P2^7; //數(shù)碼位 unsigned char code ShuMaGuan[]={0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; unsigned char code WeiXuanBiao[]={0x00,0xfe,0xfd,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned char Js=0; //中斷計(jì)時(shí) unsigned char Hm=0; //毫秒 unsigned char Mo=0; //秒 void ShuMaXianShi(unsigned char d,unsigned char w) { unsigned char YanShi=255; P0=WeiXuanBiao[w]; wei=1; wei=0; P0=ShuMaGuan[d]; duan=1; While(YanShi--); duan=0; } void ZhongDuanSheZhi() { TH0+=0X4c; /*定時(shí)器賦初值, 定時(shí)50ms觸發(fā)中斷, 自動(dòng)補(bǔ)償方式*/ TL0+=0X00; TMOD=0X01; TR0=1; ET0=1; //開啟定時(shí)器 EA=1; //全局中斷開關(guān) } void XianShi() { ShuMaXianShi(Hm,3); ShuMaXianShi(Mo%10,2); ShuMaXianShi(Mo/10,1); } void main() { ZhongDuanSheZhi(); while(1) { XianShi() if(!QiTin) { if(Js>=2) TR0=!TR0; while(!QiTin) XianShi(); } } } void ZhongDuan() interrupt 1 { ++Js; if(!(Js%2)) if(++Hm>=10) Hm=0; if(Js>=20) { if(++Mo>=60)Mo=0; Js=0; } TH0+=0X4c; TL0+=0X00; } ========================================== void main() { ZhongDuanSheZhi(); { XianShi(); if(!QiTin) { //XianShi(/*巧借 8個(gè)數(shù)碼顯示消抖*/); YanShi=Js; if(TR0==0){TR0=!TR0;K=1;} //重啟中斷 while(Js==YanShi)XianShi(); //中斷消抖 if(!k)TR0=!TR0;else k=0; //關(guān)閉中斷, 消抖后清除標(biāo)記 while(!QiTin)XianShi(/*按下期間顯示*/); } } } ====================================== 另說明代碼工程中的中斷內(nèi)的這句YanShi=Js;要?jiǎng)h除掉,并修改 if(!k&&++Hm>=10) Hm=0;這句,包內(nèi)忘記改了。 |
Powered by 單片機(jī)教程網(wǎng)