Pic Microcontroller Programming Tutorial For Beginners using MikroC With Step By Step Guide.

Sunday, December 20, 2015

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

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 a 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 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 the dogs out of there . After doing that we can move . When we saw the dog , our journey was interrupted and we needed to do a certain process. Compare that with microcontroller. When microcontroller get notification about interrupt,  microcontroller forget everything and perform tasks that are written in interrupt function . After doing that MCU get back to it's general routine . That's the way the microcontroller or microprocessor's interrupt work .
how to control an external interrupt
how to control an external interrupt

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 one 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 clear 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 event to the MCU .

Now it's time to take a look on pic 18f25550 microcontroller's properties: 
IR (Infrared) Remote Control Communication Between Two Microcontroller -Step By Step Tutorial : Part-2
INTCON Register of PIC 18f2550

Note : INT pins indicates the pins for External Interrupt
PIC 18f2550 microcontroller has three external interrupt pins , 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 .
IR (Infrared) Remote Control Communication Between Two Microcontroller -Step By Step Tutorial : Part-2
Pin Out of PIC 18f2550
Now take a look on INTCON register
IR (Infrared) Remote Control Communication Between Two Microcontroller -Step By Step Tutorial : Part-2
INTCON Register of PIC 18f2550
IR (Infrared) Remote Control Communication Between Two Microcontroller -Step By Step Tutorial : Part-2
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 . 
IR (Infrared) Remote Control Communication Between Two Microcontroller -Step By Step Tutorial : Part-2
INTCON2 Register

Interrupt on Rising Edge and Falling Edge

It's required to set exact condition of interrupt. That means, which condition can be considered as an interrupt . 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 receive a falling edge signal of external interrupt . At that time the MCU follows the interrupt function 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 set 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 this interrupt function makes INTCON.INT0IF=0 and microcontroller goes to general routine.That's all .

IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-2
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
IR (Infrared) Remote Control Communication Between Two Microcontroller -Step By Step Tutorial : Part-2

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



Download this project

>>Continue to 3rd PART<<

Reactions:

1 comments:

Post a Comment

Share and Bookmark this Blog

Learn at Udemy :

10 Amazing Microcontroller projects for Engineering students

Tags

: (1) 18F2550 (1) 36KHz (3) and (1) Based (1) battery (1) Bipolar (1) Blinking (1) blinks (1) Bluetooth (1) bluetooth device interfacing (1) bluetooth module (1) button (1) circuit (1) clock (1) control (1) crystal oscillator (3) Db9 (1) DC Motor (2) digital (2) Digital Voting Machine (1) digital voting machine using pic (1) display (2) DS1307 (1) electronic (1) embedded c programming tutorial (11) embedded c tutorial (11) experiment kit (4) external interrupt (4) flash (1) flashing (1) Gas Leakage detector (1) HC-06 (1) home (1) how (1) How to (10) i2c tutorial (1) in (1) indicator (1) infrared Connection (3) interface (8) interfacing (3) Interrupt (3) Introduction (1) IR Connection (3) IR Receiver (4) IR Transmitter (4) key pad (1) keypad (1) lavel (1) Lcd 16x2 (2) lcd 2x16 (2) led (1) lm35 (2) LPG (1) machine (1) make (1) Make bootloader (1) making (1) matrix (1) max232 (1) membrane keyboard (1) meter (2) Micocontroller (1) microchip (4) microchip pic (2) microchips (3) microcontroller (9) microcontroller based (3) microcontroller programming (3) Microcontroller Project (4) Microcontroller Projects (1) microcontroller_project (2) microcontrollers (4) Microprocessor (2) mikroC (5) mikroc code to start and stopstart and stop dc motor (1) mikroc pro for pic (2) Motion detector (1) MQ-9 Gas Sensor (1) musical (1) NEC Protocol (4) pcb (5) PIC (3) pic controller (11) pic microcontroller (11) pic microcontroller tutorial (11) pic programming (1) pic programming in c (12) pic proteus (1) Pic Tutorial (12) pic18 (2) pic18f2550 (11) picmicrocontroller (4) picRFモジュール (1) PIR Motion Sensor (1) printed circuit board (1) proteus (6) pulse width modulation (1) push (1) push button (1) PWM (1) real (1) rf transmitter (3) Rs 232 (1) Rs232 (1) scroll (1) scrolling (1) Serial communication (1) Serial Connection (1) Serial Port (1) serial port rs232 (1) Servo Motembedded c programming tutorial (1) simulation (2) Soil Moisture Meter (1) speed control (1) step by step (7) step bystep (1) Stepper Motor (2) text (2) Thief Detector (1) time (1) timer (4) timer0 (4) tone (1) TSOP38236 Receiver (4) tutorial (2) Unipolar (1) USART Connection (1) USB (1) usb 1.0 (1) USB bootloadere (1) USB HID (1) using (9) voltmeter (1) voting (1) water level indicator (3) with (2) work (1)

Definition List

Comment Option isn't working properly

Comment option isn't working properly. If you have anything to say, you are requested to use the "Contact Form" below here.

Leave Your Message Here

Name

Email *

Message *

Google+ Followers

Like on Facebook