タイマ割り込み CAT709用
#include <mes2.h>
#include <h8/reg770x.h>
extern void init_tmu0(void);
extern void start_tmu0(void);
extern void stop_tmu0(void);
extern void tmu0_int(void);
int tmu0_flag;
int main(void){
stop_tmu0();
set_handler(0x400,tmu0_int);
init_tmu0();
start_tmu0();
for(;;){
printf("%d\r",tmu0_flag); 意味は無い。動作していることが確認できるだけ
};
}
|
#include<h8/reg770x.h>
void init_tmu0(void);
void start_tmu0(void);
void stop_tmu0(void);
void init_tmu0(void){
IPRA |=0x8000;//TMU0 IntLevel =8
TOCR =0;//Set TCLK Pin as Input(not use)
TCR_0 =0x0023;//UNF(Interrupt Enable),P/256 - (14765600*2)/256 =8.668microSec
// TCOR_0 =114;//1mSec
TCOR_0 =115366;//1Sec
TCNT_0 =115366;
}
void start_tmu0(void){
TSTR |=1;//Start TCNT0
}
void stop_tmu0(void){
TSTR &=0xfe;//Stop TCNT0
TCR_0 =0x0003;//UNIE(Interrupt DisEnable)
IPRA &=0x0fff;//TMU0 IntLevel =0
}
|
以下は、コンパイル時に最適化を止めること。
#include <mes2.h>
#include <h8/reg770x.h>
#pragma interrupt
void tmu0_int(void);
void tmu0_int(void){
TCR_0 =0x0023;// Int Coming Again UNF =0
PJDR ^= 0xc0; JポートにLEDがあって、点滅する。
}
|