MicroZig Atmel AVR example
This example demonstrates how to use interrupts in Zig to create a program that blinks an LED connected to the PA1 pin of the ATtiny412 microcontroller. The LED blinking frequency is controlled by an interrupt generated by the TCA0 timer.
Before running this example, ensure you have the following:
- Zig compiler installed.
- ATtiny412 microcontroller datasheet for reference.
- Connect an LED to pin PA1 pin.
- Connect UPDI compatible programmer to PA0 pin. You could use TinyUPDI device.
-
Import the necessary
microzig
module and retrieve theperipherals
for the chip. -
Define the interrupt handler for the
TCA0_LUNF
interrupt. This handler toggles the state of the LED connected to PA1 and clears the overflow interrupt flag. -
Define the
main
function:- Configure the CPU to run at 10MHz.
- Enable interrupts.
- Set PA1 as an output.
- Configure the TCA0 timer to generate interrupts.
- Enter an idle sleep mode while waiting for interrupts.
git submodule update --init --recursive
cd fw
make PORT=/dev/ttyUSB0 flash