本帖最后由 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 ;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
- void interrupt int0_isr(void) {
- static unsigned char i=0;
-
- INT0IF = 0; //clera the flag
- i+=1; //increment the counter
- if (i==2) {
- IO_FLP(OUT_PORT, OUT); //flip out
- i=0; //reset the counter
- }
- }
-
- void int0_init(void) {
- IO_CLR(OUT_PORT, OUT); //clear out
- IO_OUT(OUT_DDR, OUT); //out as output
-
- IO_IN(INT0_DDR, INT0); //int0 as input
-
- INTEDG0 = 1; //intrrupt on rising edge
-
- INT0IF = 0; //clera the flag
- INT0IE = 1; //enable int0 isr
- }
-
复制代码int0_init() sets up the input and output pins, and activates the isr. in the isr, we use a counter to count the number of rising edges on int0 before the output pin is flipped.they all follow roughly the same scheme to set up and to run.
一周热门 更多>