Last active
December 23, 2015 21:19
-
-
Save dtudury/6695938 to your computer and use it in GitHub Desktop.
osx setup for atmega32u4 (with silly program to control 7-segment led)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 0) I have xcode installed everywhere, I'm not sure that's a dependency but... | |
// I'm not going to uninstall it to test the theory | |
// 1) download and install crosspack: http://www.obdev.at/products/crosspack/download.html | |
// (you may need to go into "security & privacy" and take osx out of nanny-mode) | |
// 2) with the controller unplugged open a console and type `ls /dev/tty.*` | |
// 3) plug it in and type `ls /dev/tty.*` again... make a note of the new device | |
// 4) `cd ~/Documents` | |
// 5) `avr-project 7-segment` | |
// 6) `cd 7-segment/firmware` | |
// 7) edit the Makefile | |
// change DEVICE to: atmega32u4 | |
// change CLOCK to: 8000000 | |
// change PROGRAMMER to: -c avr109 -P the-device-name-from-step-3 | |
// 8) edit main.c (maybe with the program below) | |
// 9) `make` | |
// 10) push the button on the controller to put it into boot mode (it should start to blink) | |
// 11) while it's blinking: `make flash` | |
#include <avr/io.h> | |
#include <util/delay.h> | |
#ifndef F_CPU | |
#define F_CPU 16000000UL // or whatever may be your frequency | |
#endif | |
static char segments[80] = { | |
0b00000001, 0b00000010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b10000000, | |
0b00000001, 0b00000000, 0b00000100, 0b00001000, 0b00000000, 0b00100000, 0b01000000, 0b00000000, | |
0b00000001, 0b00000010, 0b00000100, 0b00000000, 0b00000000, 0b00100000, 0b01000000, 0b10000000, | |
0b00000001, 0b00000010, 0b00000000, 0b00000000, 0b00010000, 0b00000000, 0b01000000, 0b00000000, | |
0b00000000, 0b00000010, 0b00000100, 0b00000000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, | |
0b00000000, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b00000000, | |
0b00000001, 0b00000010, 0b00000000, 0b00000000, 0b00000000, 0b00100000, 0b00000000, 0b10000000, | |
0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b00000000, | |
0b00000001, 0b00000010, 0b00000100, 0b00000000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, | |
0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b00000000, 0b00000000 | |
}; | |
int main(void) { | |
uint16_t i = 0; | |
uint16_t t = 0; | |
DDRD = 0b11111111; | |
for(;;){ | |
PORTD = segments[(i++ % 8) + t * 8]; | |
_delay_ms(1); | |
if(i > 1000) { | |
i = 0; | |
t = (t + 1) % 10; | |
} | |
} | |
return 0; /* never reached */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment