zwll 发表于 2022-9-1 20:05

PIC12F683电平变化中断触发不了

本帖最后由 pzsh 于 2022-11-6 21:26 编辑

PIC12F683电平变化中断触发不了

supernan 发表于 2022-9-1 20:07


楼主程序可以公开吗?贴程序看下吧,这么说看不出什么原因

zwll 发表于 2022-9-1 20:09

程序如下:
GP4作为输入无法触发电平变化中断,点亮GP0上的LED,哪位指导下
#pragma config FOSC = INTOSCIO// 4M Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF      // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown Out Detect (BOR disabled)
#pragma config IESO = ON      // Internal External Switchover bit (Internal External Switchover mode is enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)


void main(void) {
         // OSCCON = 0x78;
         //OPTION_REG=0b00000000; //全局使能上拉
         CMCON0 = 0x07;            //关比较器,并设GP0-GP5为数字IO口
         //CMCON1 = 0x07;            //关闭比较器
         ANSEL = 0x00;             //设GP0-GP5为数字IO口
         OPTION_REG = 0b00000000;    //GPIO pull-ups are enabled by individual PORT latch values in WPU register Tck=FOSC/4
         TRISIO4 = 1;                     // 0001 0000 GP4 IN, Other Outputs; Rest are O/Ps
         WPU4 = 0;
         WPU0 = 1;
         IOC4 = 1;                        //GP4 as INT if IO change
         //ADON = 0;

         GIE = 1;
         PEIE = 1;                         //开外部中断
         GPIE = 1;                         //GPIO Change Interrupt Enable bit 开电平变化中断
         //INTE = 1;
         GPtemp = GP4;
         GPIF = 0;                        //GPIO Change Interrupt Flag bit
         GP0=0;
         for(;;)                                             // ?????
         {

         }
}


void interrupt ISR(void)
{
   if(GPIF)            //电平中断
    {
      GPIE=0;
      GPtemp = GP4;
         GP0=1;
      GPIF=0;
      GPIE=1;
    }
    GIE=1;//开启总中断
}

ousj 发表于 2022-9-1 20:11

不要在ISR里面操作GIE,非常危险

supernan 发表于 2022-9-1 20:14

GP0=1是不是能点亮。能的话测下GP4, 在主循环里 if(GP4) GP0=1; else GP0=0; 没问题再测中断部分。

zwll 发表于 2022-9-1 20:20

看一下配置文件,管脚4配置的对吗

zwll 发表于 2022-9-1 20:21

主循环能闪的
      for(;;)                                             // ?????
         {
            
                   delay();
                   GP0 = 0;
                  delay();
                  GP0 = 1;   
            
         }

zwll 发表于 2022-9-1 20:23


可以了是proteus 里面的program configurationg word 没有改 要改成0x0CD4

dengdc 发表于 2022-9-1 20:26

配置字你程序里不是定义过了,哪里有冲突?

wyjie 发表于 2022-9-1 20:29

一直不可以进入中断吗

jiajs 发表于 2022-9-1 20:31

看看主循环那能进入判定语句吗

supernan 发表于 2022-9-1 20:34

重复定义也会报错的

yszong 发表于 2022-9-1 20:36

io口的配置的那部分程序贴一下看看

jiajs 发表于 2022-9-1 20:38

总中断那里开启了吗

ousj 发表于 2022-9-1 20:40

这个系列没太多复杂度吧

ousj 发表于 2022-9-1 20:42

是不是有相应的是能没开启

jiaxw 发表于 2022-9-1 20:44

可以说明一下危害吗?书本都这样教的,进中断先关GIE。改为关PEIE行不?

wyjie 发表于 2022-9-1 20:47

硬件会帮你处理的,不需要你人工干预

wyjie 发表于 2022-9-1 20:50


页: [1]
查看完整版本: PIC12F683电平变化中断触发不了