Created
February 23, 2016 04:56
-
-
Save owskio/d506bc94fd54875f9fcc to your computer and use it in GitHub Desktop.
Working with atmega16a-pu and the blue atmel 6 pin isp (the $35-$50 one) on ubuntu
This file contains 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
//avr-gcc -Wall blink.c -mmcu=atmega16 -DF_CPU=1000000UL -o blink.o | |
//sudo avr-objcopy -O ihex -R .eeprom blink.o blink.hex | |
//sudo chmod a+rw /dev/ttyS0 #not sure if this matters | |
//sudo avrdude -p atmega16 -c avrisp2 -U flash:w:blink.hex | |
#include <avr/io.h> | |
// define what pins the LEDs are connected to. | |
// in reality, PD6 is really just '6' | |
#define LED PA0 | |
// Some macros that make the code more readable | |
#define output_low(port,pin) port &= ~(1<<pin) | |
#define output_high(port,pin) port |= (1<<pin) | |
#define set_input(portdir,pin) portdir &= ~(1<<pin) | |
#define set_output(portdir,pin) portdir |= (1<<pin) | |
// this is just a program that 'kills time' in a calibrated method | |
void delay_ms(uint8_t ms) { | |
uint16_t delay_count = F_CPU / 17500; | |
volatile uint16_t i; | |
while (ms != 0) { | |
for (i=0; i != delay_count; i++); | |
ms--; | |
} | |
} | |
int main(void) { | |
// initialize the direction of PORTD #6 to be an output | |
set_output(DDRA, LED); | |
while (1) { | |
// turn on the LED for 200ms | |
output_high(PORTA, LED); | |
delay_ms(200); | |
// now turn off the LED for another 200ms | |
output_low(PORTA, LED); | |
delay_ms(200); | |
// now start over | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment