관리 메뉴

드럼치는 프로그래머

[마이크로프로세서 응용설계] 실습자료 - AVR_TEST 본문

★─Multi Media/☆─3학년 1학기

[마이크로프로세서 응용설계] 실습자료 - AVR_TEST

드럼치는한동이 2008. 10. 13. 19:42

#include <iom128.h>
#include <ina90.h>

#define ON 1
#define OFF 0
#define UINT8 unsigned char

// input setting
#define get_sw0() !PIND_Bit0
#define get_sw1() !PIND_Bit5
#define get_sw2() !PIND_Bit6

// output setting
#define set_led0(x) PORTE_Bit3 = !x
#define set_led1(x) PORTE_Bit4 = !x
#define set_led2(x) PORTE_Bit5 = x
#define set_led3(x) PORTE_Bit6 = x

void init_mcu()
{
    DDRD = (UINT8) ~(0x61);   // ~(01100001) = (10011110) = 0x9e 
    DDRE = (UINT8) ~(0x87);   // ~(10000111) = (01111000) = 0x78
    PORTD = 0x61;             // 01100001
    PORTE = 0x18;             // 00011000
}

void main(void)
{
    init_mcu();
   
    while (1)
    {   
        if ( get_sw0() ) set_led0(ON);
        else set_led0(OFF);
      
        if ( get_sw1() ) set_led1(ON);
        else set_led1(OFF);
       
        if ( get_sw2() ) set_led2(ON); 
        else set_led2(OFF);
       
        set_led3(ON);
    };
}

Comments