관리 메뉴

드럼치는 프로그래머

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

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

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

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

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

#define ON                 1
#define OFF                0
#define DEF_USE            1
#define DEF_NOTUSE         0
#define UINT8              unsigned char
#define UINT16             unsigned int

// 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

#define Set_pullup(x)    {SFIOR_PUD = !x; }

void    delay_us(UINT16 time_us) // us 단위로 지연
{
 UINT16 i;
 for(i = 0; i < time_us; i++ ) // 4 cycle +
 {
  asm("NOP");  // 1 cycle +
  asm("NOP");  // 1 cycle +
  asm("NOP");  // 1 cycle +
  asm("NOP");  // 1 cycle += 8 cycle for 8MHZ
 }
} // 1초에 백만번

void delay_ms(UINT16 time_ms) // ms 단위로 지연
{
 UINT16    i;
 for ( i = 0; i < time_ms; i++ ) delay_us(1000);
}

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

#define Set_fnd(UINT8)  PORTB = uint8 & 0xff

const UINT8   BCD2FND[10] =
        { 0x7d,  // 0111 1101 0
   0x0c,  // 0000 1100 1
   0xb5,  // 1011 0101 2
   0x9d,  // 1001 1101 3
   0xcc,  // 1100 1100 4
   0xd9,  // 1101 1001 5
   0xf9,  // 1111 1001 6
   0x4d,  // 0100 1101 7
   0xfd,  // 1111 1101 8
   0xdd  // 1101 1101 9
};

void main(void)
{
 init_mcu();
        DDRB = 0xff;
 PORTB = BCD2FND[0];

 /*while(i++)
 {
  if(i>9) i=0;
  Set_fnd(i);
  delay_ms(1000);
 }*/
}

Comments