Skip to main content

Interrupt of PIC 16F877A


Interrupt of PIC 16F877A




Features of the external interrupt that we will use.
The interrupt is triggered by an input on RB0, either ( depending on how we set it up ) as the signal goes from 0 to 1, called the rising edge, or as the signal goes from 1 to 0, called the falling edge. This sets the interrupt flag, and if the interrupt is enabled ( and we are not already in an interrupt ) the microcontroller goes to the interrupt subroutine.
The use of the RB0/Int to manage interrupt externally generated requires the setting of a couple of registers of the picmicro: INTCON and OPTION_REG   



 

It should be clear that the use of RB0/Int function of a picmicro requires the setting of the:
GIE(7): set to 1 to enable global interrupts
INTE(4): set to 1 to enable interrupts on pin RB0
PEIE(6): to disable other periferal interrupts
and the set of the INTEDG bit(6) of the OPTION_REG register simply to select the  rising or falling edge, of the signal.










When switch is pressed RB0 goes from 0 to 1 causing an interrupt which calls the interrupt() routine. The interrupt routine increment the value of PORD by one. 



Code


  void interrupt(void)
{
  PORTD++;          //Increment PORTD value by one
  //delay_ms(500);
  INTCON.INTF = 0;          // clear the interrupt flag
}

void main(void)
{
  TRISB = 0x01;
  TRISD = 0x00;
  INTCON.GIE = 1;                  //Enable Global Interrupt
  INTCON.INTE = 1;                //Enable RB0/INT external Interrupt
  INTCON.PEIE = 0;                //Disable all unmasked peripheral interrupt
  OPTION_REG.INTEDG = 1;    //Interrupt on rising edge
  PORTD=0;
do
  {

   } while(1);
}



Circuit
Interrupt of PIC 16F877A

Comments

  1. Hi, you can simplify the HW and thereby save R2 by configuring RBPU (Pullups on Port B) and using the switch to pull RB0 to GND instead to Vcc.
    Then INTEDG needs to be set to zero to interrupt on keypress.


    With your HW you can simplify the SW. INTEDG is set to 1 on Reset - so "OPTION_REG.INTEDG = 1;" not needed

    ReplyDelete
  2. Nice information about the microcontrollers which comes under embedded projects. PIC microcontrollers are used to perform various number of tasks. They are used in alarms,control systems,phones,etc. This microcontroller has special features such as flash memory, Data SRAM, Data EEPROM, Watchdog Timer,etc.

    ReplyDelete

Post a Comment

Popular posts from this blog

PIC 16F877A Microcontroller Based Electronic Lock 16x2LCD 4x3 Keypad

 Circuit Diagram Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible. An access control for doors forms a vital link in a security chain. The microcontroller based digital lock for Doors is an access control system that allows only authorized persons to access a restricted area. An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a Keypad, LCD and the controller PIC16F877A. This article describes the making of an electronic code lock using the 16F877A microcontroller. The system is fully controlled by the 8 bit microcontroller 16F877A which has a 8Kbytes of ROM for the program memory. The password is stored in the

Electronic Voting Machine Using 8051 Microcontroller (AT89C51)

  Circuit Electronic voting machine has now replaced the traditional mechanism of voting due to several advantages like security, automatic counting etc. This project presents a way to develop an electronic voting machine which displays the count of votes on a 16x2 LCD interface. A user can get his/her vote register through a set of switches (one for each candidate). After every cast of vote, the subsequent count can be seen on LCD. The circuit uses AT89C51 microcontroller and the code for the project has been written in C. This LCD based electronic voting machine is designed for four candidates. The input part consists of a set of six tactile switches. The switches and 16x2 LCD are interfaced to microcontroller AT89C51 for various operations and displays. The provision of casting votes for the candidates has been provided through four of these switches. These switches are made active high and connected to pins 2-5 (P1^1 – P1^4) of the controller. The remaining two

89C51 Based Digital Thermometer Using DS1820

Introduction The hardware configuration when using multiple 1-Wire temperature sensors like the DS1820 is very simple, as illustrated in the block diagram below. A single-wire bus is used for communication between the microcontroller and the temperature sensor. It is also possible to power the devices direclty via this 1-Wire bus. An almost unlimited number of 1-WireTM devices can be connected to the bus because each device has a unique 64-bit ROM code identifier which is used to address each sensor   Temperature measurement using DS1820 sensor. Use of ‘1-wire’ protocol... Temperature measurement is one of the most common tasks performed by the microcontroller. A DS1820 sensor is used for measurement here. It is capable of measuring temperature in the range of -55 °C to 125 °C with 0.5 °C accuracy. For the purpose of transferring data to the microcontroller, a special type of serial communication called 1-wire is used. Due to a simple and wide use of these sensors, commands us