Q3 [18 marks]
Timer1 is assumed to be used to maintain a real-time clock keeping track of tenths of a
second, seconds, and minutes. You are required to display the seconds counter only
using 6 LEDs connected to PORTD pins (RD0-RD5) as a binary display showing the
running seconds. Assume Timer 1 is configured to rollover every 0.1 sec. Review the
following steps and complete the given partial code:
a. Three global integer variables (dsec, sec, min) that will act as the tenths of a
second, seconds, and minutes counters, respectively are declared.
b. Assume Port D and Timer 1 are configured and no need to be configured
You are required to complete Timer 1 ISR to do the following:
c. Increment the tenths of a second counter (dsec++) every time the timer
overflows.
d. If the tenths of second counter exceeds 9 (>=9), increment the seconds counter
(sec++) and reset dsec.
e. Display the seconds counter value on the 6 LEDs
f. If the seconds counter exceeds 59 (>=59), increment the minutes counter (min++)
and reset sec
g. If min>59, reset min.
//global variables: dsec, sec, and min declaration
int dsec = 0;
int sec = 0;
int min = 0;
void _attribute__((interrupt, auto_psv)) ISR_T1Interrupt (void)
{
// write C code here to implement steps c to g above.
}
Student Name:
int main (void)
{
// Assume Port D is configured
// Assume Timer 1 configured to rollover every 0.1 seconds
// Assume Timer 1 interrupt is configured and enabled.
while (1)
{
}
return 0;
}
Student ID: