本帖最后由 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 ;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
google RMW.
read the f@#$king datasheet.
谢谢大神!RMW ,that's what I need !
In general, it is caused by the divergence between the actual state of the pins and the "target" state of the pins.
That could happen if the pins are overloaded, resistively or capacitively (reactively). In your case, if you tie an led to the pin directly (you should not do that normally), its voltage drop may go below the input high threshold of that pin -> reading it back will yield a logic 0, even though you have written a logic 1 to it.
Similar things will happen if you load the pin with excessive capacitance (vs. writing -> reading cycle). For example, you may write a 1 to the pin, and then subsequently reading it back. As the capacitance on the pin is being charged up, the voltage on the pin doesn't have sufficient time to get to its logic 1 state -> you get a logic 0 on reading it back.
This situation isn't unique to PIC. The solutions are usually:
1) correct circuit design: don't overload your pins;
2) use shadow variables to keep track of the pins output status;
3) use output registers (which is essentially a shadow variable);
4) insert delays - a dumb soultion in my view.
hope it helps.
一周热门 更多>