Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Lab 7 — Timer0/Counter0, Keypad, ASCII Lookup & SRAM Messages

AVR assembly covering Timer0 in normal mode with a 1024 prescaler, 4×4 matrix keypad scanning, an ASCII multi-tap lookup table, and buffering a typed message in SRAM for timed playback.

Three parts in one file

Set PART_SELECT near the top of lab7_timers_keypad.asm to 1, 2, or 3 and rebuild. Only the selected part is assembled.

  • Part 1 — Timer0 normal mode, prescaler 1024, ~0.5 s tick rolling a single lit LED across PORTB.
  • Part 2 — Two keypresses select a character (multi-tap: first key = digit row, second key A–D = letter) shown on the LEDs via a flash lookup table.
  • Part 3 — Buffers characters in SRAM until #, then plays the whole message back on the LEDs. INT0 lengthens the inter-character delay (up to 5 s), INT1 shortens it (down to 0.5 s), live during playback.

Timer math (0.5 s @ 1 MHz, prescaler 1024)

t_tick  = 1024 / 1e6        = 1.024 ms / count
counts  = 0.5 s / 1.024 ms  = 488   -> two overflow passes of 244 counts
TCNT0 preload = 256 - 244   = 12

R23 holds the overflow-pair count (default 2 = 0.5 s). Each INT0/INT1 press adjusts it by ±2 pairs = ±0.5 s.

Hardware / wiring (STK500)

  • PORTB → LEDs (ribbon cable)
  • Keypad → PORTA: PA4–PA7 = rows (outputs), PA0–PA3 = columns (inputs, pulled up). See the keypad pin diagram (Reference 2 in the lab handout).
  • Part 3 only: INT0 → SW0 (PD2), INT1 → SW1 (PD3).

Keypad layout (multi-tap)

The TextArray table maps 4*row_button + column to ASCII. The default layout follows a standard phone keypad (22 a b c, etc.). Verify against your keypad's physical legend and edit the .DB rows if your hardware differs.

Build (Microchip Studio)

  1. New AVR Assembler Project, device ATmega32.
  2. Replace the .asm with lab7_timers_keypad.asm, set PART_SELECT.
  3. Build and program via JTAGICE mkII.

Changes from the original report

  • The original Part 2 lookup table produced impossible codes (e.g. 0x80 for 8,B). The table here yields correct ASCII; index math is unchanged.
  • LookupChar now carries the carry into ZH, so the table can safely cross a 256-byte flash boundary.
  • The SRAM Message buffer is sized to 64 bytes and the element counter is reset after each playback so consecutive messages work.
  • Symbolic bit names (TOV0, INT0, INT1) used instead of magic numbers.