找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2112|回复: 0
收起左侧

P1.0输出1HZ方波,送入计数器T0,计的数通过数码管的方式显示出来,最多显示到99,...

[复制链接]
ID:263579 发表于 2017-12-19 13:47 | 显示全部楼层 |阅读模式
  1. /*
  2. *平台:Keil U4+STC89C52
  3. *名称:/*
  4. *平台:Keil U4+STC89C52
  5. *名称:P1.0输出1HZ方波,送入定时器T0,计的数通过数码管的方式显示出来,
  6.        最多显示到99,超过以后重新回到0。  
  7. *日期:2017.11.19*/
  8. #include<reg52.h>
  9. #define WEI0 P1=0xfd;        //定义位选引脚
  10. #define WEI1 P1=0xfb;
  11. int m=1;
  12. unsigned int count;//用来计数
  13. //unsigned int i,j;
  14. //定义一个数组,将0~9对应的编码存入数组
  15. unsigned char n[] = {0xc0,0xf9,0xa4,0xb0,        
  16.                                 0x99,0x92,0x82,0xf8,
  17.                                 0x80,0x90};
  18. sbit LED=P1^0;
  19. void timer0();//函数声明
  20. /*定时器T0,工作方式2,200微秒发起一次中断*/
  21. void timer0()
  22. {
  23.    TMOD=0x02;
  24.    TH0=0x48;//初始化TH0和TL0
  25.    TL0=0x48; //每隔200微秒发起一次中断
  26.    ET0=1;//开启T0中断
  27.    EA=1;//开启总中断
  28.    TR0=1;//打开T0定时器
  29.    count=0;//count初始值为零
  30. }
  31. void SMG_display(int a,int b);//声明显示函数
  32. void SMG_display(int a,int b)
  33. {
  34.    switch(m)
  35.    {
  36.      case 0x01:  P0=0xff;WEI1;P0=n[a];m++;  break;
  37.          case 0x02: P0=0xff;WEI0;P0=n[ b];m=1;   break;
  38.          default: break;
  39.    }
  40. }
  41. void main()
  42. {
  43.    int a,b;
  44.    LED=1; //关闭LED
  45.    timer0();//
  46.    while(1)
  47.    {
  48.       for(b=0;b<10;b++)
  49.           {
  50.              for(a=0;a<10;)
  51.                  {
  52.                       SMG_display(a,b);
  53.                       if(count<=2500)
  54.               {
  55.                   LED=0;
  56.               }
  57.               if(count>2500&&count<=4999)
  58.               {
  59.                  LED=1;
  60.               }
  61.               if(count==5000)
  62.               {
  63.                              LED=0;
  64.                  count=0;
  65.                      a++;
  66.               }        
  67.                  }
  68.           }
  69.           P0=1; //关闭数码管
  70.    }
  71. }
  72. void timer() interrupt 1
  73. {
  74.    count++;//每次中断count+1
  75. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表