[PIC®/AVR®/dsPIC®产品]

如此简单INT0为什么不产生?

[复制链接]
1584|3
手机看帖
扫描二维码
随时随地手机跟帖
qianlong30|  楼主 | 2018-1-18 16:55 | 显示全部楼层 |阅读模式
// PIC18F25K80 Configuration Bit Settings

// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = DIG    // SOSC Power Selection and mode Configuration bits (Digital (SCLKI) mode)
#pragma config XINST = OFF      // Extended Instruction Set (Disabled)

// CONFIG1H
#pragma config FOSC = HS1       // Oscillator (HS oscillator (Medium power, 4 MHz - 16 MHz))
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = OFF      // Brown Out Detect (Disabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = HIGH    // BORMV Power level (BORMV set to high power level)

// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)

// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB1K     // Boot Block Size (1K word Boot Block size)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)

// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)

// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)

// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)

// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)


#include <xc.h>
#include <stdio.h>
#include <stdlib.h>

#define _XTAL_FREQ   8000000L     //8MHz??
#define T0_H 0X00//0X66       //TMR0约80毫秒(0X66)
#define T0_L 0X36
#define LD2      PORTBbits.RB3  //??LD2?????
#define LD1      PORTBbits.RB2  //??LD1?????
#define CPU_OUT1 PORTBbits.RB1  //????????????

//高优先中断程序,向量地址0x0008)
void interrupt my_hi_int(void)
{
    if(INT0IE && INT0IF)
    {
        LD2=0;      //有外部中断时开LD2发光管
        //LD1=0;
        INT0IF=0;     
    }
    if(TMR0IE && TMR0IF)
    {        
        if(LATBbits.LATB2) LD1=0;   //定时到时取反LD1发光管
        else LD1=1;  
        TMR0IF=0;
        TMR0H=T0_H;
        TMR0L=T0_L;
    }
   
    return;   
}
//低优先级中断程序(中断向量0X0018)
void interrupt low_priority my_low_int(void)
{
    return;
}


int main() {
        
    TRISBbits.TRISB3=0; //LD2发光管 输出
    TRISBbits.TRISB2=0; //LD1发光管 输出
    TRISBbits.TRISB1=0; //CPU_OUT1 输出
     
    // 设置TMR0   
    T0CON=0B00000011;   //4分频
    TMR0MD=0;        
    TMR0H=T0_H;
    TMR0L=T0_L;   
    TMR0IF=0;   
    TMR0IE=1;
    TMR0ON=1;
   
    //设置INT0   
    TRISBbits.TRISB0=1; //CPU_Zero 过零检测RB0设置为输入
    INTCON2bits.INTEDG0=1;  //上升沿触发
    //INTCON2bits.RBPU=0;
    //RCONbits.IPEN=1;        
    INTCONbits.INT0IF=0;
    INTCONbits.INT0IE=1;
   
    GIE=1;
   
    LD2=1;  //关闭LD2及LD1
    LD1=1;
    do {
               
    } while (1);
}
------------------------------------------------------------------------------------------
TMR0中断能正常运行,INT0外部中断就是不运行,用LM258集成运放做比较器,输出接INT0,看次脚信号上升沿时间约30uS,是否是这个上升沿不够陡峭造成?还是上述软件有问题?
评论
ljfljf0401 2018-10-9 14:20 回复TA
不错的资料|! 
GeekyGeek| | 2018-1-19 12:52 | 显示全部楼层
本帖最后由 GeekyGeek 于 2018-1-19 12:55 编辑

1. 有PEIE没? PEIE 要不要置1? 已经忘了

2. RB0 PIN是否复用AN功能,如果是,需要禁止AN功能

第二种可能最大。

PIN复用很多功能的话,那些功能是有优先级的,   

假如某引脚有以下功能:
AN0/INT0/RXD/RB0...

那么这些功能中优先级 AN0 > INT0 > RXD > RB0

所以一旦某输入引脚复用了AN功能, 一定要先禁止AN功能,否则AN功能是最优先的。

使用特权

评论回复
qianlong30|  楼主 | 2018-1-19 16:43 | 显示全部楼层
谢谢,是AN复用的问题。中文数据手册,28脚的引脚图中显示此脚复用AN10,但数据手册声明28脚片子只有8个AD囗,所以我想可能引脚图标的AN10是错误的,这个口线应该没有AD复用,昨晚想管它到底有没有AD复用,先把对应AN10关掉,还真对了,外部中断出现了。

使用特权

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

本版积分规则

149

主题

349

帖子

2

粉丝