[AVR]/AT90USB2012. 1. 29. 10:40

[AT90USB1287] Timer2 테스트

[AT90USB1287] Timer2 테스트

AT90USB1287의 타이머 관련 레지스터는 ATMega128과 약간 다른데 드라이버 코드를 수정할 필요가 있다.
//---------------------------------------------------------------------------------------
#define TIMER2_VALUE      (256-115)

volatile unsigned int m_TimerTick = 0;

//---------------------------------------------------------------------------------------
// Timer2
#define TIMER_STOP                         0
#define TIMER2_CLK_DIVCLK                   1
#define TIMER2_CLK_DIV8                     2
#define TIMER2_CLK_DIV32                    3
#define TIMER2_CLK_DIV64                    4
#define TIMER2_CLK_DIV128                   5
#define TIMER2_CLK_DIV512                6
#define TIMER2_CLK_DIV1024                7

#define TIMSK        TIMSK2
#define TIMER2_INT_ENABLE     BIT0
#define Timer2Set(Value)     (TCNT2 = Value)
#define TCCR2        TCCR2B

void Timer2Init(void)
{
    Sbi(TIMSK, TIMER2_INT_ENABLE);
 Sbi(TCCR2, TIMER2_CLK_DIV128);

 //set 1ms
 Timer2Set(TIMER2_VALUE);
}
//---------------------------------------------------------------------------------------



Timer2 인터럽트 핸들러
//---------------------------------------------------------------------------------------
// Timer2 Handler
SIGNAL(TIMER2_OVF_vect)
{
 m_TimerTick++;

 //Led2Toggle();

 //set 1ms
 Timer2Set(TIMER2_VALUE);
}
//---------------------------------------------------------------------------------------



AT90USB1287 Timer 테스트 예제 소스코드
//-----------------------------------------------------------------------------
int main(void)
{
 //시스템 초기화
 SystemInit();
 
 //LED포트 초기화
 Led1Init();
 Led1Off();

 Led2Init();
 Led2Off();

 //UART Init
 DebugInit(BAUD_57600);
 DebugPrint("[AT90USB1287-EX] Test Program - Timer\r\n");

//Timer2초기화
 Timer2Init();
 enable();

 while(1)
 {
  if(m_TimerTick>100)
  {
   
   Led2Toggle();
   m_TimerTick = 0;
  }
 }
}
//-----------------------------------------------------------------------------



Posted by nexp

댓글을 달아 주세요