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.
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.
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.
- 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).
The TextArray table maps 4*row_button + column to ASCII. The default layout
follows a standard phone keypad (2→2 a b c, etc.). Verify against your
keypad's physical legend and edit the .DB rows if your hardware differs.
- New AVR Assembler Project, device ATmega32.
- Replace the
.asmwithlab7_timers_keypad.asm, setPART_SELECT. - Build and program via JTAGICE mkII.
- The original Part 2 lookup table produced impossible codes (e.g.
0x80for8,B). The table here yields correct ASCII; index math is unchanged. LookupCharnow carries the carry intoZH, so the table can safely cross a 256-byte flash boundary.- The SRAM
Messagebuffer 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.