Question: / * * EX: 7 . 0 When configuring hardware peripherals to generate interrupts, it is important to ensure that interrupts cannot be raised by
EX:
When configuring hardware peripherals to generate interrupts, it is
important to ensure that interrupts cannot be raised by other
peripherals while this configuration is taking place.
TASK: Disable interrupts globally before configuring the TCB peripheral
and reenable interrupts globally afterwards.
HINT: Use the cli and sei functions provided by avrinterrupth
void clockinitvoid
CODE: Write your code for Ex within this function.
TCB is a bit timer that has been configured to generate
an interrupt every th of a second. This was done to increase
the resolution of the timer.
TCBCCMP ;
TCBCTRLB TCBCNTMODEINTgc;
TCBINTCTRL TCBCAPTbm;
TCBCTRLA TCBENABLEbm;
EX:
The stopwatch will be controlled by pushbuttons S S and S
TASK: Write code to configure the pins connected to these pushbuttons
to generate an interrupt on falling edges.
See ATtiny Datasheet Register Summary PORTx on p and
Pin n Control on p
void buttonsinitvoid
CODE: Write your code for Ex within this function.
EX:
To display the elapsed time on the segment display, we need to count
the number of times the TCB CAPT interrupt is invoked.
TASK: Declare a global variable called "count that will be used
to store a count of seconds that have elapsed.
Ensure this variable is sufficiently large so that it can represent the
largest value that can be displayed on the segment display.
The stopwatch should initially display x
CODE: Write your code for Ex above this line.
EX:
To allow pushbuttons S and S to control when the stopwatch is
counting, we need to keep track of the state of the stopwatch.
TASK: Declare a global variable called iscounting" that keeps track
of the stopwatch's state.
The stopwatch should initially be paused.
CODE: Write your code for Ex above this line.
EX:
TASK: Declare an interrupt service routine ISR for the TCB peripheral
that was configured in Ex
Find the vector number and name that correspond to the TCB CAPT
interrupt.
Refer to datasheet Section Interrupt Vector Mapping on p
Given that vectors are of the form vect", find the appropriate
macro corresponding to the vector number identified in step
Type vect" to invoke VSCode suggestions.
Declare an ISR using the ISR macro syntax, where
is the macro identified in step
If the stopwatch is currently counting, increment "count by
Ensure that this variable does not exceed the value which represents
s xFF s
As the value displayed on the segment display is a count of s
define a local variable called "count and convert "count to
a count of s
Update the segment display to reflect the value of "count
Acknowledge that the interrupt has been handled by clearing the CAPT
bit in the TCBINTFLAGS register.
See ATtiny Datasheet Interrupt Flags on p for
information on how to clear this bit.
NOTE: You may use displayhex to display a number in hexadecimal on
the segment display. This function accepts an unsigned bit integer.
To find the maximum value of "count in step and to perform the
conversion in step you will need to use the following relationship to
convert between counts of s and counts of s:
second second
CODE: Write your code for Ex above this line.
EX:
To allow the variables "count and iscounting" to be shared between
compilation units ie srctimerc and srcbuttonsc we must declare
them as external variables.
TASK: Declare "count and iscounting" as external variables.
NOTE: An external declaration must not provide an initialisation.
CODE: Write your code for Ex above this line.
EX:
TASK: Write an interrupt service routine for PORTA, that will be invoked
when a falling edge is detected on any pins connected to pushbuttons S
S or S
This ISR should check which pin generated the interrupt, and perform
one of the following actions:
If S is pressed, start the stopwatch.
If S is pressed, pause the stopwatch.
If S is pressed, reset the stopwatch to x
See ATtiny Datasheet Interrupt Flags on p for
information on how to clear these interrupt flags.
NOTE: Each pin has its own interrupt flag, and you must only clear the
interrupt flag for the pin that generated the interrupt.
CODE: Write your code for Ex above this line.
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
