硬件連接:
代碼:
#include #define uchar unsigned char #define uint unsigned int sbit K1 = P3^7; uchar i,Second_Counts,Key_Flag_Idx; bit Key_State; uchar DSY_CODE[]= { 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f }; void DelayMS(uint ms) { uchar t; while(ms--) { for(t=0;t<120;t++); } } void Key_Event_Handle() { if(Key_State == 0) { Key_Flag_Idx=(Key_Flag_Idx+1)%3; switch(Key_Flag_Idx) { case 1:EA=1;ET0=1;TR0=1;break; case 2:EA=0;ET0=0;TR0=0;break; case 0:P0=0x3f;P2=0x3f;i=0;Second_Counts=0; } } } void main() { P0 = 0x3f; P2 = 0x3f; i = 0; Second_Counts = 0; Key_State = 1; TMOD = 0x01; TH0 = (65535-50000)/256; TL0 = (65535-50000)%256; while(1) { if(Key_State != K1) { DelayMS(10); Key_State = K1; Key_Event_Handle(); } } } void DSY_Refresh() interrupt 1 { TH0 = (65535-50000)/256; TL0 = (65535-50000)%256; if(++i==2) { i = 0; ++Second_Counts; P0 = DSY_CODE[Second_Counts/10]; P2 = DSY_CODE[Second_Counts%10]; if(Second_Counts == 100) Second_Counts = 0; } }
上一篇:按鍵狀態led顯示
下一篇:單片機蜂鳴器生日快樂歌
推薦閱讀
史海拾趣
設計資源 培訓 開發板 精華推薦
- 有獎直播:意法半導體SiC產品及其工業應用指南
- 易電源電源模塊試用!
- TI 嵌入式處理器最新產品發布會 全程在線直播 4月16日精彩為您呈現!預報名、看直播、享好禮
- 免費下載 | 注冊施耐德電氣,下載《施耐德電氣參考指南》白皮書
- Maxim 利用nanoPower創新技術,致力于降低系統的靜態功耗 看視頻答題贏好禮! 還有免費開發板等你拿
- 力源&安森美有獎直播:RSL15 - 安森美更高效更智能更安全的 BLE 5.2 藍牙芯片
- 下載有禮:4種方法幫助您高效進行元器件表征,加速元器件檢測
- ADI有獎下載活動之19:ADI可編程邏輯控制器(PLC)解決方案(更新版)
- 下載【ADI 6本精選電子書】,截圖抽紅包啦~
- 有獎直播|ST資料中心與通訊網路電源管理解決方案