注册 登录
编程论坛 单片机编程

51单片机数码管怎么做100以内动态显示计数器(正计数)

gwrt 发布于 2022-05-15 20:19, 3965 次点击
//STC89C52RC,利用T0定时器和中断,有一个参考程序 ,但是做不到视觉上的同时显示。
#include<reg52.h>


sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
unsigned char Led[]={
                0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
                          };
  unsigned char count=0;
  unsigned char i=0;
  unsigned char j=1;
  unsigned char k=1;
  unsigned char z=1;
  unsigned char x=1;
  unsigned char c=1;
  unsigned char flag=1;
void main()
{
  EA  = 1;
  ET0 = 1;
  TMOD = 0x01;
  TH0 = 0x3C;
  TL0 = 0xB0;
  TR0 = 1;
  while(1)
  {}
}
void InterruptT0() interrupt 1
{

  TH0 = 0x3C;
  TL0 = 0xB0;
  count++;
  if(count==20){
     if(i<=10){
      LSC = 0;LSB = 0;LSA = 0;
      P0=Led[i];
      i++;
     if(i>10&&j<=10){
      i=0;
      LSC = 0;LSB = 0;LSA = 1;
      P0=Led[j];
      j++;
     if(j>10&&k<=10){
      j=1;
      LSC = 0;LSB = 1;LSA = 0;
      P0=Led[k];
      k++;
     if(k>10&&z<=10){
      k=1;
      LSC = 1;LSB = 0;LSA = 0;
      P0=Led[z];
      z++;
     if(z>10&&x<=10){
      z=1;
      LSC = 1;LSB = 0;LSA = 1;
      P0=Led[x];
      x++;
     if(x>10&&c<=10){
      x=1;
      LSC = 1;LSB = 1;LSA = 0;
      P0=Led[c];
      c++;
      }
      }
      }
      }
      }
      }
     count=0;
      }
 }
1 回复
#2
xianfajushi2022-05-16 20:37
https://blog.
1