반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iom8.h>    
#include <ina90.h>    
 
#pragma vector = TIMER2_COMP_vect 
__interrupt void TIMER2_COMP_interrupt(void// 타이머 인터럽트 1ms
{     
    static unsigned int Count;
    
    if(++Count >= 1000)
    {
        Count = 0;
        
        PORTD ^= 0xAA;    
    }
}                            
    
void Port_Init(void)
{
    DDRD = 0xFF;
}
    
void Timer_Init(void)
{    
    // 16,000,000 / 64     / 250 = 1ms    
    //  8,000,000 / 32    / 250 = 1ms            
    //  1,000,000 / 8     / 125 = 1ms            
 
    TCCR2 = 0x0B// 32분주
    TCNT2 = 0x00// 0으로 세팅
    OCR2  = 250 - 1// 250 (0 ~ 249)
    
    // Timer(s)/Counter(s) Interrupt(s) initialization        
    TIMSK = 0x80// 타이머 2 세팅 (CTC모드)
}    
 
void main( void )
{
    Port_Init();
    Timer_Init();
    
    __enable_interrupt();    
    
    while(1)
    {
        
    }
}
 
 
cs


반응형

'개발모듈 > 펌웨어 모듈' 카테고리의 다른 글

- [AVR Studio] EEPROM 읽고 쓰기  (0) 2017.05.26
- sprint  (0) 2017.05.18
- Key Control 2  (0) 2016.12.01
- Key Control  (0) 2016.06.07
- 타이머 딜레이  (0) 2016.06.03
Posted by 메가아재
,