ATMEGA128
ATMEGA128, CodeVisonAVR, TIMER, timer_compare_intr_1ms
CoyoteUgly
2018. 8. 30. 16:15
ATMEGA128, CodeVisonAVR, TIMER, timer_compare_intr_1ms
0. 참고 자료
1. 모듈
2. HW 구성
3. Ports > Bit0 out
LED Port
4. Timers > Timer0

5. SW 구성
#include <mega128.h>
// Timer 0 output compare interrupt service routine interrupt [TIM0_COMP] void timer0_comp_isr(void) { // Place your code here // 16MHz / 64 = 0.004ms // 0.004ms * 250 = 1ms PORTA ^= 0x01; }
// Declare your global variables here
void main(void) { // Declare your local variables here
// Input/Output Ports initialization // Port A initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTA=0x00; DDRA=0x01;
// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 16000.000 kHz // Mode: CTC top=OCR0 // OC0 output: Disconnected ASSR=0x00; //TCCR0=0x09; TCCR0 = // 64 prescaler (0 << FOC0) | (0 << WGM00) | (0 << COM01) | (0 << COM00) | (1 << WGM01) | (1 << CS02) | (0 << CS01) | (0 << CS00); TCNT0=0x00; OCR0=0xF9; // 249
// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x02;
ETIMSK=0x00;
// Global enable interrupts #asm("sei")
while (1) { // Place your code here
} } |
6. 소스
7. 결과
1ms 마다 LED가 반응합니다.
