初涉STM8单片机,遇到问题:设置PB5下降沿中断,外接按键,按键按一次PC7上指示灯取反。
症状如下:
不按外部按键,系统一直处于等待状态,按外部按键进入中断,执行完中断函数后程序复位,是什么原因呢?请各位赐教
程序如下
main()
{
unsigned char n;
_asm("SIM");//disable interrupt
CLK_init();//设置HSI 16M
PB_DDR = 0x00;
PB_CR1 = 0x30;
PB_CR2 = 0x20;//PB5为中断上拉输入
EXTI_CR1 = 0x08;//pb口设置为仅下降沿触发
EXTI_CR2 = 0x00;//其他端口中断
_asm("RIM");//enable interrupt
while (1){
;
}
}
中断函数
void PORTB_interrupt(void)
{
PC_ODR ^= 0X80;//外接LED指示灯
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, (interrupt_handler_t)PORTB_interrupt}, /* 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, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
}; |
|