標(biāo)題: 通過單片機(jī)定時器實(shí)現(xiàn)99s精確計(jì)時程序Proteus仿真圖 [打印本頁]

作者: awedf    時間: 2022-11-18 20:13
標(biāo)題: 通過單片機(jī)定時器實(shí)現(xiàn)99s精確計(jì)時程序Proteus仿真圖
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uint i;
  5. char ctime=0;
  6. uchar code led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
  7. void main()
  8. {
  9.   TMOD=0X01; //設(shè)定定時器為工作方式1
  10.   TH0=(65536-45872)/256; //裝初值,11.0592 MHZ晶振定時50MS,計(jì)數(shù)值為45872
  11.   TL0=(65536-45872)%256;
  12.   EA=1;   //打開總中斷
  13.   ET0=1;  //打開定時器中斷
  14.   TR0=1;  //啟動定時器0
  15.   while(1)
  16.   {
  17.    P0=led[ctime/10];
  18.    P2=led[ctime%10];
  19.   
  20.   }

  21. }


  22.    void time() interrupt 1  //定時器0中斷服務(wù)程序
  23. {
  24.   TH0=(65536-45872)/256;   //重裝初值
  25.   TL0=(65536-45872)%256;   
  26.   i++;
  27.   if(i==20)                //如果i=20,說明1s時間到
  28.   {
  29.    i=0;
  30.   
  31.    ctime++;
  32.    if(ctime>99)
  33.    {
  34.     ctime=0;
  35.   }
  36. }  
  37. }
復(fù)制代碼

Keil代碼與Proteus仿真下載: 仿真程序.7z (59.46 KB, 下載次數(shù): 21)





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