日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

51单片机实现电子时钟代码

發布時間:2023/12/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 51单片机实现电子时钟代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<reg52.h> sbit key1=P3^1; sbit key2=P3^0; sbit key3=P3^2; sbit key4=P3^3; sbit a=P2^2; //位選聲明 sbit b=P2^3; sbit c=P2^4; void delay(int); void zhongduan(); void display(int,int,int,int,int,int); void keyscan(); //獨立按鍵 char num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; char num2[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//帶點數據 int shu1,shu2,shu3,shu4;// int ge,shi,fen1,fen2,hour1,hour2; int main(){ TMOD=0x01; TH0=(65536-45872)/256; TL0=(65536-45872)%256; //TH1=(65536-45872)/256; //TL1=(65536-45872)%256; EA=1; ET0=1; //ET1=1; TR0=1; //TR1=1; while(1) { //顯示 display(ge,shi,fen1,fen2,hour1,hour2); keyscan(); } return 0; } void delay(int x){//timer int i,j; for(i=x;x>0;x--) for(j=110;j>0;j--); } void zhongduan()interrupt 1 { TH0=(65536-45872)/256; TL0=(65536-45872)%256; shu2++; if(shu2==20){ //1s shu2=0; shu1++; if(shu1==60){ shu3++; shu1=0; } shi=shu1/10; ge=shu1%10; if(shu3==60){ shu4++; shu3=0; } fen1=shu3%10; fen2=shu3/10; if(shu4==24){ shu4=0; } hour1=shu4%10; hour2=shu4/10; }//第一個if }//函數void display(int ge,int shi,int fen1,int fen2,int hour1,int hour2){ P0=num[ge]; //段選 秒個位 a=0; //位選 b=0; c=0; delay(1);P0=num[shi]; //段選 秒十位 a=1; //位選 b=0; c=0; delay(1);P0=num2[fen1]; //段選 分個位 a=0; //位選 b=1;c=0; delay(1);P0=num[fen2]; //段選 分十位 a=1; //位選 b=1; c=0; delay(1);P0=num2[hour1]; //段選 時個位 a=0; //位選 b=0; c=1; delay(1);P0=num[hour2]; //段選 時十位 a=1; //位選 b=0; c=1; delay(1); }//fd=16*16^1+13*16^0=256+13=269=>11111101 void keyscan(){ if(key1==0){ delay(5); if(key1==0){ shu4++; if(shu4==24) shu4=0; while(!key1);//等待按鍵釋放} } if(key2==0) { delay(5); if(key2==0) { shu3++; if(shu4>=24) shu3=0; while(!key2);// } } if(key3==0) { delay(5); if(key3==0) { shu1+=10; if(shu1>=60) shu1=0; while(!key3); } }if(key4==0) { delay(5); if(key4==0) { while(!key4) TR0=~TR0; } }//return 0; }

總結

以上是生活随笔為你收集整理的51单片机实现电子时钟代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。