Posts

Showing posts from July, 2014

Arduino pure c programming part2 push button

/* Toggle a on-board led if push button is pressed */ #include <avr/io.h> void init_io() { DDRB |= 1<<PB5; //Setting the pin as output DDRD &= ~(1<<PD2); //Setting the pin as input } int is_button_pressed() { return (PIND&(1<<PD2)) ; } void toggle_led() { PORTB ^= 1<<PB5; } int main() { init_io(); while(1){ if(is_button_pressed()) toggle_led(); } return 0; }

Arduino pure C programming part1 Blinking On-Board Led

Code: /* Program to blink the on-board led */ #include <avr/io.h> #include <util/delay.h> int main(void){ DDRB |= (1 << PB5); while(1) { PORTB ^= (1 << PB5); _delay_ms(2000); } } Commands avr-gcc -mmcu=atmega328p -Wall -Os -o blink.elf blink.c  -DF_CPU=16000000UL avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex sudo avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:blink.hex