Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
// Frequency number needed by the delay function.// The chip is factory set to run on internal// oscillator at 1 MHz so the value is 1000000UL#define F_CPU 1000000UL#include <avr/io.h>#include <util/delay.h>// Number of frames in the animation#define FRAMES 8 // The animation sequence array.// All the values are in binary for easy// reading (1 = LED on / 0 = LED off)// The rightmost bit is PB0 and the leftmost// bit after '0b' is PB4.// -> 0b[4][3][2][1][0]char animation[FRAMES] ={ 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010};int main(void){ DDRB = 0x1F; // PB0-PB4 output PORTB = 0x00; // Set all pins low int i; while(1) { // Loop through all the frames in the animation for(i=0 ; i<FRAMES ; i++) { // Write the value from the array to the port PORTB = animation[i]; // Wait 100 ms before going to the next frame _delay_ms(100); } } return 0;}
################################################################################ Makefile for the project LED_blinking################################################################################# General FlagsPROJECT = LED_blinkingMCU = atmega168TARGET = LED_blinking.elfCC = avr-gcc.exe## Options common to compile, link and assembly rulesCOMMON = -mmcu=$(MCU)## Compile options common for all C compilation units.CFLAGS = $(COMMON)CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=16000000UL -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsCFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d ## Assembly specific flagsASMFLAGS = $(COMMON)ASMFLAGS += $(CFLAGS)ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2## Linker flagsLDFLAGS = $(COMMON)LDFLAGS += -Wl,-Map=LED_blinking.map## Intel Hex file production flagsHEX_FLASH_FLAGS = -R .eepromHEX_EEPROM_FLAGS = -j .eepromHEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings## Objects that must be built in order to linkOBJECTS = LED_blinking.o ## Objects explicitly added by the userLINKONLYOBJECTS = ## Buildall: $(TARGET) LED_blinking.hex LED_blinking.eep LED_blinking.lss size## CompileLED_blinking.o: ../LED_blinking.c $(CC) $(INCLUDES) $(CFLAGS) -c $<##Link$(TARGET): $(OBJECTS) $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)%.hex: $(TARGET) avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@%.eep: $(TARGET) -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0%.lss: $(TARGET) avr-objdump -h -S $< > $@size: ${TARGET} @echo @avr-size -C --mcu=${MCU} ${TARGET}## Clean target.PHONY: cleanclean: -rm -rf $(OBJECTS) LED_blinking.elf dep/* LED_blinking.hex LED_blinking.eep LED_blinking.lss LED_blinking.map## Other dependencies-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
ok good and bad newsgood: I got it to build and compile a .hex file.bad: all the board does is light up all 5 LEDS at the same time
// Frequency number needed by the delay function.// The chip is factory set to run on internal// oscillator at 1 MHz so the value is 1000000UL#define F_CPU 1000000UL#include <avr/io.h>#include <util/delay.h>// Number of frames in the animation#define FRAMES 8 // The animation sequence array.// All the values are in binary for easy// reading (1 = LED on / 0 = LED off)// The rightmost bit is PB0 and the leftmost// bit after '0b' is PB4.// -> 0b[4][3][2][1][0]char animation[FRAMES] ={ 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010};int main(void){ DDRD = 0x1F; // PB0-PB4 output PORTD = 0x00; // Set all pins low int i; while(1) { // Loop through all the frames in the animation for(i=0 ; i<FRAMES ; i++) { // Write the value from the array to the port PORTD = animation[i]; // Wait 100 ms before going to the next frame _delay_ms(100); } } return 0;}
char animation[FRAMES] ={ 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010};
char animation[FRAMES] ={ 0d00001, 0d00010, 0d00100, 0d01000, 0d10000, 0d01000, 0d00100, 0d00010};
hmm... I think you should change this:Code:char animation[FRAMES] ={ 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010};to this:Code:char animation[FRAMES] ={ 0d00001, 0d00010, 0d00100, 0d01000, 0d10000, 0d01000, 0d00100, 0d00010};But I could be wrong....