Your board gets its brain. You plug in the ATmega4809 microcontroller, solder the piezo buzzer, and write your first program in assembly language, the language of the chip itself. The first version toggles the buzzer pin so fast you can’t hear it. Adding delay loops slows it to about 440 Hz, a note you can hear. Then you prepare the surface-mount LEDs for next week.
This is a simulator of the ATmega4809 running the exact code from the handout. The processor reads one instruction, does it, adds its clock cycles to the total, and moves the program counter to the next line. Watch the registers r16 and r17, the Z (zero) flag, and pin PF6, which drives the buzzer test point BUZ. Step through slowly first, then run fast and look at the scope.
The loop is only 5 instructions: ldi, out, ldi, out (1 cycle each) and rjmp (2 cycles) = 6 cycles per wave. At 3.33 MHz that is about 556 kHz, far above the 20 kHz limit of hearing. The scope on BUZ shows it; your ears can’t.
Each pass through bent: spends 12 nops + dec + brne. Starting r17 at 255 makes 255 passes, about 3824 cycles. Doing that once with the pin high and once with it low makes one wave of 7656 cycles: about 435 Hz, close to concert A (440 Hz).
DEC subtracts 1 and sets the zero flag only when the result is 0. BRNE (“branch if not equal”) jumps back while Z is clear and falls through once Z is set. (The pre-lab table words this backwards; the text below it is right.)
The pre-lab says 20 MHz, but the program never changes the clock settings, and the ATmega4809 starts up dividing 20 MHz by 6. Your measured frequency tells you which: 7656 cycles × 435 Hz ≈ 3.33 million cycles per second. That’s the first report question.
The chip only understands 16-bit numbers. LDI r24,165 is assembled into 1110 1010 1000 0101: 4 bits say “LDI”, 8 bits hold the constant (split in two), and 4 bits pick the register. Only 4 bits for the register is why LDI works with r16–r31 only. Pick a register and a constant:
Bit 0 is the rightmost (least significant), bit 7 the leftmost. There is no “out immediate”, so you always load a register with LDI first, then OUT it to the port.
Most instructions take 1 cycle. BRNE takes 2 when it jumps and 1 when it doesn’t; RJMP takes 2; a label takes none. For a loop that starts with ldi rX,N and has k one-cycle instructions plus dec and brne inside, the cycle count is below. Change N and k to design your own tone.
The two pads are not identical: the cathode (−) pad has little “horns”. The LED’s green (or black) mark is the cathode. Green mark → horned pad. On the solder side, with the board oriented as in the handout, the six horizontal LEDs point their green marks left, the two vertical ones up.
Mixed colours look alike when unlit. DMM Shift → Cont (diode test) lights the LED so you can see its colour; swap probes if it doesn’t light (it only conducts one way).
Six LEDs count seconds, one shows USB power, one shows the alarm is armed. Some colours don’t show through some acrylic covers, so check the demo board at the back of the lab first.
Step 30 asks you to break it on purpose (type lido instead of ldi). The Output box shows an error with a hyperlink; click it to jump to the line. Common real mistakes:
Then measure BUZ (right edge of the board; PF6, chip pin 29) with the scope, ground clip on the GND loop.
Try each one before opening the answer. These are not the real assignment questions; they use the same ideas with different numbers.