Skip to main content

Subsection 10.3.13 Part 10: Coding Challenge

Write some counters that show on the display: this will help you get ready for Lab 5.

Activity 10.3.9. Coding Challenge: Counters on the Display.

These coding challenges will help you get ready for the lab. First: rename the library you just finished from SevenSegPartial.c and SevenSegPartial.h to SevenSeg.c and SevenSeg.h, change the #include to match, and move both into your mylib folder alongside i2c.c and i2c.h, so that they are ready to use in Lab 5.

(a)

Show a 16-bit unsigned counter, incrementing once a second on the display. Write SevenSeg_number() to do the conversion: it takes a number and fills a buffer with the segment patterns for its digits. Four digits hold 0 to 9999, so decide what it should do with a number that does not fit and add a comment to your code to explain your choice.

(b)

Show an 8-bit signed counter, −128 to 127. You will need a minus sign, which is one segment; if you want an absolute value, #include <stdlib.h> gives you abs().

(c)

Show a clock, MM:SS, counting up from zero. Here you need the colon, so you need to have found which bit in display_buffer[4] lights it.

(d)

Optional, and worth doing before Lab 5: drive the update from a timer interrupt rather than delay_ms(), so the counter keeps time while the main loop does something else.
Lab 5 is due Tuesday. It asks for a modular ADC driver, an ADC reading taken on a timer interrupt rather than a delay, and a seven-segment display driver, and it says to use the code you developed in class today as the basis for the last of those. The counters above are the same shape as what it wants on the display.