Created
April 22, 2018 01:08
-
-
Save six519/2d47345c07ed4b4c8a811e5e92ab7da3 to your computer and use it in GitHub Desktop.
Pure C Language In Arduino Uno (Sample Code 2)
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
/* | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment