AVR PORTG 스위치 다루기

컴퓨터 이야기/AVR 2015. 12. 9. 05:55
#include <avr/interrupt.h>
#include <avr/io.h>
void port_init(void)
{
    PORTA = 0x00;
    DDRA  = 0x00;
    PORTB = 0x00;
    DDRB  = 0x00;
    PORTC = 0x00; //m103 output only
    DDRC  = 0x00;
    PORTD = 0x00;
    DDRD  = 0x00;
    PORTE = 0x00;
    DDRE  = 0x00;
    PORTF = 0x00;
    DDRF  = 0x00;
    PORTG = 0x00;
    DDRG  = 0b00001111;
}


//call this routine to initialize all peripherals
void init_devices(void)
{
    //stop errant interrupts until set up
    cli(); //disable all interrupts
    XDIV  = 0x00; //xtal divider
    XMCRA = 0x00; //external memory
    port_init();


    MCUCR = 0x00;
    EICRA = 0x00; //extended ext ints
    EICRB = 0x00; //extended ext ints
    EIMSK = 0x00;
    TIMSK = 0x00; //timer interrupt sources
    ETIMSK = 0x00; //extended timer interrupt sources
    sei(); //re-enable interrupts
    //all peripherals are now initialized
}


void delay(int n)
{
    volatile int i,j;
    for(i=1;i<n;i++)
    {
        for(j=1;j<600;j++);
    }
}

int main(void)
{
    unsigned int temp, i;
    init_devices();    

    
    delay(600);
    
    while(1){
        if(PING & 0b00000100){
            PORTG = 0x01;
        }
        if(PING & 0b00001000){
    
            PORTG = 0x02;
        }
        delay(10);
    }
    return 0;
}


'컴퓨터 이야기 > AVR' 카테고리의 다른 글

AVR 하이퍼 터미널 기초 소스  (0) 2015.12.09
: