This program explains hello world LED blinking program.In this program an LED is connected through a resistor to PINB0.
#include <avr/io.h> #include <avr/delay.h> int main() { DDRB |= 1<<PINB0; while(1) { PORTB |= 1<<PINB0; _delay_ms(100); PORTB &= ~(1<<PINB0); _delay_ms(100); } }
The above program makes PINB0 blink with 100ms delay.
Compile and upload the hex file.You can use the blow make file for the whole process
CC = avr-gcc OBJCOPY = avr-objcopy OBJDUMP = avr-objdump AVRDUDE = avrdude REMOVE = rm -f MCU =atmega8 TARGET = blink SRC = $(TARGET).c AVRDUDE_PROGRAMMER = dapa AVRDUDE_PORT = /dev/parport0 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex elf: $(CC) -mmcu=$(MCU) -Os -o $(TARGET).elf $(SRC) hex: $(OBJCOPY) -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex flash: $(AVRDUDE) -p m8 -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) $(AVRDUDE_WRITE_FLASH) clean: $(REMOVE) $(TARGET).hex $(TARGET).elf $(TARGET).c~
When your program name changes change name of the TARGET variable in Makefile.
Use the commands in sequence
make elf make hex make flash
HelloWorld in action
Happy Hacking 🙂