打印
[STM8]

STM8外部中断求助

[复制链接]
2197|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
sherryky|  楼主 | 2013-3-1 14:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
初涉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 */
};
沙发
uet_cache| | 2013-3-1 15:28 | 只看该作者
你可以在中断函数里执行空语句试试。看是什么原因造成。

使用特权

评论回复
评分
参与人数 1威望 +2 收起 理由
sherryky + 2 很给力!
板凳
sherryky|  楼主 | 2013-3-1 16:23 | 只看该作者
执行空语句了还是看不出什么原因,只要不使用中断就是正常的。

使用特权

评论回复
地板
kingguans| | 2013-3-5 20:13 | 只看该作者
难道是??按键没消抖?卡死了?

使用特权

评论回复
5
roper_peter| | 2013-7-30 08:16 | 只看该作者
是否是程序反复进入中断程序,引起看门狗复位的原因呢,我也遇到过同样的问题
https://bbs.21ic.com/forum.php?mo ... 87246&epclose=1

使用特权

评论回复
6
xiaolanghahaha| | 2013-8-16 11:09 | 只看该作者
应该是看门狗的原因吧,你一直按着,一直进中断,没有喂狗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

20

帖子

0

粉丝