I'm very new to programming AVR in assembler and my initial experiments have left me kind of confused. I've some some searching here and through google, but haven't been able to figure out what I've missed or done incorrectly.
First, the setup: I'm using an ATTiny25, programming with an adafruit usbtiny, and using the gcc toolchain since I'm using a mac. (So, I write some assembly.S, compile it with avr-gcc, extract a hex from the .o with avr-objcopy, and upload with avrdude.)
Now, the problem: this is pretty much a skeleton program that should toggle all output pins on and off with a nice, 50% duty cycle. But that's not what happens. Instead, the pins go high for about 5 microseconds, then stay low for about 120 microseconds (as eyeballed on my oscilloscope). Whaaaat?
Here's the code in its entirety:
.arch attiny25 #define __SFR_OFFSET 0 #include
#define mp r16 0: rjmp reset ;reset vector rjmp reset ;1 rjmp reset rjmp reset rjmp reset rjmp reset rjmp reset rjmp reset rjmp reset rjmp reset ;9 reset: ldi mp, RAMEND out _SFR_IO_ADDR(SPL),mp ldi mp, 0x3F out DDRB, mp ; all ports output out PORTB, mp ; all pins on loop: ldi mp,0x3F out PINB,mp rjmp loop
The fuse bits are all left at default, except I turned the clock/8 fuse off to see if it had any effect. (It did; everything sped up. Before the pins were going high for about 40us and staying low for almost 1ms).
If I comment out the #include and instead use register offsets for SPL/DDRB/PORTB/PINB directly from the datasheet, the behavior is the same, so that doesn't seem to be it.
I doubt it's a circuit thing, but for the sake of completeness: there is an LED +330ohm resistor attached to PB0, a .1uf cap decoupling Vcc to gnd, reset is held to +Vcc, and the power supply is a (supposedly) nice and even 3.3v from a sparkfun regulator kit.
If I change the main loop so that it reads like this:
loop: ldi mp,0x3F out PORTB, mp forever: rjmp forever
...the pins go high like they're supposed to and stay that way forever.
So what's wrong with the first code block? Any feedback MOST welcome.