Question
USE CODE BELOW #include #include #include #include #include #include #include #include #include lcd_model.h void draw_double(uint8_t x, uint8_t y, double value, colour_t colour); void draw_int(uint8_t x,
USE CODE BELOW
#include
#include
#include
#include
#include
#include
#include
#include
#include "lcd_model.h"
void draw_double(uint8_t x, uint8_t y, double value, colour_t colour);
void draw_int(uint8_t x, uint8_t y, int value, colour_t colour);
void setup(void) {
set_clock_speed(CPU_8MHz);
lcd_init(LCD_DEFAULT_CONTRAST);
lcd_clear();
// (a) Initialise Timer 1 in normal mode so that it overflows
// with a period of approximately 0.5 seconds.
// Hint: use the table you completed in a previous exercise.
// (b) Enable timer overflow for Timer 1.
// (c) Turn on interrupts.
// (d) Display your student number, "r20395748", with nominal top-left
// corner at screen location (11,23). Left-aligned 10
// pixels below that, display the pre-scale factor that corresponds
// to a timer overflow period of approximately 0.5
// seconds.
// Keep the next instruction intact.
show_screen();
}
// (e) Create a volatile global variable called cycle_count.
// The variable should be a 32-bit unsigned integer of type uint32_t.
// Initialise the variable to 0.
// (f) Define an interrupt service routine to process timer overflow
// interrupts for Timer 1. Every time the interrupt service
// routine is called, cycle_count should increment by 1.
// (g) Define a function called now which has
// no parameters, but returns a value of type double which contains
// the total elapsed time measured up to the time at which it is called.
// Use the method demonstrated in the Topic 9 lecture to compute the
// elapsed time, taking into account the fact that the timer counter has
// 16 bits rather than 8 bits.
// -------------------------------------------------
// Helper functions.
// -------------------------------------------------
char buffer[20];
void draw_double(uint8_t x, uint8_t y, double value, colour_t colour) {
snprintf(buffer, sizeof(buffer), "%f", value);
draw_string(x, y, buffer, colour);
}
void draw_int(uint8_t x, uint8_t y, int value, colour_t colour) {
snprintf(buffer, sizeof(buffer), "%d", value);
draw_string(x, y, buffer, colour);
}
// -------------------------------------------------
// Test driver.
// -------------------------------------------------
void process(void) {
double time = now();
draw_string(0, 0, "Time = ", FG_COLOUR);
draw_string(10, 10, " ", FG_COLOUR);
draw_double(10, 10, time, FG_COLOUR);
show_screen();
}
int main(void) {
setup();
for ( ;; ) {
process();
}
}
Do not use the static qualifier for global variables.
Make sure you include any helper function(s) such as draw_int required by your solution.
mplement and test a function called now which computes the elapsed time from power-up in a Teensy. the program will use a designated 16-bit timer in normal mode, with overflow interrupt handling. Time calculation will be accurate to the nearest timer update "tick" our task is to adapt the sample program provided in Lecture 9: Implementing Timer Overflow ISR to implement a new library function called now) which is capable of tracking lapsed time for a reasonably long period. se Timer 1, and set it up in normal operational mode so that it overflows approximately once every 0.5 seconds. Create a global 32-bit unsigned integer variable called ycle_count. Implement an interrupt service routine which increments cycle_count by 1 every time the timer overflows. Implement a function called now() which returns e elapsed time since program start, accurate to the nearest timer "tick", as a double-precision floating point value. o implement the function, follow the detailed specification laid out in comments in the program skeleton below. mplement and test a function called now which computes the elapsed time from power-up in a Teensy. the program will use a designated 16-bit timer in normal mode, with overflow interrupt handling. Time calculation will be accurate to the nearest timer update "tick" our task is to adapt the sample program provided in Lecture 9: Implementing Timer Overflow ISR to implement a new library function called now) which is capable of tracking lapsed time for a reasonably long period. se Timer 1, and set it up in normal operational mode so that it overflows approximately once every 0.5 seconds. Create a global 32-bit unsigned integer variable called ycle_count. Implement an interrupt service routine which increments cycle_count by 1 every time the timer overflows. Implement a function called now() which returns e elapsed time since program start, accurate to the nearest timer "tick", as a double-precision floating point value. o implement the function, follow the detailed specification laid out in comments in the program skeleton belowStep 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