中断问题pic18f4550
我在使用MPLAB 8.89和c18编译器的pic18f4550上遇到中断问题 关键是,如果pin更改为status,则中断不会进入。我可以看到状态的改变,但它只是没有改变。但是,如果将中断写为一个中断,它将进入例程 这是我的密码,知道吗中断问题pic18f4550,c,embedded,microcontroller,pic,C,Embedded,Microcontroller,Pic,我在使用MPLAB 8.89和c18编译器的pic18f4550上遇到中断问题 关键是,如果pin更改为status,则中断不会进入。我可以看到状态的改变,但它只是没有改变。但是,如果将中断写为一个中断,它将进入例程 这是我的密码,知道吗 ////// Autonomated Velocity Transmssion for a Bicycle of 9 gears///// #include <p18f4550.h> //////////////////////////////
////// Autonomated Velocity Transmssion for a Bicycle of 9 gears/////
#include <p18f4550.h>
//////////////////////////////////////////// Variables /////////////////////////////////////////////////
unsigned int sensors=0; // Counter of the sensor in the star
unsigned int sensorw=0; // Counter of the sensor in the wheel
unsigned int rpms=0; // Rpms of the star
unsigned int rpmw=0; // Rpms of the wheel
unsigned int velw;
//////////////////////////////////////////// Interruption functions //////////////////////////////////////////////////
void Llanta (void); //Wheel
void Estrella (void); //Star
/////////////////////////////////////// High Priority Interruptions /////////////////////////////////////////////////
#pragma code high_vector=0x08
void high_interrupt (void)
{
_asm nop _endasm
}
//////////////////////////////////////////// Low Priority Interruptions //////////////////////////////////////////////////
#pragma code low_vector=0x18
void low_interrupt (void)
{
if(INTCON3bits.INT1IF==1){ //interruption for INT1 on rising edge
_asm goto Llanta _endasm //Wheel
}
if(INTCONbits.RBIF==1) { //Interruption for change on RB port change
_asm goto Estrella _endasm //Star
}
}
#pragma code
#pragma interruptlow Llanta
void Llanta (void) //Counts when the hall sensor of the wheel is activated
{
INTCON3bits.INT1IF=0; //Turn off flag
sensorw++; //add
}
#pragma interruptlow Estrella //Counts when the hall sensor of the star is activated
void Estrella (void)
{
INTCONbits.RBIF=0; //Turn off flag
if(PORTBbits.RB4 == 1){
sensors++; //Add
}
}
////////////////////////////////////////////// Main program /////////////////////////////////////////////////////////////////////
void main (void)
{
unsigned int temp16;
OSCCON=0b01100000; //Oscillator 4 MHz
//Pins Configuration
TRISBbits.RB1=1; //input sensor wheel
TRISBbits.RB4=1; //input sensor star
TRISB=0xFF; //All as inputs
T1CON=0b01000001; // Oscillator 4 MHz, timer 1
///////////////////////// Priorities ////////////////////////////////
RCONbits.IPEN=1; //Enable priority levels
INTCON=0b11001000; //Enable high, low interrupts and RB port change interrupt
INTCON2=0b01110000; //Pull up disabled, interrupt on rising edge, and low priority on rb change
INTCON3=0b00011000; //low priority interruption, and enables external interruptions.
ADCON1=0x0F; //digital input
do{
INTCON3bits.INT1IF=1; // This was made to make a test. i put this as one, the interruption works and it goes where it should go.
}
while(1);
}
///9档自行车的自动变速/////
#包括
////////////////////////////////////////////变数/////////////////////////////////////////////////
无符号整数传感器=0;//星型传感器的计数器
无符号整数传感器w=0;//车轮中传感器的计数器
无符号整数RPM=0;//星星的RPM
无符号整数rpmw=0;//车轮转速
无符号整数电平;
////////////////////////////////////////////中断函数//////////////////////////////////////////////////
无效(无效)//车轮
void-Estrella(void)//明星
///////////////////////////////////////高优先级中断/////////////////////////////////////////////////
#杂注代码高_向量=0x08
无效高_中断(无效)
{
_asm nop_endasm
}
////////////////////////////////////////////低优先级中断//////////////////////////////////////////////////
#杂注代码低_向量=0x18
无效低_中断(无效)
{
如果(INTCON3bits.INT1IF==1){//上升沿上INT1的中断
_asm goto Llanta _endasm//车轮
}
如果(INTCONbits.RBIF==1){//中断RB端口更改
_asm goto Estrella _endasm//Star
}
}
#布拉格码
#布拉格中断语
void lanta(void)//当车轮霍尔传感器激活时计数
{
INTCON3bits.INT1IF=0;//关闭标志
sensorw++;//添加
}
#pragma interruptlow Estrella//当星的霍尔传感器被激活时计数
虚空埃斯特雷拉(虚空)
{
INTCONbits.RBIF=0;//关闭标志
如果(PORTBbits.RB4==1){
传感器+++;//添加
}
}
//////////////////////////////////////////////主程序/////////////////////////////////////////////////////////////////////
真空总管(真空)
{
无符号整数temp16;
OSCCON=0b01100000;//振荡器4 MHz
//引脚配置
TRISBbits.RB1=1;//输入传感器轮
TRISBbits.RB4=1;//输入传感器星形
TRISB=0xFF;//全部作为输入
T1CON=0b01000001;//振荡器4 MHz,定时器1
/////////////////////////优先次序//////////////
RCONbits.IPEN=1;//启用优先级
INTCON=0b11001000;//启用高、低中断和RB端口更改中断
INTCON2=0b01110000;//上拉禁用,上升沿中断,rb更改优先级低
INTCON3=0b00011000;//低优先级中断,并启用外部中断。
ADCON1=0x0F;//数字输入
做{
INTCON3bits.INT1IF=1;//这是为了做一个测试。我把它作为一个,中断工作,它去它应该去的地方。
}
而(1),;
}
检查以下一些想法
CONFIG3H:
配置寄存器3和PBADEN位
PBADEN: PORTB A/D Enable bit
1 = PORTB<4:0> pins are configured as analog input channels on Reset
0 = PORTB<4:0> pins are configured as digital I/O on Reset
If set to analog it won't register your pin status changes.
您正在轮询/读取中断中的端口请正确缩进代码。这是不可读的,所以我懒得读。如果使用tab键缩进,则应将代码编辑器设置为在按tab键时插入空格。对于缩进,我很抱歉,我只是更改代码以简化中断。
INTCON3=0b00011000代码>设置了INT1IE
和INT2IE
,这意味着启用了INT2
外部中断。但相应的标志是中断功能未处理。可能INTCON3=0b00001000代码>解决问题?
RBIF: RB Port Change Interrupt Flag bit(1)
1 = At least one of the RB7:RB4 pins changed state (must be cleared in software)
0 = None of the RB7:RB4 pins have changed state
Note 1: A mismatch condition will continue to set this bit.
Reading PORTB, and then waiting one additional instruction cycle,
will end the mismatch condition and allow the bit to be cleared.