- /* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices
- * Copyright (c) 2007 STMicroelectronics
- */
- //这里使用的是定时器4
- typedef void [url=home.php?mod=space&uid=1095855]@far[/url] (*interrupt_handler_t)(void);
- struct interrupt_vector {
- unsigned char interrupt_instruction;
- interrupt_handler_t interrupt_handler;
- };
- @far [url=home.php?mod=space&uid=422518]@interrupt[/url] void NonHandledInterrupt (void)
- {
- /* in order to detect unexpected events during development,
- it is recommended to set a breakpoint on the following instruction
- */
- return;
- }
- extern void _stext(); /* startup routine */
- @far @interrupt void timer4_out (void);
- 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, timer4_out}, /* irq23 */
- {0x82, NonHandledInterrupt}, /* irq24 */
- {0x82, NonHandledInterrupt}, /* irq25 */
- {0x82, NonHandledInterrupt}, /* irq26 */
- {0x82, NonHandledInterrupt}, /* irq27 */
- {0x82, NonHandledInterrupt}, /* irq28 */
- {0x82, NonHandledInterrupt}, /* irq29 */
- };
2 此处是MAIN.C文件
- void init_io(void)
- {
- PB_CR1 &= ~(1<<5);
- PB_CR2 &= ~(1<<5);
- PB_DDR |= (1<<5);
- PB_ODR = 0xff;
- }
- void init_timer4 (void)
- {
- TIM4_PSCR = 0x02;
- TIM4_ARR = 0xFA;
- TIM4_CNTR = 0xFA;
- TIM4_IER |= (1<<0);
- }
- @far @interrupt void timer4_out (void)
- {
- count++;
- }
- void init_clk (void)
- {
- CLK_CMSR = 0xe1;
- CLK_CKDIVR =((0x11<<3)|(0x01));//8|2
- CLK_PCKENR1 |= (1<<4);
- }//1M
- void main (void)
- {
- _asm("sim");
- init_io();//板上一个LED,初始化LED输出的接口
- init_clk();//初始化系统时钟
- init_timer4();//初始化定时器4
- TIM4_CR1 = (1<<0);
- _asm("rim");
- while(1)
- {
- if(count>1000)//当定时器中断服务程序的计数大于1000的时候执行括号内的程序
- {
- PB_ODR^=(1<<5);//LED接口取反
- count = 0;//计数清零
- }
- }
- }
单步运行的时候发现程序一直运行在中断服务程序@far @interrupt void timer4_out (void)中,count一直在加1,无法跳出中断服务程序。
昨天看了一晚上,实在看不出是语法错误还是规格数理解有问题,请各位帮忙看看,找找问题在哪里。