源代码:

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

#include <avr/io.h>
#include<util/delay.h>
#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 拨码管

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-09-02
  • 2021-06-12
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-15
  • 2021-05-28
  • 2021-12-06
  • 2022-12-23
  • 2021-09-22
  • 2021-07-21
  • 2021-09-06
相关资源
相似解决方案