|
/* |
|
Compiling and uploading to Arduino Uno (Sample Code 2) |
|
====================================================== |
|
|
|
avr-gcc -Os -mmcu=atmega328p -c test.c |
|
avr-gcc -mmcu=atmega328p -o test.elf test.o |
|
avr-objcopy -O ihex -R .eeprom test.elf test.hex |
|
avrdude -F -V -c arduino -p ATMEGA328P -P /dev/cu.usbmodem1421 -b 115200 -U flash:w:test.hex |
|
|
|
*/ |
|
#ifndef F_CPU |
|
#define F_CPU 16000000UL //set frequency |
|
#endif |
|
|
|
#include <avr/io.h> |
|
#include <util/delay.h> |
|
|
|
#define MS_DELAY 2000 //2 seconds |
|
|
|
int main() { |
|
DDRB |= _BV(DDB1); //set pin 9 to output |
|
DDRB |= _BV(DDB0); //set pin 8 to output |
|
|
|
for(;;) { |
|
PORTB |= _BV(PORTB1); //set pin 9 to high |
|
PORTB &= ~_BV(PORTB0); //set pin 8 to low |
|
_delay_ms(MS_DELAY); //delay |
|
|
|
PORTB &= ~_BV(PORTB1); //set pin 9 to low |
|
PORTB |= _BV(PORTB0); //set pin 8 to high |
|
_delay_ms(MS_DELAY); //delay |
|
} |
|
|
|
return 0; |
|
} |