- Wed Mar 01, 2006 8:15 pm
#10564
Predictably, I'm having trouble with my first AVR application (on an atmega128). Basically, I want to "walk" across 8 LEDs, lighting each one up in sequence (1-8 ), then back down again (8-1), forever. Only one LED should be lit up at a time. I've written both an assembler, and a C (AVR-GCC) version of the code, and neither one works.
details:
1) I have LEDs on each pin of PORTB.
2) PORTB is configured as all output (ie: DDRB=0xFF).
3) the other end of each LCD is connected to VCC (pin 21 of the atmega128).
4) The following fuses are "set" (ie: "checked off" in PonyProg): CKOPT, BOOTSZ1, BOOTSZ0, SUT1, SUT0. (I admit, I'm a little confused when it comes to fuses, so there might be something wrong here.)
5) I'm using the Atmega128 header board from sparkfun, with external 16MHz oscillator on XTAL.
6) no bootloader installed.
7) Here's the C code:
details:
1) I have LEDs on each pin of PORTB.
2) PORTB is configured as all output (ie: DDRB=0xFF).
3) the other end of each LCD is connected to VCC (pin 21 of the atmega128).
4) The following fuses are "set" (ie: "checked off" in PonyProg): CKOPT, BOOTSZ1, BOOTSZ0, SUT1, SUT0. (I admit, I'm a little confused when it comes to fuses, so there might be something wrong here.)
5) I'm using the Atmega128 header board from sparkfun, with external 16MHz oscillator on XTAL.
6) no bootloader installed.
7) Here's the C code:
Code: Select all
Is there some obvious boneheaded thing I'm not thinking of?#define F_CPU 16000000UL //CPU-freq
#define DELAY_MS 100 //delay between LEDs
#include <util/delay.h>
#include <avr/io.h>
typedef unsigned char u08;
int main(void)
{
u08 temp=0xfe;
DDRB = 0xff;
PORTB=temp;
while(1){
//rotate left
while (temp & 0x80){ //while high-bit is not 0
temp=(temp << 1) | 0x01;
PORTB=temp;
_delay_ms(DELAY_MS); //wait
}
//rotate right
while (temp & 0x01){ //while lo-bit is not 0
temp=(temp >>1) | 0x80;
PORTB=temp;
_delay_ms(DELAY_MS); //wait
}
}
}