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

標題: 51單片機定時器模組 [打印本頁]

作者: 111小北    時間: 2022-7-12 20:50
標題: 51單片機定時器模組
利用計時器的原理設計的定時器,含有中斷程序

  1. #include <REGX52.H>
  2. #include "Delay.h"
  3. #include "LCD1602.h"
  4. #include "Timer.h"
  5. #include "key.h"

  6. unsigned int sec=0,min=0,hour=0;
  7. unsigned char key1=0;
  8. void main()
  9. {
  10.         LCD_Init();
  11.         Timer0_Init();
  12.        
  13.         while(1)
  14.         {
  15.                 LCD_ShowString(1,1,"Clock:");
  16.                 LCD_ShowString(2,1,"  :  :");
  17.                 LCD_ShowNum(2,1,hour,2);
  18.                 LCD_ShowNum(2,4,min,2);
  19.                 LCD_ShowNum(2,7,sec,2);
  20.                 key1=key();
  21.                 if(key1)
  22.                 {
  23.                         if(key1==1){sec=0;min=0;hour=0;}
  24.                         if(key1==2)        sec++;
  25.                         if(key1==3)        min++;
  26.                         if(key1==4)        hour++;
  27.                 }
  28.         }

  29. }

  30. void Timer0_Rountine() interrupt 1
  31. {
  32.         static unsigned int T0count;
  33.         TL0 = 0x18;                       
  34.         TH0 = 0xFC;
  35.         T0count++;
  36.         if(T0count>=1000)
  37.         {
  38.                 T0count=0;
  39.                 sec++;
  40.                 if(sec>=60)
  41.                 {sec=0;min++;}
  42.                 if(min>=60)
  43.                 {min=0;hour++;}
  44.                 if(hour>=24)
  45.                 {hour=0;}
  46.                
  47.         }       
  48. }
復制代碼


定時器.zip

44.15 KB, 下載次數: 7, 下載積分: 黑幣 -5






歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1