Added starter example project.

This commit is contained in:
Andrew Lalis 2022-12-02 11:42:42 +01:00
parent 082a1f3cd1
commit 38cd2efb0a
5 changed files with 65 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
bin/

18
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "AVR",
"includePath": [
"${workspaceFolder}/**",
"/lib/avr/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/avr-gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-avr",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
all: clean build
clean:
rm -rf bin/
flash: build
avrdude -c arduino -p atmega328p -P /dev/ttyUSB0 -b115200 -U flash:w:bin/gympal.hex:i
build: gympal.hex
gympal.hex: src/gympal.c bin
avr-gcc -Wall -Os -DF_CPU=16000000UL -mmcu=atmega328p -c src/gympal.c -o bin/gympal.o
avr-gcc -Os -mmcu=atmega328p -o bin/gympal.elf bin/gympal.o
avr-objcopy -O ihex -R .eeprom bin/gympal.elf bin/gympal.hex
bin:
mkdir bin

View File

@ -1,2 +1,16 @@
# GymPal
A simple device for recording gym sessions, using AVR.
## Development
The software for this system is developed in C, using [avr-libc](https://www.nongnu.org/avr-libc/), and the build toolchain is managed by make, using [avr-gcc](https://linux.die.net/man/1/avr-gcc) and [avr-dude](https://github.com/avrdudes/avrdude) to upload firmware to the Atmega328p microcontroller.
To compile the firmware, you can run `make`.
To upload the firmware to an Arduino, run `make flash`.
### Helpful Links
The following links are helpful for learning how to program an AVR-based microcontroller.
- [avr-libc Homepage](https://www.nongnu.org/avr-libc/)
- [avr-libc Library Reference](https://www.nongnu.org/avr-libc/user-manual/modules.html)
- [avrdude Firmware Uploader](https://github.com/avrdudes/avrdude)

15
src/gympal.c Normal file
View File

@ -0,0 +1,15 @@
#include <avr/io.h>
#include <util/delay.h>
int main() {
// Pin 12 == Port B4, aka 4th bit on the B register.
// Set pin 12 as output.
DDRB = 1 << PORTB4;
// Set pin 12 as HIGH.
PORTB = 1 << PORTB4;
// Delay for 1 second.
_delay_ms(1000.0);
// Set pin 12 as LOW.
PORTB = 0 << PORTB4;
return 0;
}