本帖最后由 chandler-00 于 2012-6-26 15:39 编辑
先上程序,打算用rb0口的外部中断,中断计数两次控制rd0 ,rd1端口电压反向,可是中断一直进入不了用的是hitech 的编译器
求大神帮助!!!求hitech 中断的例程
//#include <p18F4685.h>
#include <htc.h>
#pragma config OSC=HS
#pragma config WDT=OFF
#pragma config LVP=OFF
unsigned char i;
void inter();
void interrupt HI_ISR()
{
if (INTCONbits.INT0IF == 1)
inter();
}
void main(void)
{
i = 0;
//端口输入输出设置 初始化
TRISDbits.TRISD0 = 0;
TRISDbits.TRISD1 = 0;
PORTDbits.RD0 = 0;
PORTDbits.RD1 = 1;
TRISBbits.TRISB0 = 1; // RB0设置输入 ,外部中断
//中断允许
INTCONbits.PEIE = 1; // peripheral interrupt enable
INTCONbits.GIE = 1; // global interrupt enable
INTCONbits.INT0IE = 1; //允许int0外部中断
INTCONbits.INT0IF = 0; //INT0外部中断标志为清零
//INTCONbits.RBIE = 1 ; //允许rb端口电平变化中断
//INTCON2bits.RBIP = 1; //int0始终高优先级
while (1) //等待中断发生
{
if (i = 2)
{
PORTDbits.RD0 = ~PORTDbits.RD0;
PORTDbits.RD1 = ~PORTDbits.RD1;
i = 0 ;
}
}
}
void inter()
{
i ++;
INTCONbits.INT0IF = 0 ;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
“Looks like you didn't disable other functions on RB0. Look up the datasheet for that.”
I have checked ,and this is the latest code , it did not work ! by the way , if (i = 2) is a obvious mistake ,I have changed it , Thanks !
#include <htc.h>
unsigned char i;
void interrupt HI_ISR()
{
if (INTCONbits.INT0IF == 1)
{
i ++;
INTCONbits.INT0IF = 0 ;
}
}
void main(void)
{
i = 0;
//端口输入输出设置 初始化
ADCON1|= 0x0F; //********将RB0等设置为数字I/O
TRISD0 = 0;
TRISD1 = 0;
RD0 = 0;
RD1 = 1;
TRISB0 = 1; // RB0设置输入 ,外部中断
//中断允许
IPEN = 1 ; //使能中断优先级
INT0IF = 0; //INT0外部中断标志为清零
INTEDG0 = 1; //上升沿触发
RBIF = 0 ; // RB4~RB7 电平变化标志位清零
INT1IF = 0 ; //INT1外部中断标志位清零
RBIP = 1; //int0始终高优先级
INT0IE = 1; //允许int0外部中断
PEIE = 1; // peripheral interrupt enable
GIE = 1; // global interrupt enable
while (1) //等待中断发生
{
if (i == 2) //如果频率过高,可能永远也执行不了
{
RD0 = ~RD0;
RD1 = ~RD1;
i = 0 ;
}
}
}
一周热门 更多>