PART 1 : Basic Introduction
PART 2 : Interrupt
PART 3 : Timer
PART 4 : Calculation
PART 5 : LED Switching Project [END]
Part-2 : Interrupt
In this part I will describe about microcontroller's interrupt . You must learn about this, it's really important !!.
Interrupt means, make any restriction to something. In microcontroller when interrupt happens, the total process is restricted and microcontroller executes only the instructions which are provided into the interrupt function .
Consider that we are driving a car on the road. The road is clean and clear. So we are doing what we are supposed to do. Compare this with microcontroller or microprocessor and we find that MCU performs it's general routine at a running state like our car. Alright.
Again consider, suddenly three dogs have come to the middle of the road. So we need to stop and get those dogs out of there. After doing that we can move forward. When we saw the dogs, our journey was interrupted and we needed to do some certain things. Compare that with microcontroller. When microcontroller gets notifications about interrupt, microcontroller forget everything and perform tasks that are written inside the interrupt function. After doing that MCU gets back to it's general routine. That's the way the microcontroller or microprocessor's interrupt works.
There are two types of Interrupt
1. Internal Interrupt 2.External Interrupt
***Internal Interrupt :
Internal interrupts occurs during the time of internal events. Timer overflow interrupt can be considered as a kind of internal interrupt. When timer counts and timer register becomes full with data, on that situation it's required to reset the register so that it can count again. On that situation timer overflow interrupt occurs. Interrupt function clears the register and finally mcu goes to the regular routine .
In this Part , I will describe only about External Interrupt.
***External Interrupt :
External interrupt occurs during the time of external events. When any external signal comes to the external interrupt pin, external interrupt happens. To understand completely, we will interface a push button with microcontroller and that will provide an interrupt signal to the MCU.
Now it's time to take a look on pic 18f25550 microcontroller's properties:
![]() |
INTCON Register of PIC 18f2550 |
Note : INT pins indicates the pins for External Interrupt
PIC18f2550 microcontroller has three external interrupt pins(As far as I am concerned), which are RB0(INT0), RB1(INT1) and RB2(INT2). To control these pins we have INTCON, INTCON2 and INTCON3 registers. In this tutorial we will use RB0(INT0) as an external interrupt and we will see an example of this.
![]() |
Pin Out of PIC 18f2550 |
Now take a look on INTCON register
![]() |
INTCON Register of PIC 18f2550 |
![]() |
INTCON Register |
Required Configuration to Setup RB0(INT0) as Interrupt:
1. First set Global interrupt [INTCON.GIE=1] to 1.
2. Set Peripheral Interrupt to 1 .[INTCON.PEIE=1]
3. Set RB0 as External Interrupt .[INTCON.INT0IE=1]
4. Disable Pull-Ups on PortB [INTCON2.RBPU=1].
5. Finally set RB0 interrupt flag [INTCON.INT0IF=0]
6. Setup interrupt on RB0 as Falling Edge (You may use rising Edge) [INTCON2.INTEDG0=0]
INTCON.GIE=1; // Enabling Global Interrupt
INTCON.PEIE=1; // Enables Peripheral Interrupt
INTCON.INT0IE=1; // Enables RB0 pin as external interrupt
INTCON.INT0IF=0; // Set the RB0 interrupt flag as 0 . that means no interrupt happens .
INTCON2.RBPU=1; // DISABLE PULUP REGISTER
INTCON2.INTEDG0=0; // Set Interrupt on RB0(INT0) as Falling Edge .
![]() |
INTCON2 Register |
Interrupt on Rising Edge and Falling Edge
It's required to set exact condition of interrupt. That means, which condition should be considered as an interrup . Is it for, from 0 to 1 Condition? or from 1 to 0 Condition ?
Interrupt Flag:
Now we will create a project where a push button will be connected with RB0 pin. When button is pressed, the RB0 pin will receive a falling edge signal of external interrupt event. At that time the MCU will follow the interrupt service routine.
Listen to me, carefully. Flag is one kind of indicator. When any interrupt occurs at RB0 pin, this makes INTCON.INT0IF=1; That means RB0 pin related interrupt flag becomes 1. This gets our microcontroller understand that interrupt has happened. When we set INTCON.INT0IF=0, microcontroller continues to it's general function routine. That's why we need to clear INTCON.INT0IF=0 in interrupt function and microcontroller goes to perform it's general routine. If again interrupt occurs, flag is set to INTCON.INT0IF=1. After execution of interrupt function which makes INTCON.INT0IF=0 and microcontroller goes to perform it's general routine. That's all .
![]() |
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-2 |
Note :1. In coding the External Interrupt ( INT ) pin should be declared as digital input pin .
2.To write interrupt function routine . We just need to write a function like this ,
void interrupt(){
......
......
..}
Your microcontroller will automatically understand that it is a interrupt routine .
MikroC Source Code for External Interrupt :
//
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections
unsigned int count=0,sgnal=0;
int chk=7,j=0,xr=0;
void interrupt()
{
if(INTCON.INT0IF){
PORTC=0xFF;
chk=3;
INTCON.INT0IF=0;
}
}
void main()
{
ADCON1=0x0F;
CMCON=7;
TRISC=0x00;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
INTCON.GIE=1;
INTCON.PEIE=1;
INTCON.INT0IE=1;
INTCON.INT0IF=0;
INTCON2.RBPU=1; // DISABLE PULUP REGISTER
INTCON2.INTEDG0=0;
while(1){
PORTC=0x00;
if(chk==7){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"General");
Lcd_Out(2,3,"Routine");
} else{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Interrupt");
Lcd_Out(2,3,"Routine");
chk=7;
}
}
}
It isn't wise to use delay_ms() function in this case .
Proteus Circuit for External Interrupt :

