I just spent a few hours tracking a tricky rascal...My program is pretty simple reading & writing to ports A & B of a tiny26. I am also using the PWM & A/D & an ISR timer. All seemed to work well, after figuring out how to set up all the control bits. But Port PB4 was refusing to work 100% properly. Port A was just fine. Since PB4 is shared with other functions, such as external xtal & interupt on pin change, I looked to see if the pin had been "redefined".
one thing I noticed was that port A was being written "directly" -- that is different values are being directly written to port A, while port B used the IN function to read the port, then some processing was done on the value & it was spit back out.
After much messing around I realized that the processor was constantly being reset, so port B was being accidentally reinitialized. I looked at all sources of what might cause the reset. The rest pin itself showed no pulses on a scope. I tried putting in watchdog timer reset instructions here & there to no avail (tho I didn't think I had set up the WDT in the first place).
read the manual & of course it was no help either!
Then it dawned on me that the reinitialization seemed to be syncd up with my ISR timer (few hundred ms). Of course I had properly pushed and popped the status register in the ISR. THEN IT HIT ME....I never initialized the stack pointer!!! So somehow this was causing the problem (though I'm not sure what I was writing over).
The FIX :
ldi r16, RAMEND
out SP, r16 ; THAT'S IT--a few hours aggrevation saved for you
now, I could use a quick bit of help...what is the shortest code to toggle a bit on one port (say PA5)
is there anything shorter than the following????
in temp, porta
ldi temp2, $20
eor temp, temp2
out porta, temp