Author Topic: ATMega8 program problem  (Read 5286 times)

0 Members and 1 Guest are viewing this topic.

Offline McFireTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
ATMega8 program problem
« on: December 16, 2009, 10:29:16 PM »
Hi,
I made the $50 robot controller board. I have 7 LED's connected to pins PD0 - 4 & 6 7. And I made a very simple program that turns one LED on at a time. I can program the ATmega168 without any problems. and the LED's do what they are supposed to do. But when I modify the makefile to work with the ATmega8 it looks as if the programming worked but the LED's wont activate. Im using avrdude & the AVRISP2 to burn the program on the chip. Could someone tell me what I can do to make It work?

I changed this make file:
Code: [Select]
DEVICE     = atmega168
CLOCK      = 8000000    # 8 MHz in Hz
PROGRAMMER = -c avrispmkII -P usb
FUSES      = -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m
OBJECTS    = main.o

# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all: main.hex

.c.o:
$(COMPILE) -c $< -o $@

.S.o:
$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
$(COMPILE) -S $< -o $@

flash: all
$(AVRDUDE) -U flash:w:main.hex:i

fuse:
$(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
bootloadHID main.hex

clean:
rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
$(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
rm -f main.hex
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm: main.elf
avr-objdump -d main.elf

cpp:
$(COMPILE) -E main.c
To this:
Code: [Select]
DEVICE     = atmega8
CLOCK      = 8000000    # 8 MHz in Hz
PROGRAMMER = -c avrispmkII -P usb
FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
OBJECTS    = main.o

# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all: main.hex

.c.o:
$(COMPILE) -c $< -o $@

.S.o:
$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
$(COMPILE) -S $< -o $@

flash: all
$(AVRDUDE) -U flash:w:main.hex:i

fuse:
$(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
bootloadHID main.hex

clean:
rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
$(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
rm -f main.hex
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm: main.elf
avr-objdump -d main.elf

cpp:
$(COMPILE) -E main.c
And I'm using this C code:
Code: [Select]
#include <avr/io.h>
#include <util/delay.h>


#define LED0 0xFE
#define LED1 0xFD
#define LED2 0xFB
#define LED3 0xF7
#define LED4 0xEF
#define LEDS 0x7F

#define xDelay 40 /* ms */
#define yDelay 200 /* ms */

void TestPattern();

int main (void)
{
/* set PORTD for output*/
DDRD = 0x9F;
PORTD = 0x00; // Set all pins low

TestPattern();

while (1) {

int x;
for ( x = 0; x < 10; x++ ) {

PORTD = LED2;
_delay_ms(xDelay);
PORTD = LED1 & LED3 & LEDS;
_delay_ms(xDelay);
PORTD = LED0 & LED4;
_delay_ms(xDelay);
PORTD = LED1 & LED3 & LEDS;
_delay_ms(xDelay);
PORTD = LED2;
_delay_ms(xDelay);
PORTD = LED1 & LED3 & LEDS;
_delay_ms(xDelay);
PORTD = LED0 & LED4;
_delay_ms(xDelay);
PORTD = LED1 & LED3 & LEDS;
_delay_ms(xDelay);

}

int y;
for ( y = 0; y < 10; y++ ) {

PORTD = LED2;
_delay_ms(xDelay);
PORTD = LED3 & LEDS;
_delay_ms(xDelay);
PORTD = LED4;
_delay_ms(xDelay);
PORTD = LED3 & LEDS;
_delay_ms(xDelay);
PORTD = LED2;
_delay_ms(xDelay);
PORTD = LED1 & LEDS;
_delay_ms(xDelay);
PORTD = LED0;
_delay_ms(xDelay);
PORTD = LED1 & LEDS;
_delay_ms(xDelay);

}

int z;
for ( z = 0; z < 10; z++ ) {

PORTD = LED3;
_delay_ms(xDelay);
PORTD = LED1 & LEDS;
_delay_ms(xDelay);
PORTD = LED4;
_delay_ms(xDelay);
PORTD = LED0 & LEDS;
_delay_ms(xDelay);
PORTD = LED4;
_delay_ms(xDelay);
PORTD = LED1 & LEDS;
_delay_ms(xDelay);
PORTD = LED3;
_delay_ms(xDelay);
PORTD = LED2 & LEDS;
_delay_ms(xDelay);

}

}
return 0;
}


void TestPattern()
{

PORTD = LED0;
_delay_ms(xDelay);
PORTD = LED1;
_delay_ms(xDelay);
PORTD = LED2;
_delay_ms(xDelay);
PORTD = LED3;
_delay_ms(xDelay);
PORTD = LED4;
_delay_ms(xDelay);
PORTD = LEDS;
_delay_ms(yDelay);
PORTD = 0x00;
_delay_ms(yDelay);

}


Offline McFireTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: ATMega8 program problem
« Reply #2 on: December 22, 2009, 05:50:06 PM »
Ok I disabled the brownout detection fuse and now I can program the ATmega8, and it works as its supposed to.
Thanks for replying.

 

SMF spam blocked by CleanTalk