avrstudio5 拨码管

源代码:

/*
* _3.c
*
* Created: 2011-4-5 11:34:29
*  Author: xmphoenix.fish
*/

#include
#include
#define F_CPU 8000000UL

const unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char buff[3]={0,0,0};

int main(void)
{
    unsigned char i,data;
    DDRB = 0x00;PORTB = 0xFF;
    DDRF = 0xff;PORTF = 0x00;
    DDRE = 0xff;PORTE = 0x00;
    while(1)
    {
        data =    PINB;
        buff[0] = data/100;
        buff[1] = data/10%10;
        buff[2] = data%10;
        for (i=0;i<3;i++)
        {
            PORTE = ~_BV(i+1);//关键的两句表达式
            PORTF = table[buff[i]];
            _delay_ms(10);
        }
    }
}

截图:

avrstudio5 拨码管_第1张图片

你可能感兴趣的:(avrstudio5 拨码管)