3424 views|14 replies

68

Posts

0

Resources
The OP
 

Why can't my INT function enter the interrupt? [Copy link]

 

Why can't my RB0 port enter an interrupt? What's the problem?

#include<pic.h>
#include<pic16f877a.h>
#define uchar unsigned char
#define uint unsigned int
__CONFIG(0x3731);
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void init() //initialization
{
OPTION_REG=0x00; //RBPU=0 enables the pull-up resistor of port B, INTEDG=0 triggers the falling edge interrupt
INTCON=0xD0; //GIE is 1 to allow general interrupts, INTE=1 enables RB0/INT external interrupts, INTF=0 clears the RB0 external interrupt flag
TRISB=0x01; //The lower 2 bits of port B are set to the keyboard input
TRISD=0; //The lower 4 bits of port D are set to the output of the LED
// PORTB=0x01;
PORTD=0; //Clear port D
}
void interrupt INT()
{
if(INTF==1) //Check if the interrupt flag is set to 1
{
INTF=0; //Clear interrupt flag
if(RB0==0) //Check if RB0 port is pressed again
{
PORTD=0x02; //Motor reverses
}
}
}
void main()
{
init();
while(1)
{
PORTD=0x00; //Motor reverses
}
}

This post is from Microchip MCU

Latest reply

Are GIE and PEIE open?   Details Published on 2020-9-11 11:58
 

1w

Posts

204

Resources
2
 

Any hint on the reason for the error?

This post is from Microchip MCU
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle

Comments

No error message. The interrupt can be set to 1, but the interrupt cannot be entered  Details Published on 2020-6-30 20:26
 
Personal signature

玩板看这里:

http://en.eeworld.com/bbs/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 

1w

Posts

25

Resources
3
 

The interrupt is not turned on.

This post is from Microchip MCU

Comments

INTCON=0xD0; //GIE=1 enables general interrupt, INTE=1 enables RB0/INT external interrupt, INTF=0 clears RB0 external interrupt flag.  Details Published on 2020-6-30 20:26
 
 
 

68

Posts

0

Resources
4
 

Using ICD2 simulation, you can see that the interrupt position is 1, but you cannot enter the interrupt.

This post is from Microchip MCU

Comments

I don't have the hardware of PIC16F877A, I can only use software simulation: currently I can enter the interrupt. From the perspective of program writing, the initialization section can be adjusted as follows: ① Set the pin level (PORTx→H, L); ② Set the pin direction (TRISx→input/output); ③ Set  Details Published on 2020-7-6 16:03
 
 
 

68

Posts

0

Resources
5
 
okhxyyo posted on 2020-6-28 05:58 Is there any hint for the error reason?

No error message. The interrupt can be set to 1, but the interrupt cannot be entered

This post is from Microchip MCU
 
 
 

68

Posts

0

Resources
6
 
dcexpert posted on 2020-6-28 09:04 The interrupt is not turned on

INTCON=0xD0; //GIE=1 enables general interrupt, INTE=1 enables RB0/INT external interrupt, INTF=0 clears RB0 external interrupt flag

With interrupt enabled

This post is from Microchip MCU
 
 
 

310

Posts

5

Resources
7
 

Help

This post is from Microchip MCU
 
 
 

637

Posts

2

Resources
8
 
yealien posted on 2020-6-30 20:25 Using ICD2 simulation, you can see the interrupt position 1, but you can't enter the interrupt.

I don't have the hardware for the PIC16F877A

Only through software simulation: Currently, it is possible to enter the interrupt. From the perspective of programming, the initialization section can be adjusted as follows:

①Set the pin level (PORTx→H, L);

②Set the pin direction (TRISx→input/output);

③Set the pull-up (if any);

④ Clear the relevant interrupt flags and set the interrupt enable bit;

⑤ Turn on the required general interrupt and external setting interrupt.

This post is from Microchip MCU

Comments

I changed the order, but it still doesn't work.  Details Published on 2020-7-10 18:54
 
 
 

68

Posts

0

Resources
9
 
dingzy_2002 posted on 2020-7-6 16:03 I don't have the hardware of PIC16F877A, I only use software simulation: currently I can enter the interrupt. From the perspective of program writing, I can initialize this section...

void init() //initialization
{
OPTION_REG=0x00; //RBPU=0 enables the pull-up resistor of port B, INTEDG=0 triggers the falling edge interrupt
INTCON=0xD0; //GIE is 1 to allow general interrupts, INTE=1 enables RB0/INT external interrupts, INTF=0 clears the RB0 external interrupt flag
TRISB=0x01; //The lower 2 bits of port B are set to the input of the keyboard
TRISD=0; //The lower 4 bits of port D are set to the output of the LED
// PORTB=0x01;
PORTD=0; //Clear port D
}

That's right.

This post is from Microchip MCU
 
 
 

637

Posts

2

Resources
10
 

I usually write like this:

①:

// PORTB=0x01;
PORTD=0; // Port D cleared

②:

TRISB=0x01; //The lower 2 bits of port B are set as keyboard input
TRISD=0; //The lower 4 bits of port D are set as LED
output③

OPTION_REG=0x00; //RBPU=0 enables the pull-up resistor of port B, INTEDG=0 triggers the falling edge interrupt
INTCON=0xD0; //GIE is 1 to enable general interrupts, INTE=1 enables RB0/INT external interrupts, INTF=0 clears the RB0 external interrupt flag

This post is from Microchip MCU

Comments

It seems to be the opposite of my order. I will try it tomorrow.  Details Published on 2020-7-7 19:58
 
 
 

68

Posts

0

Resources
11
 
dingzy_2002 posted on 2020-7-7 11:49 I usually write like this: ①: // PORTB=0x01; PORTD=0; &n ...

It seems to be the opposite of my order. I will try it tomorrow.

This post is from Microchip MCU
 
 
 

68

Posts

0

Resources
12
 
dingzy_2002 posted on 2020-7-6 16:03 I don't have the hardware of PIC16F877A, I only use software simulation: currently I can enter the interrupt. From the perspective of program writing, I can initialize this section...

I changed the order, but it still doesn't work.

This post is from Microchip MCU

Comments

I used software simulation, and I could enter the interrupt. When simulating with hardware, I could not enter the interrupt, and it mainly depended on the register configuration. In my experience, observing the changes in register data more often will help you find problems more quickly.   Details Published on 2020-7-11 14:45
 
 
 

637

Posts

2

Resources
13
 
yealien posted on 2020-7-10 18:54 I adjusted the order, but it still doesn't work.

I used software simulation, and I can enter the interrupt;

When hardware simulation is in progress, whether the interrupt is enabled or not depends mainly on the register configuration.

In my experience, observing register data changes more often will help you find problems more quickly.

This post is from Microchip MCU

Comments

I have no problem using software simulation, but I can't enter the interrupt with hardware simulation  Details Published on 2020-7-13 18:37
 
 
 

68

Posts

0

Resources
14
 
dingzy_2002 posted on 2020-7-11 14:45 I used software simulation and can enter the interrupt; When hardware simulation, entering the interrupt mainly depends on the register configuration problem; In my opinion...

I have no problem using software simulation, but I can't enter the interrupt with hardware simulation

This post is from Microchip MCU
 
 
 

2

Posts

0

Resources
15
 

Are GIE and PEIE open?

This post is from Microchip MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list