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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2227|回復: 2
打印 上一主題 下一主題
收起左側

基于51單片機的倒計時程序設計

[復制鏈接]
跳轉到指定樓層
樓主
基于51單片機  led 12864的顯示器  顯示當前時間 和 距離高考小白第一個項目  望大神指點  多多指教
  1. #include <reg51.h>
  2. #include "lcd12864.h"
  3. #include "string.h"
  4. #include "stdio.h"
  5. #include "uart.h"
  6. #include "main.h"
  7. #include "ds1302.h"
  8. unsigned int i = 0;
  9. //當前時間
  10. extern uint         now_year,now_month,now_date,now_hour,now_min,now_sec;
  11. //倒計時時間
  12. extern int        days;
  13. extern int        hours;
  14. extern int        mins;
  15. extern int        secs;
  16. uchar temp[10] = {0};
  17. //獲取個位數并轉換為字符類型
  18. uchar get_ge(uint c){
  19.         uchar ge = c%10;
  20.         ge = ge+48;
  21.         return ge;
  22. }
  23. //獲取百位數并轉換為字符類型
  24. uchar get_shi(uint c){
  25.         uchar ge = c%100/10;
  26.         ge = ge+48;
  27.         return ge;
  28. }
  29. //獲取十位數并轉換為字符類型
  30. uchar get_bai(uint c){
  31.         uchar ge = c%1000/100;
  32.         ge = ge+48;
  33.         return ge;
  34. }


  35. void to_str(uint c,uchar* content,uint length){
  36.         
  37.         if(length == 1){
  38.                 *content = ' ';
  39.                 *(content+1) = get_ge(c);
  40.                 *(content+2) = '\0';
  41.         }
  42.         else if(length == 2){
  43.                 *(content) = get_shi(c);
  44.                 *(content+1) = get_ge(c);
  45.                 *(content+2) = '\0';
  46.         }
  47.         else if(length == 3){
  48.                 *content = ' ';
  49.                 *(content+1) = get_bai(c);
  50.                 *(content+2) = get_shi(c);
  51.                 *(content+3) = get_ge(c);
  52.                 *(content+4) = '\0';
  53.         }
  54. }
  55. void add_str(char* p){
  56.         while(*p !='\0')
  57.         {
  58.                 LCD12864_WriteData(*p);
  59.                 p++;        
  60.         }
  61. }
  62. //刷新顯示界面
  63. void refresh(){
  64.         //LCD12864_ClearScreen();//清屏有BUG
  65.         LCD12864_SetWindow(0, 0);
  66.         add_str("當前時間");
  67.         to_str(now_hour,temp,2);
  68.         add_str(temp);
  69.         add_str("時");
  70.         to_str(now_min,temp,2);
  71.         add_str(temp);
  72.         add_str("分");
  73.         LCD12864_SetWindow(1,0);
  74.         add_str("  距離高考還有  ");
  75.         LCD12864_SetWindow(2,0);
  76.         if(days < 10){
  77.                 to_str(days,temp,1);
  78.         }else if(days >= 10 && days < 100){
  79.                 to_str(days,temp,2);
  80.         }else{
  81.                 to_str(days,temp,3);
  82.         }
  83.         to_str(days,temp,3);
  84.         add_str(temp);
  85.         add_str("天");
  86.         LCD12864_SetWindow(2,3);
  87.         to_str(hours,temp,2);
  88.         add_str(temp);
  89.         add_str("時");
  90.         to_str(mins,temp,2);
  91.         add_str(temp);
  92.         add_str("分");
  93.         to_str(secs,temp,2);
  94.         add_str(temp);
  95.         LCD12864_SetWindow(3,0);
  96.          add_str("你還年輕你怕什么");
  97. //        if (days==127&& now_hour ==8&& now_min <=5){
  98. //                        TR0=0;
  99. //                LCD12864_SetWindow(0, 0);
  100. //                 add_str("擼起袖子加油干  ");
  101. //                LCD12864_SetWindow(1, 0);
  102. //                 add_str("                ");
  103. //                LCD12864_SetWindow(2, 0);
  104. //                add_str("                ");
  105. //                LCD12864_SetWindow(3, 0);
  106. //                 add_str("          謝顯山");
  107. //        }
  108. ////        if ( days ==138&&now_hour ==15 && now_min <=5){
  109. //                        TR0=0;
  110. //                LCD12864_SetWindow(0, 0);
  111. //                 add_str("人生最大的痛苦是");
  112. //                LCD12864_SetWindow(1, 0);
  113. //                 add_str("夢醒了無路可走  ");
  114. //                LCD12864_SetWindow(2, 0);
  115. //                add_str("  不怕萬人阻擋  ");
  116. //                LCD12864_SetWindow(3, 0);
  117. //                 add_str("  只怕自己投降  ");
  118. //        }
  119. //        
復制代碼

時間  和勵志標語  可在基礎上進行更改

TIM截圖20190703104122.png (102.52 KB, 下載次數: 16)

TIM截圖20190703104122.png

倒計時.7z

49.74 KB, 下載次數: 14, 下載積分: 黑幣 -5

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:586359 發表于 2019-7-31 10:00 | 只看該作者
這里有用到定時器嗎?為什么會有TR0呢?
回復

使用道具 舉報

板凳
ID:393625 發表于 2019-8-14 10:17 | 只看該作者
請問有電路圖參考一下呢嗎?
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

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