标题: 通过单片机定时器实现99s精确计时程序Proteus仿真图 [打印本页]

作者: awedf    时间: 2022-11-18 20:13
标题: 通过单片机定时器实现99s精确计时程序Proteus仿真图
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  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; //设定定时器为工作方式1
  10.   TH0=(65536-45872)/256; //装初值,11.0592 MHZ晶振定时50MS,计数值为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中断服务程序
  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. }
复制代码

Keil代码与Proteus仿真下载: 仿真程序.7z (59.46 KB, 下载次数: 21)





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1