My Daily Gist | Ferdinand Silva


Pure C Language In Arduino Uno

 
/*
Compiling and uploading to Arduino Uno
======================================
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>
#include <compat/deprecated.h>
#define MS_DELAY 2000 //2 seconds
int main() {
DDRB = 0xFF; //all pins of PORT-B are output pins
for(;;) {
sbi(PORTB, PB1); //set pin 9 to high
cbi(PORTB, PB0); //set pin 8 to low
_delay_ms(MS_DELAY); //delay
cbi(PORTB, PB1); //set pin 9 to low
sbi(PORTB, PB0); //set pin 8 to high
_delay_ms(MS_DELAY); //delay
}
return 0;
}
view raw test.c hosted with ❤ by GitHub