Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write s program using an Interrupt Service Routine that does the following : Q3. [8 marks] Write a program using an Interrupt Service Routine that
Write s program using an Interrupt Service Routine that does the following :
Q3. [8 marks] Write a program using an Interrupt Service Routine that does the following : Waits for a Single High Pulse of 200 ms,on Pin OC1. When the High Pulse goes from High to low, it turns ON the LED at Port A,RA0 and the LED then stays on. You will use the Output Compare OC1, Dual Compare mode with a Single High Pulse (OCM=004). You will use Timer 2 for the OC with a pre-scale value of 256 . You need to setup OC1RS and OC1R such that OC1RS - OC1R =200ms We need to convert 200m into Timer Clock Cycles. We have Timer 2 with a 80Mbz PBClk and a Precale, of 256. We will use the PR formula for the Timer delay from before. 200ms=(PR+1)/(pBLCK/256)20010(3)=(PR+1)/(80106/256)) instead of PR+1 we will call this value X. X=20010(3)(8010n6/256)=62,500 slk, cycles Hence 200ms=62,500 clk, cycles. To make OC1RS- OC1R =62,500 clk cycles , We need to make OC1R some value >0, so we will make OC1R= 1 and OC1RS =62,501. Now OC1RS-OC1R = 62,5011=62,500 Hence OC1R =1 OC1RS =62,501 You will set the ISR Routine of OC1 to turn on the LED at RA0. Because this is a Single Pulse, this will Interrupt will run only once. You do not need to include any \#pragma compiler directive (the DEVCFG initial setup)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started