So far I have only worked with ATmega32 chips, programming them in C. Now I have to work with an ATTINY12, which can only be programmed in ASM.
As a proof of concept, I wrote a simple program that turns on a LED on PB0. I can compile the code and flash the microcontroller successfully, but the LED does not turn on.
I verified that the circuit works as intended and I tried 2 different microcontroller to rule out a hardware issue. It looks like I am misunderstanding something in the source code I have assembled based on a couple of tutorials I've found.
#include <avr/io.h>
.org 0x00
.global main
main:
ldi R16,0b00000001
out DDRB,R16 // Set PB0 as output pin
ldi R16,0b00000001
out PORTB,R16 // Set PB0 to high
loop:
rjmp loop // loop forever
.end
I compiled the source with Microchip Studio and flashed the chip with AVRDUDE. I also added LEDs to PB1-PB5 for debugging, but none of them showed any sign of life.
The program seems so simple and straightforward. What am I missing?
Edit: After a couple of very helpful comments, I found another weird behavior. When I try to set a single bit on PORTB using sbi PORTB, 1
, which should set PB0 to high, the compiler throws an error operand out of range: 56
. This does not make sense, because PORTB is supposed to have 6 bits (0-63). This indicates to me, that my main problem lies in the way I use PORTB in my code.
The same applies to sbi DDRB, 1
, only that the compile error reads operand out of range: 55
.