IR (Infrared) Remote Control Communication Between Two Microcontroller -Step By Step Tutorial : Part-2

pl clear here my dabout
ReplyDeleteif i use RA4 for External Interrupt in place RB0
then what need change in code
we can use as
INTCON.GIE=1; // Enabling Global Interrupt
INTCON.PEIE=1; // Enables Peripheral Interrupt
INTCON.RA4=1; // Enables RA4 pin as external interrupt
INTCON.RA4=0; // Set the RA4 interrupt flag as 0 . that means no interrupt happens .
// INTCON2.RBPU=1; // DISABLE PULUP REGISTER
// INTCON2.INTEDG0=0; // Set Interrupt on RB0(INT0) as Falling Edge .
i'm right way ?
Sorry for being late. My comment wasn't working for a long time. I couldn't fix it. Yeah, It's supposed to work as you said. Good luck!
DeleteExcellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. agentie pr
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteOne of the things I miss the most is my physics class. There, we used to undertake a lot of electrical experiments, and now that college has ended, I'm imprisoned behind the digital bars. Experimenting on my own is becoming increasingly tough for me. I am now in the University and have an assignment to finish and would greatly appreciate it if you could provide some research proposal help UK for my physics project. After that, I believe I'll be able to conclude this experiment. So, what are your opinions on the subject?
ReplyDeleteGreat topic! I have read this topic for the last night.It was really helpful and informative for me and all the readers.If you are looking to buy an online free dissertation topics to the student of uk at an affordable and reasonable price.
ReplyDeleteWORLD OF WARSHIPS BLITZ MOD APK is a new action-packed free-to-play game that puts players in control of legendary warships in explosive team battles. Download world of warships blitz mod apk – Unlimited Everything – for Android to play with all ships unlocked, unlimited money
ReplyDeleteThanks for sharing. you can read motherboard reviews on our website here is the link https://demotherboards.com/best-motherboard-for-ryzen-9-5900x/
ReplyDeleteThese tips will help me to complete some task in the builder hall 3 base defense download and win the games.
ReplyDeleteI’m really happy to say it was an interesting post to read. I learned new information from your article on nmims solved assignment december 2022
ReplyDelete, you are doing a great job
Need some insights about the instagram baddie outfits
ReplyDeleteI've been reading a lot of blogs over the past two months as I've tried to understand the reasoning behind ARM MCUs. essay writing Company in California You consistently make the best presentations!
ReplyDeleteBut if any interruption arrives, like some object suddenly appearing in front of our car, we must immediately stop and take necessary action. In the microcontroller, when the interrupt comes, the microcontroller contains its running routine and goes to the interrupt function and executes the provided instruction. In this way, interrupt will help us a lot to make our program much better and more accurate. I think this is enough to understand the interruption. If you need more help understanding this topic, look up narrative essay writing help to get more information and guidance.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteTo ensure the integrity of your website's content, using the free plagiarism checker uk is crucial. This tool helps identify any potential copied material and maintain originality. Additionally, like pokieslab.com/aristocrat/, consider politely requesting visitors to disable their ad blockers as advertising revenue supports the project. You can continue delivering valuable content by encouraging users to support your efforts while ensuring a fair user experience.
ReplyDeleteFor numerous applications, efficient communication between two microcontrollers is essential, enabling data transmission and cooperation in embedded systems. Data transport is made seamless by using reliable communication protocols like UART, SPI, or I2C. professional cv services canada in Canada can help you highlight your knowledge of microcontroller programming and embedded systems, improving your career prospects in this specialized field, if you are an engineer or developer working on such projects.
ReplyDelete