Question: Description: - This program uses a pushbutton ( PBO ) connected to the external INT input ( i . e . on pin RB 0
Description: This program uses a pushbutton PBO connected to the external INT input ie on pin RB of the PICF to trigger an interrupt everytime the button is pressed. When PB is pressed, it generates an interrupt, which increments a counter in the Interrupt Service Routine. The counter keeps track of how many times the pushbutton PB is pressed inside the Interrupt Service Routine. The value of the counter is displayed on the LEDs connected to PORTA.
Instructions:
Create a Global Variable btncount" and initialise it to The variable btncount" is used to count the number of times that the button PB is pressed.
Setup RB pin as a digital input.
Setup all pins on PORTA as digital outputs.
Setup the RBOINT external interrupt:
a Setup Interrupt on the rising edge of RB Bit "INTEDG". See OPTIONREG Page of PICF Datasheet
b Enable RBINT External interrupt Bit "INTOIE". See INTCON Page of PICF Datasheet
c Enable Global Interrupt Bit "GIE". See INTCON Page of PICF Datasheet
In main leave an empty while loop as all the functionaility will be contained in the
Create an Interrupt Service RoutineISR:
a Use function header for ISR: void interrupt isrvoid
b Inside the ISR
iquad Check if the INTIF flag has been set Page PICF Datasheet
ii If INTOIF flag if set, increment btncount" variable.
iii. Use the variable btncount" to directly drive the LEDs connected to PORTA. iv Reset the INTOIF flag
At this point, you should have a working program that functions as descried in the description section above. Simulate the program in Proteus to ensure that it works as it should.
Toggle the value of the "INTEDG" bit and record your observations in a Microsoft Word file that you submit along with the Proteus exercises within the Zip file. Name the Word File "ExerciseAnswers.doc". As an example list your observation as follows:ANS: EXPart After adjusting the INTEDG bit......
Inside the ISR: Put the value of INTEDG back to its original value, before Step Comment out where you reset the INTOIF flag. Insert a delay of mSec inside the ISR to observe the result of not resetting the INTOIF flag. Record the effect of not resetting the INTOIF flag and state the reason for the observed effect in the Microsoft Word file that you created above. As an example list your observation as follows:
ANS: EXPart The result of not resetting the INTOIF flag,......
Return the code to a working state ie end of Step above Download the code to the PIC development board using the PPP programmer. Ensure the LEDs are connected to PORTA whith the switches connected to PORTB. What nonideal behavour do you notice on real hardware? State your answer in the Microsoft Word File ANS: EXPart
Inputs:ie RB
Outputs:ie RA RA Enter Interrupt Service Routine
INTOIF set bit happens automatically when an interrupt occurs once the interrupt is configured
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
