数码管依次显示0-f

/**********************************
数码管依次显示0-f 持续
**********************************/
#include
#define uchar unsigned char
#define uint unsigned int


sbit dula=P2^6;
sbit wela=P2^7;
uchar num,num1;


uchar code table[]={//数字0-f(16进制)
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};


uchar code address[]={//数码管1-6
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};


void delayms(uint);//延迟


void main()
{
    while(1)
    {
        dula=1;
        if(num==16)
            num=0;
        P0=table[num];
        num++;
        dula=0;
        P0=0xff;
        wela=1;
        if(num1==6)
            num1=0;
        P0=address[num1];
        num1++;
        wela=0;
        delayms(500);
    }    
}


void delayms(uint xms)
{
    uint i, j;
    for(i=xms; i>0; i--)
        for(j=110; j>0; j--);
}

你可能感兴趣的:(嵌入式)