单片机 STM8S903SK
程序如下:
定时器6初始化程序:
void timer6_50us(void)//配置1ms中断的寄存器状态
{
TIM6_EGR=0X01;
TIM6_ARR=0X64;
TIM6_PSCR=0X00;
TIM6_CR1=0X84;
TIM6_SR=0X00;
TIM6_IER=0X01;
TIM6_CR1|=0X01;
}
中断服务程序:
#include"stm8s903k3.h"
typedef void @far (*interrupt_handler_t)(void);
extern void _stext(); /* startup routine */
extern flag_tt;
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
/* in order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction
*/
return;
}
@far @interrupt void TIM6_UPD_OVF_TRG_IRQHandler()
{
//TIM6_SR=0X00;
//flag1_tt=0x05;
flag_tt=1;
TIM6_SR=0X00;
return;
}
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, TIM6_UPD_OVF_TRG_IRQHandler}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
主程序:
main()
{
_asm("sim");
clock_inti();
io_inti();
_asm("rim");
timer6_50us();
while(1)
{
if(flag_tt==1)
{PC_ODR|=0x80;}
else
{PC_ODR&=0x00;}
}
}
程序可以完全跑起来,可是中断程序的时间标志位 flag_tt,按道理在走完中断程序后应该置为位了。可是实际跑完后,该标志还是0,哪个大哥有碰到相同的问题,请指教一下吧!!!!!!!!!!!!!! |
|