欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

玩转51单片机:让2个数显灯轮流显示00-99,每0.5秒切换一次

最编程 2024-02-05 22:00:32
...
#include<reg51.h>
sbit P12=P1^2;
sbit P13=P1^3;
unsigned char code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
void DelayMS(unsigned int x)
{
    unsigned char t;
    while(x--)
        for(t=0;t<120;t++);
}
void main()
    {    
    unsigned int i=0;
    unsigned char j;
    P0=0x00;
    while(1)
    {
    i=i+1;
      if(i>99)
    i=0;
          for(j=0;j<25;j++)
          {
          P12=1;
          P13=0;
          P0=DSY_CODE[i%10]    ;
          DelayMS(10);
          
          P12=0;
          P13=1;
          P0=DSY_CODE[i/10%10]    ;
          DelayMS(10);        
          }
    }
}