Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active May 23, 2020 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cellularmitosis/3f74b60edfbad8cc9c36a654db13cb87 to your computer and use it in GitHub Desktop.
Save cellularmitosis/3f74b60edfbad8cc9c36a654db13cb87 to your computer and use it in GitHub Desktop.

Outline for "Intro to C using Atmel/Arduino"

Lesson 1:

Requirements:

  • 1 Arduino Uno (with ATmega328p).
  • brew install avr-gcc avrdude

  • Warm-up: write the blink program for Arduino.
  • Now write it using C, avr-gcc and avrdude.
  • Turn it into a benchmark: blink 1,000,000 times and then spin.
  • Compare the time to 1,000,000 blinks for Arduino vs C.

Resources:

For the Arduino sketch:

  • use pinMode() and digitalWrite().
blink.hex: blink.elf
avr-objcopy -O ihex blink.elf blink.hex
blink.elf: blink.o
avr-gcc -DF_CPU=16000000 -mmcu=atmega328 -o blink.elf blink.o
blink.o: blink.c
avr-gcc -DF_CPU=16000000 -mmcu=atmega328 -o blink.o -c blink.c
flash: blink.hex
avrdude -c arduino -p atmega328p -P /dev/tty.wchusbserial1420 -U flash:w:blink.hex
clean:
rm -f blink.o blink.elf blink.hex
.PHONY: flash clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment