×
单片机 > 单片机程序设计 > 详情

avrstudio5 拨码管

发布时间:2021-01-20 发布时间:
|

源代码:

/* 
* _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  拨码管 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
ARM 汇编的必知必会