標(biāo)題: 單片機(jī)60秒倒計(jì)時(shí)程序+Proteus仿真,初學(xué)者編寫 [打印本頁]

作者: 牛牛ko    時(shí)間: 2019-7-1 09:18
標(biāo)題: 單片機(jī)60秒倒計(jì)時(shí)程序+Proteus仿真,初學(xué)者編寫
初學(xué)者,嘗試做一個(gè)60S的倒計(jì)時(shí)。實(shí)驗(yàn)圖如下;


這個(gè)程序是60S倒計(jì)時(shí),達(dá)到0時(shí),重新賦初值為60,繼續(xù)進(jìn)行減計(jì)時(shí),循環(huán)往復(fù)。
單片機(jī)源程序如下:
  1. //60S倒計(jì)時(shí)程序
  2. #include<reg52.h>
  3. #define uchar unsigned char  
  4. #define uint unsigned int
  5. uchar temp,bai,shi,ge,num;
  6. uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  7. void delay(uint z);
  8. void main()
  9. {  
  10.         temp=60;  
  11.         num=0;
  12.         P1=0x00;  
  13.         TMOD=0x01;  
  14.         TH0=(65536-55536)/256;   
  15.         TL0=(65536-55536)%256;
  16.         EA=1;  ET0=1;  TR0=1;  
  17.         while(1)
  18.         {
  19.                 shi = temp/10;
  20.                 ge = temp%10;
  21.                 P1 = 0xFD;
  22.                 P2 = table[shi];
  23.                 P1 = 0xFD;
  24.                 delay(5);
  25.                 P1 = 0xFE;
  26.                 P2 = table[ge];
  27.                 delay(5);               
  28.         }
  29. }
  30. //定時(shí)器0外部中斷方式
  31. void time_0() interrupt 1
  32. {
  33.         TH0=(65536-55536)/256;   
  34.         TL0=(65536-55536)%256;
  35.         num ++;
  36.         if(num == 18)
  37.         {
  38.                 temp --;
  39.                 num = 0;
  40.                 if(temp == -1)
  41.                 {
  42.                         temp = 60;
  43.                 }
  44.         }
  45. }
  46. //延時(shí)程序
  47. void delay(uint z)
  48. {
  49.         uint x,y;
  50.         for(x=z;x>0;x--)
  51.         for(y=110;y>0;y--);
  52. }
復(fù)制代碼
全部資料51hei下載地址:
60S程序+仿真.zip (87.35 KB, 下載次數(shù): 55)





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