All Projects → swharden → AVR-projects

swharden / AVR-projects

Licence: MIT license
A collection of standalone AVR projects written in C

Programming Languages

c
50402 projects - #5 most used programming language
python
139335 projects - #7 most used programming language
C#
18002 projects
Batchfile
5799 projects
AGS Script
88 projects

AVR-projects

This repository contains a growing collection of individual AVR project files for various tasks. I personally use these projects as starting points for new microcontroller projects, or reference for common procedudures I would otherwise have to go back to the datasheet for (timers, counters, frequency counting or synthesis, interrupts, UART, I2C, ADC, etc). Each folder is self-contained and has batch scripts to set fuses to change the clock source (internal RC oscillator at 8MHz, div/8 for 1MHz, or external crystal typically up to 20 MHz)

These are some of my favorites:

Programming Setup

I almost always use AVRISPmkII and AVRdude (launched from a batch script) to program my chips. I virtually never use AVRStudio. I typically develop in a Windows environment, but the code (and AVRdude) works the same in Linux.

Software

  • Just install WinAVR and it should install drivers for common programmers.
  • I prefer to edit C code in Notepad++
  • definately check out AVRDudess (a GUI for AVRdude) as an easy GUI to load flash onto chips

Hardware

Programmers

Note Picture
AVRISPmkII is a ceap, fast, and convenient AVR programmer. AVRISPmkII
Bus Pirate technically can program AVRs, but it's so slow it's not practical. Here's a post I wrote about it. I like the bus pirate when I need to use software to measure voltages and toggle pins. It's slow though, because the handshake it bit-banged and it takes tens of seconds to program an AVR. For just programming, I prefer an (ebay knockoff) AVR ISP mkII. Definately check out AVRDudess as a GUI for AVRDude. I usually get a standard command for a project and put it in a batch file in the same folder.
AVRDudess can simplify programming of code and fuses. avrdudess

Common AVR Datasheets and Pinouts

chip pinout datasheets
ATMega328 [summary] [complete]
ATTiny2313 [summary] [complete]
ATTiny45 [summary] [complete]

Helpful Links

Misc Code

Reading pins

if(PIND&(1<<PD7)){doSomething();} // runs doSomething() if PD7 is HIGH

Bit flipping in C

PORTD|=(1<<PD6); // sets PD6 high
PORTD&=~(1<<PD6); // sets PD6 low
PORTD^=(1<<PD6); // flips the state of PD6

Memory-Efficient Timers

#include <util/delay.h>
void waitMs1(){_delay_ms(1);}
void waitMs(int ms){while (ms-->0){waitMs1();}}
void waitSec(int sec){while (sec-->0){waitMs(1000);}}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].