51数码管显示0-9

#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
//数码管段码共阳
uchar code DSY_CODE[]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
//延时
void DelayMS(uint x)
{
     uchar t;
     while(x--) for(t=0; t<120; t++);
}


void main()
{
     uchar a;

    P0=0X00;//初始化
     while(1)
         {
            //方法一       
                     /*
                for(a=0; a<11; a++)
                    {
                        DelayMS(200);
                        P0=~DSY_CODE[a];
                             */
                         //方法二                
                     P0=~DSY_CODE[a];
                     a=(a+1)%10;
                     DelayMS(200);


         }
}

 

posted @ 2021-08-12 08:59  游工  阅读(831)  评论(0)    收藏  举报