Skip to content

zaccesss/avr-zac

Repository files navigation


🔎 Quick navigation: OverviewHardwareGetting StartedProjectsState MachineDocsAcknowledgements


Overview

A personal project to learn bare metal AVR C development, writing directly to hardware registers without any framework or abstraction layer. The ATmega644P runs at 20 MHz on a custom PCB designed by Richard Reeves with an external crystal, LM317T voltage regulator and 10-way headers breaking out all 32 I/O pins.

Projects progress from a basic LED blink through GPIO manipulation, button polling, interrupt-driven input, software PWM and ADC, building towards a full nine-mode state machine that includes a reaction game and a Tetris melody synced to LEDs. All code targets the ATmega644P and can be built with either PlatformIO in VS Code or Microchip Studio 7. See WORKFLOW.md for the full setup and flash guide.

C Embedded C PlatformIO VS Code Microchip Studio Git GitHub

Hardware

Item Detail
MCU ATmega644P DIP-40, 20 MHz external crystal
PCB Richard Reeves AVR Project PCB 2019 with LM317T regulator
Programmer Pololu USB AVR Programmer v2.1 via STK500v2 on COM4

The breadboard components (LEDs, button, buzzer) are a temporary configuration used for learning and change between sessions. See docs/wiring.md for the current breadboard connections and header pin assignments. Full PCB component list, connector pinout and power supply circuit are in hardware/pcb_notes.md.


Getting Started

  1. Clone the repo and choose an IDE: VS Code with PlatformIO or Microchip Studio 7.
  2. Follow the full setup guide in WORKFLOW.md. It covers prerequisites, environment switching, build tasks and flash commands.
  3. Connect the Pololu programmer to the ISP header (J1) on the PCB and to a USB port (COM4).
  4. Select a project from the Projects table below and build.

Manual flash command if needed:

C:\avrdude\avrdude.exe -c stk500v2 -p m644p -P COM4 -B 10 -V -U flash:w:<project>.hex:i

The -B 10 flag slows the ISP clock to ~50 kHz, which is required to avoid timeout errors with the Pololu programmer. See WORKFLOW.md for the full flag reference and troubleshooting steps.


Projects

# File Description Key Concepts
0 00_fuse_test.c Fuse configuration and restoration reference Fuse bits, clock source, avrdude -F flag
1 01_blink.c Double blink on PB0 DDRB, PORTB, _delay_ms
2 02_led_cycle.c Five LEDs cycling sequentially Multi-pin output, bit shifting
3 03_button_polling.c Button drives buzzer via polling PIND, input reading, active buzzer
4 04_interrupt_buzzer.c Button drives buzzer via INT0 ISR, EICRA, EIMSK, sei()
5 05_state_machine_basic.c Four-mode state machine (initial build) enum, ISR, debounce, switch
6 06_state_machine.c Nine-mode state machine (full build) PWM, ADC, reaction game, Tetris melody

Source files live in projects/learning_projects/ (one folder per project). The active project is also copied into platformio/src/ for building. See WORKFLOW.md for how to switch between projects.


State Machine Modes

06_state_machine.c cycles through nine modes on each button press. Mode state is held in a volatile variable updated inside an INT0 ISR with software debounce.

Mode Name Description
0 Chase LEDs light one by one in sequence
1 Blink All All five LEDs blink together
2 Alternate Odd and even LEDs alternate
3 PWM Fade All LEDs fade in and out via software PWM
4 Knight Rider Single LED sweeps left to right and back
5 Binary Counter LEDs count 0 to 31 in binary
6 Random LEDs display random patterns seeded by ADC noise
7 Reaction Game Press button when green LED lights to win
8 Tetris Melody Tetris theme plays with LEDs synced to each note

Documentation Hub

Document Description
Build and Flash Workflow Full VS Code/PlatformIO and Microchip Studio setup, environment switching, build tasks and troubleshooting
Wiring Reference Current breadboard connections and header pin tables
Hardware Notes Fuse settings, ISP clock speed, register map and ADC configuration
PCB Full Reference Component list, connector pinout, power supply circuit and soldering order
PCB Schematic PDF Original PCB schematic and layout PDF for the Richard Reeves AVR Project PCB 2019
ATmega644P Datasheet Official Microchip datasheet for the ATmega644P
C Operators Reference PDF Printable C operator reference card

Session Notes

Each session has a notes.md (reference) and a lab.md (hands-on tasks).

Session Topic Notes Lab
1 Introduction to AVR C notes lab
2 Bit Shifting, Arrays and Data Types notes lab
3 Inputs, Bit Masking and Interrupts notes lab
4 Timers: Overflow and Output Compare notes lab
5 Hardware PWM notes lab
6 UART Serial Transmission notes lab
7 Analogue to Digital Conversion notes lab
8 UART Serial Reception notes lab

General Reference

Document Description
C Operators Reference Arithmetic, bitwise, relational and assignment operator tables with AVR examples and precedence table
Hardware Reference PCB overview, power supply, headers (J1 to J7), crystal, fuse summary and component list


Acknowledgements

Richard Reeves, lab technician at Aston University, designed the AVR Project PCB and provided components and guidance.


Contact and Support

Open an issue in this repository for questions or bugs.

You can also reach me directly at eng@isaacadjei.me or via my website contact page.

About

ATmega644P embedded C projects, bare metal AVR microcontroller development using Microchip Studio and PlatformIO. Includes state machines, interrupts, PWM, ADC and more!

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages