Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1.38 KB

README.md

File metadata and controls

37 lines (25 loc) · 1.38 KB

microzig-avr-example

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.

Prerequisites

Before running this example, ensure you have the following:

Hardware Setup

  • Connect an LED to pin PA1 pin.
  • Connect UPDI compatible programmer to PA0 pin. You could use TinyUPDI device.

Code Explanation

  1. Import the necessary microzig module and retrieve the peripherals for the chip.

  2. 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.

  3. 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.

Building and Running

git submodule update --init --recursive
cd fw
make PORT=/dev/ttyUSB0 flash