STM8s103的定时器4定时中断问题
定时器4初始化void timer_init( void )
{
TIM4_CNTR = 0x00; //计数器
TIM4_PSCR = 0x07; //分频数128
TIM4_ARR = 0xFA; //自动重载值
TIM4_SR = 0x00;
TIM4_IER = 0x01; //更新中断使能
TIM4_CR1 = 0x01; //使能计数器
}
@far @interrupt void Time4_20ms_interrupt( void )
{
LED();
}
extern void _stext(); /* startup routine */
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, Time4_20ms_interrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
以上为定时器4及中断处理函数,中断映射函数,但是运行时却无法正常进中断
RE:STM8s103的定时器4定时中断问题
如下定义:#ifdef _COSMIC_
@far @interrupt void TIM4_UPD_OVF_IRQHandler (void) {
#else
void TIM4_UPD_OVF_IRQHandler (void) interrupt 23 {
#endif
TIM4->SR1&=~TIM4_SR1_UIF; // clear overflow flag
return;
} main.c:
#include "stm8s103f2u.h"
//int a,b,c;
void initLED(void);
void initTIM4(void);
/*void delay_10us(int us);
void delay_ms(unsigned int ms);*/
@far @interrupt void TIM4light(void);
main()
{
initLED();
initTIM4();
_asm("rim");
TIM4_CR1|=0x01;
while (1){
}
}
void initLED(void){
PC_DDR=0x70;
PC_CR1=~0x70;
PC_CR2=~0x70;
// PC_ODR=0x70;
}
void initTIM4(void){
TIM4_PSCR=0x07;
TIM4_IER=0x01;
TIM4_CNTR=255;
TIM4_ARR=255;
}
中断向量表:
/* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices
* Copyright (c) 2007 STMicroelectronics
*/
#include "stm8s103f2u.h"
int i;
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
return;
}
@far @interrupt void TIM4light (void)
{
i++;
if(i==61)
{ i=0;
if(PC_ODR==0x70)
{
PC_ODR=~0x70;
}
else
{
PC_ODR=0x70;
}
}
TIM4_SR=0x00;
return;
}
extern void _stext(); /* startup routine */
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap*/
{0x82, NonHandledInterrupt}, /* irq0*/
{0x82, NonHandledInterrupt}, /* irq1*/
{0x82, NonHandledInterrupt}, /* irq2*/
{0x82, NonHandledInterrupt}, /* irq3*/
{0x82, NonHandledInterrupt}, /* irq4*/
{0x82, NonHandledInterrupt}, /* irq5*/
{0x82, NonHandledInterrupt}, /* irq6*/
{0x82, NonHandledInterrupt}, /* irq7*/
{0x82, NonHandledInterrupt}, /* irq8*/
{0x82, NonHandledInterrupt}, /* irq9*/
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, TIM4light}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
我的也进入不了中断,求大神!
页:
[1]