AT91SAM7S.zip
오타가 있으면 말씀해 주세요 !!
압축파일만 덩그러니 횡해서 spec 페이지 정리한거 몇자 올려봅니다.
실행결과는 Timer Count 에 의해 1초에 한번 LED가 점멸합니다.
날씨가 개가있는데 개가 덥습니다... 그래도 퐈이팅하시길 !!
==================================================================================
★ Timer Count ( TC )

※ spec :: 389p
ㆍ3개의 체널에 구별되는 타이머 카운터를 가지고 있다. ( 16Bit)
ㆍ계산할수 있는 한계는 64K 이다.
ㆍATmega는 8bit ~ 16bit 사이이다.
ㆍ외부 PLL 에 의해 48M 로 증가 된다.
ㆍ즉 48M 에 1초이다.
ㆍ계산이 편하기 위해 묶어서 계산하는 것을 프리스케일러(분주비)라 한다.

ㆍ위 표의 나누기 2 ~1024 는 분주비 이다.
ㆍ즉 5가지의 분주비를 지원한다.

※ spec :: 390p
ㆍPMC, AIC, PIO가 관련되어 있다.
[ 레지스터 base address ]

※ spec :: 20p
[ 메모리 맵 ]

※ spec :: 405p
Ex) Init_timer(void) 함수 구성
[ 타이머 카운터 0을 사용을 위한 PMC활성화 ]

[ 타이머 클럭 비활성화 (TC_CCR설정) ]

※ spec :: 408p

[ 타이머 인터럽트 비활성화 (TC_IDR 설정) ]


※ spec :: 421p

[ 인터럽트 상태 정보 초기화 (TC_SR읽기) ]

※ spec :: 418p
ㆍ읽으면 사용후 지워진다.

[ 분주비 1024, 비교 방식 레지스터 설정 ]
( TC_CMR, TIMER_CLOCK5, TC_CPCTRG )



※ spec :: 409p

[ TC_RC 를 1초로 설정 ]

※ spec :: 417p
ㆍ48kHz / 1024 = 49.152 :: 1ms
ㆍ 49.152/4 = 12.288 :: 0.25ms

[ 타이머 카운터 0 인터럽트 비활성화 ( AIC_IDCR, TC0 ) ]

[ 타이머 카운터 0 인터럽트 핸들러 등록 ]
(AIC_SVR :: TC0, timer_handler)

ㆍ위와 같은 세련된 방식


[ 타이머 카운터 0 인터럽트 모드 설정 ]
(AIC_SMR :: TC0, AIC_SRCTYPE :: HIGH LEVEL, AIC_PRIOR :: LOWEST)

ㆍ위와 같은 세련된 방식


ㆍ최종 수정


[ 타이머 카운터 0 인터럽트 클리어 ]
(AIC_ICCR, TC0)

※ spec :: 204p

[ TC_RC 값 비교 타이머 인터럽트 활성화 ]
(AIC_IER, TC_CPCS)


※ spec :: 420p
ㆍwaveform 을 사용할 경우 A, B를 설정하고 사용하지 않을경우 C로 설정한다.

[ 타이머 카운터 0 인터럽트 활성화 ]
(AIC_IECR, TC0)

※ spec :: 203p

[ 타이머 클럭 활성화 ]
(TC_CCR, TC_CLKEN)

※ spec :: 203p

[ 타이머 시작 ]
(TC_CCR, TC_SWTRG)

Ex) void timer_handler(void) 함수 구성
[ 인터럽트 상태 정보 초기화 ]
( TC_SR 읽기 )

[ LED 토글 프로그래밍 ]

[ 인터럽트 상태 정보 초기화 ]
( TC_SR 읽기 )

Ex) 전 AIC포스팅의 헤더파일에 Timer/Counter 추가 |
/*======================================================================== [ Timer/Counter (TC) : SPEC :: P.405 ]==================================== ========================================================================*/ #define TC_CCR (*((volatile unsigned int *)0xFFFA0000)) #define TC_CMR (*((volatile unsigned int *)0xFFFA0004)) //<Reserved>================================================== //<Reserved>================================================== #define TC_CV (*((volatile unsigned int *)0xFFFA0010)) #define TC_RA (*((volatile unsigned int *)0xFFFA0014)) #define TC_RB (*((volatile unsigned int *)0xFFFA0018)) #define TC_RC (*((volatile unsigned int *)0xFFFA001C)) #define TC_SR (*((volatile unsigned int *)0xFFFA0020)) #define TC_IER (*((volatile unsigned int *)0xFFFA0024)) #define TC_IDR (*((volatile unsigned int *)0xFFFA0028)) #define TC_IMR (*((volatile unsigned int *)0xFFFA002C)) //<Reserved>================================================== //[ TC_CCR ]============================================================ #define CLKEN 0 #define CLKDIS 1 #define SWTRG 2 //[ TC_IDR ]============================================================= #define COVFS 0 #define LOVRS 1 #define CPAS 2 #define CPBS 3 #define CPCS 4 #define LDRAS 5 #define LDRBS 6 #define ETRGS 7 //[ TC_SR ]=============================================================== #define CLSKSTA 16 #define MTIOA 17 #define MTIOB 18 //[ TC_CMR ]============================================================== #define TCCLKS 0 #define CLKI 3 #define BURST 4 #define LDBSTOP 6 #define LDBDIS 7 #define ETRGEDG 8 #define ABETRG 10 #define CPCTRG 14 #define WAVE 15 #define LDRA 16
#define TIMER_CLOCK5 4 |
Ex) timer 헤더 파일 |
#ifndef __TIMER_H__ #define __TIMER_H__
void Init_timer(void); void timer_handler(void);
#endif // __TIME_H__ |
Ex) 위 과정대로 함수 구성 |
#include "timer.h" #include "arm.h" #include "led.h"
void Init_timer(void) { PMC_PCER = 1 << TC0; TC_CCR = 1 << CLKDIS; // 타이머 클럭 비활성화
TC_IDR = 1 << COVFS| 1<<LOVRS| 1<<CPAS| 1<<CPBS| 1<<CPCS| 1<<LDRAS| 1<< LDRBS | 1<<ETRGS; TC_SR; TC_CMR = (TIMER_CLOCK5 << TCCLKS) | (1 << CPCTRG);
TC_RC = 49152;
AIC_IDCR = 1 << TC0;
AIC_SVR[TC0] = (unsigned int)timer_handler; AIC_SMR[TC0] = (AIC_SRCTYPE_INT_HIGH_LEVEL << SRCTYPE) | (AIC_PRIOR_LOWEST <<PRIOR); AIC_ICCR = 1 << TC0;
TC_IER = 1 << CPCS; AIC_IECR = 1 << TC0; TC_CCR = 1 << CLKEN; TC_CCR = 1 << SWTRG; return ; }
void timer_handler(void) { TC_SR; LED_toggle(); TC_SR; return ; } |
Ex) main 함수 |
#include "arm.h" #include "led.h" #include "aic.h" #define delay(x) for(dly = 0;100000 > dly; dly++) //[ 함수 선언부 ]==================== void Init(void); // 함수 호출 함수
int main() {
Init();
while(1); return 0; }
void Init(void) { Init_LED(); Init_AIC(); Init_timer(); return ; } |
< 실행 결과 동영상 참고 >