Skip to main content

Project 4: Digital Calendar (40 points)

Task Description​

Build a digital calendar using buttons and a 4-digit 7-segment display. The display initially shows "0000". Press a button to switch between displaying the year "2026" and the month-day "0131", and continue cycling.

Core Concepts: Dynamic display of multi-digit 7-segment displays and state switching triggered by button presses.

Required Hardware​

  • Steamania JoyKit V2 (Main Controller)
  • 4-Digit 7-Segment Display Module
  • Push Button Module

Core Tasks​

  1. Initialize 7-segment display to show "0000"
  2. Implement button press detection
  3. Toggle between year display mode (2026) and month-day display mode (0131)
  4. Continuously cycle through the display modes

Reference Solution​

Program Code​

; Digital Calendar Program
; Display year and month-day using 4-digit 7-segment display

; Initialization - Lines 000-002
000 C7 0001 0000 ; Enable 7-segment display control
001 10 0000 0000 ; Initialize display to show "0000"
002 0E 0000 0010 ; Jump to main loop at line 010

; Main Loop - Start at Line 010
010 04 0001 0020 ; If button pressed (R01 > 0), jump to mode switch at line 020
011 11 0030 0000 ; R00 = R30 (current display mode)
012 04 0000 0018 ; If R00 == 0 (year mode), jump to line 018
013 10 2026 0000 ; Set display to year "2026"
014 02 0064 0000 ; Delay 100ms
015 0E 0000 0010 ; Jump back to line 010 (loop)

018 10 0131 0000 ; Set display to month-day "0131"
019 02 0064 0000 ; Delay 100ms
01A 0E 0000 0010 ; Jump back to line 010 (loop)

; Mode Switch - Line 020
020 11 0030 0000 ; R00 = R30 (read current mode)
021 04 0000 0028 ; If R00 == 0, jump to line 028 (set to month-day mode)
022 10 0000 0030 ; R30 = 0 (set to year mode)
023 02 01F4 0000 ; Delay 500ms (debounce)
024 0E 0000 0010 ; Jump back to line 010

028 10 0001 0030 ; R30 = 1 (set to month-day mode)
029 02 01F4 0000 ; Delay 500ms (debounce)
02A 0E 0000 0010 ; Jump back to line 010

Detailed Explanation​

Initialization (Lines 000-002)​

Line 000: C7 0001 0000

  • Enable 7-segment display control
  • Required to use the 4-digit display

Line 001: 10 0000 0000

  • Initialize display to show "0000"
  • Sets the initial state

Line 002: 0E 0000 0010

  • Jump to main loop at line 010

Main Loop (Lines 010-01A)​

Line 010: 04 0001 0020

  • Conditional Jump: If button pressed (R01 > 0), jump to mode switch
  • Checks if the button has been pressed

Line 011: 11 0030 0000

  • Copy R30 (display mode register) to R00
  • R30 = 0 means year mode, R30 = 1 means month-day mode

Line 012: 04 0000 0018

  • Conditional Jump: If R00 == 0 (year mode), jump to line 018
  • Display month-day instead

Line 013: 10 2026 0000

  • Set display to show year "2026"
  • Value 2026 is displayed on 4-digit display

Line 014: 02 0064 0000

  • Delay 100ms
  • Maintains display stability

Line 015: 0E 0000 0010

  • Jump back to line 010 to continue loop

Line 018: 10 0131 0000

  • Set display to show month-day "0131"
  • Value 0131 represents January 31st

Line 019: 02 0064 0000

  • Delay 100ms
  • Maintains display stability

Line 01A: 0E 0000 0010

  • Jump back to line 010 to continue loop

Mode Switch (Lines 020-02A)​

Line 020: 11 0030 0000

  • Read current display mode from R30

Line 021: 04 0000 0028

  • Conditional Jump: If current mode is 0 (year mode), jump to set month-day mode

Line 022: 10 0000 0030

  • Set R30 = 0 (switch to year mode)

Line 023: 02 01F4 0000

  • Delay 500ms for button debounce
  • Prevents multiple triggers from single press

Line 024: 0E 0000 0010

  • Return to main loop

Line 028: 10 0001 0030

  • Set R30 = 1 (switch to month-day mode)

Line 029: 02 01F4 0000

  • Delay 500ms for button debounce

Line 02A: 0E 0000 0010

  • Return to main loop

Key Concepts​

1. 7-Segment Display Control​

The 4-digit 7-segment display can show values from 0000 to 9999. Use instruction 0x10 to set the display value.

2. Button Debouncing​

Buttons can bounce when pressed, causing multiple triggers. Use a 500ms delay after detecting a button press to ensure reliable operation.

3. State Management​

Use a register (R30) to store the current display mode:

  • R30 = 0: Year mode (display 2026)
  • R30 = 1: Month-day mode (display 0131)

Assessment Rubric​

CriteriaExcellent (5)Good (4)Satisfactory (3)Needs Improvement (2)
Circuit SetupAll components correctly connectedMinor connection errorsSome connections incorrectMajor wiring issues
Display FunctionDisplay shows correct values consistentlyMinor display errorsDisplay works but with issuesDisplay not working
Button ControlButton toggles modes reliablyButton works with minor issuesButton control inconsistentButton not functioning
Code QualityClean, well-structured codeGood code with minor issuesCode works but disorganizedCode doesn't work correctly
DebouncingEffective debouncing implementedMinor debounce issuesDebouncing partially worksNo debouncing implemented

Extension Challenges​

  1. Add Date Adjustment: Use multiple buttons to adjust year, month, and day values
  2. Auto-Cycle Mode: Automatically cycle between year and month-day every 5 seconds
  3. Add Time Display: Extend to show hours and minutes
  4. Leap Year Logic: Implement correct February days for leap years