Problems with Microcontroller Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you the Codes for Registered Members of this site only, at free service...Follow Me.

External Interrupt PROJECT

PIC12F683 has got one external interrupt pin (GP2, pin 5) which is edge-triggered:

  • rising edge if INTEDG bit in OPTION register is SET,or 
  • falling edge if INTEDG bit in OPTION register is CLEAR
In this experiment we are going to simulate an external interrupt event by a tact switch which when pressed gives a falling edge (5->0V) to external interrupt pin. When a valid edge appears on GP2/INT pin, the INTF bit (INTCON<1>) is set. This interrupt can be disabled by clearing INTE control bit (INTCON<4>). While exiting from the Interrupt Service Routine, INTF flag must be cleared to re-enable the interrupt again. ANSEL and CMCON0 must be initialized to configure GPIO as digital I/Os.

On the arrival of an interrupt, the new value of counter will increase by 1 and is displayed as no. of interrupts serviced.  

Experimental Setup:
External interrupt will be simulated by a tact switch on the board. So connect SW1 to GP2 with a jumper wire. For display purpose we will again use a hyperterminal window on a PC.




Software:

   /*
  PIC12F683 Experiment Board
  Experimen No. 4 : External Interrupt
  Date: 06/26/2010
*/
char Message1[] = "Interrupt Demonstration!";
char Message2[] = "Interrupt No.= ";
char *temp = "00", error;
unsigned int i, old_count=0, new_count=0;

// Interrupt Service Routine
void interrupt(void){

    if (INTCON.INTF == 1)          // Check if INTF flag is set
       {
     new_count++;       // If yes, increase counter
     temp[0] = new_count/10 + 48;  // Convert count digits into characters
     temp[1] = new_count%10 + 48;
     INTCON.INTF = 0;       // Clear interrupt flag before exiting ISR
    }
   }

// Main program
void main() {
CMCON0 = 7;
TRISIO = 15;  // GPIO 0, 1, 2, 3 Inputs; Rest are O/Ps
ANSEL = 0;
OPTION_REG = 0x00;       // Clear INTEDG, External Interrupt on falling edge
// Interrupt Setup
    INTCON.INTF = 0;     // Clear interrupt flag prior to enable
    INTCON.INTE = 1;     // enable on change interrupts
    INTCON.GIE  = 1;     // enable Global interrupts

// Define GPIO.3 as UART Rx, and 5 as Tx
error = Soft_UART_Init(&GPIO,3, 5, 9600, 0 );
Delay_ms(100);

do {

 for (i=0; i<= 23; i++) {
      Soft_UART_Write(Message1[i]);
      Delay_ms(50);
     }
  Soft_UART_Write(10); // Line Feed
  Soft_UART_Write(13); // Carriage Return
  delay_ms(500);

 if (new_count > old_count)
       {
     for (i=0; i<= 13; i++) {
      Soft_UART_Write(Message2[i]);
      Delay_ms(50);
     }
     for (i=0; i<= 1; i++) {
      Soft_UART_Write(temp[i]);
      Delay_ms(50);
     }
  Soft_UART_Write(10); // Line Feed
  Soft_UART_Write(13); // Carriage Return
  old_count=new_count;
     }

 } while(1);
}

Experimental Output:
On hyperterminal window, you will continuously see a message "Interrupt Demonstration!". When you press the tact switch, that will give an interrupt (falling edge), and the counter value goes up by 1. The updated counter value will be displayed.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Recent Comments

Popular Projects

Give Support

Give Support
Encourage Me through Comments

Microcontroller Projects

Total Pageviews