欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1666|回復: 0
收起左側

c51單片機+DIY電路每5分鐘顯示一次時鐘 源程序

[復制鏈接]
ID:795193 發表于 2020-7-12 10:59 | 顯示全部樓層 |閱讀模式
以下時部分程序,謝謝。
制作出來的實物圖如下:
51hei圖片20200712105359.jpg

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
5.jpg

單片機源程序如下:
  1. #include "reg52.h"                                //單片機頭文件
  2. #define uchar unsigned char        //定義uchar 代替 unsigned char
  3. #define uint unsigned int
  4. sbit shi=P0;
  5. sbit fen=P2;        //位定義
  6. sbit fenn=P1;
  7. sbit k1=P3^4;
  8. sbit k2=P3^5;
  9. sbit k3=P3^6;
  10. sbit k4=P3^7;
  11. void display(uchar a0,uchar a1,uchar a2,uchar a3,uchar a4,uchar a5);                  //函數聲明
  12. //void delay(uchar mss);
  13. //修改了數組的值
  14. uchar code tab1[]={0x20,0x30,0x38,0x3c,0x3e,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
  15. uchar code tab2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f};
  16. //uchar code tab3[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
  17. //uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f};
  18. uchar code tab3[]={0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00};//數組顯示
  19. uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20};

  20. //uchar code tab1[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
  21. //uchar code tab2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f};
  22.     //uchar code tab3[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};          去除的
  23.     //uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f};          去除的
  24. //uchar code tab3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00};//數組顯示
  25. //uchar code tab4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01};
  26. uchar ms=0,mg=0,fs=0,fg=0,ss=0,sg=0,m=0,f=0,s=0,ff=0,hf=0,fff=0;//定義變量



  27. char led[4]={0};  //顯示數組,修改   

  28. void delay(int i)    //延時函數
  29. {
  30.         while(i--);
  31. }                                          

  32. void led4(void)    //顯示函數
  33. {
  34.         char i;
  35.         for(i=0;i<4;i++)      //4位
  36.         {
  37.                 P0=~led[i];       //送段碼 P2,P0對換了
  38.                 P2=~(0x01<<i);    //送位碼
  39.                 delay(100);       //延時
  40.                 P0=0xff;          //關閉顯示
  41.                 P2=0xff;          //關閉顯示
  42.         }
  43. }

  44. char k,kk; //循環次數
  45. long n;  //移位
  46. int h;        //另外一個定時變量
  47. main()
  48. {
  49.         TMOD=0x01;
  50.         TH0=(65536-45872)/256;
  51.         TL0=(65536-45872)%256;
  52.         EA=1;
  53.         ET0=1;
  54.         TR0=1;
  55.         while(1)

  56.         {
  57.                 led4();                                                                                                                                             //調用顯示函數
  58.                    if(k1==0)                                                                 //按鍵k1為低電頻
  59.           {         
  60.              delay(40);                                                                //延時去抖
  61.              if(k1==0)                                                                 //判斷k1是否按下
  62.                   {                                                                    
  63.                    while(k1!=1);                                                                                                           //等待按鍵釋放
  64.                    ff++;                                                                                                                           //ff,5分鐘自加
  65.                                    fff++;                                                              //fff也自加                                                                            //秒置0
  66.                    if(ff==12)                                                         //ff夠12,自動置0,小時自加1
  67.                    {
  68.                       ff=0;
  69.                                           m=0;
  70.                                           h++;
  71.                                           hf++;
  72.                                           if(h==11)
  73.                                           {h=0;}
  74.                    }
  75.                         }
  76.                         }

  77.               if(k2==0)                         //按鍵k2控制加1小時
  78.            {
  79.              delay(40);
  80.              if(k2==0)
  81.                   {
  82.                    while(k2!=1);
  83.                     h++;
  84.                                         hf++;
  85.                                         m=0;
  86.                    if(h==11)
  87.                    {
  88.                     h=0;
  89.                    }
  90.                   }

  91.           }
  92.                 if(fff==1)                //把fff清0返回5分鐘后的效果
  93.                 {
  94.                         fff=0;         
  95.                         led[0]=tab1[k];     
  96.                         led[3]=tab2[k];
  97.                         k++;
  98.                         if(k>11) k=0;           
  99.                         }

復制代碼


/////////////////////////////


全部資料51hei下載地址:
5分鐘時鐘項目.rar (58.44 KB, 下載次數: 9)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表