标题: 10+0-99计数器单片机源程序+仿真 [打印本页]

作者: 欢欢days    时间: 2017-12-9 20:21
标题: 10+0-99计数器单片机源程序+仿真
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. #include <AT89X51.H>
  2. unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,
  3.                             0x6d,0x7d,0x07,0x7f,0x6f}; //0-9显示代码
  4. unsigned char Count;
  5. void delay10ms(void)   //延时10ms函数
  6. {
  7.   unsigned char i,j;
  8.   for(i=20;i>0;i--)
  9.   for(j=248;j>0;j--);
  10. }
  11. void main(void)
  12. {
  13.   Count=0;
  14.   P0=table[Count/10]; //定义P0口为十位显示位
  15.   P2=table[Count%10]; //定义P2口为个位显示位
  16.   while(1)
  17.     {
  18.       if(P3_7==0) //查询P3.7为0则延时
  19.         {
  20.           delay10ms(); //调用延时函数
  21.           if(P3_7==0) //延时后再查询P3.7脚,以去抖动.如确实为0,则计数加1
  22.             {
  23.               Count++;
  24.               if(Count==100) //查询计数是否到100,如果到则清零
  25.                 {
  26.                   Count=0;
  27.                 }
  28.               P0=table[Count/10];
  29.               P2=table[Count%10];
  30.               while(P3_7==0);
  31.             }
  32.         }
  33.     }
  34. }


复制代码

所有资料51hei提供下载:
10 0-99计数器.rar (22.47 KB, 下载次数: 15)







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