avrstudio5 拨码管

it2022-05-08  9

源代码:

/* * _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;         buff[2] = data;         for (i=0;i<3;i++)         {             PORTE = ~_BV(i+1);//关键的两句表达式             PORTF = table[buff[i]];             _delay_ms(10);         }     } }

截图:

转载于:https://www.cnblogs.com/xmphoenix/archive/2011/04/05/2006096.html

相关资源:avr studio 4

最新回复(0)