Problems clearing registers

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Having issues clearing registers on boot. The code I have was running just fine on a Tiny11, but after porting to the Mega8 these random numbers are showing up in my variables. The application is really small so the registers are all SRAM required. To port the app I just added the Stack init stuff.

.org 0x0000
Rvect:	rjmp	Reset

Reset:
	bclr 7						;Disable Interrupts (poll everything)
	ldi r16,high(RAMEND)
	out spH,r16
	ldi r16,low(RAMEND)
	out spl,r16
	
	rcall Delay

	in temp,MCUCR
	ori temp,0x40 
	out MCUCR,temp
	ldi temp,0x3				;Init Timer/Counter clk/64
	out TCCR0,temp

	ldi temp,0x00			
	out PORTB,temp				;Clear PortB
	out DDRB,temp				;Set pins to input

	ldi temp,0xFF				;Chip Reset High, Chip Select High, others low
	out DDRD,temp				;Set pins to input

ClearMem:						;Quick and dirty clearmem
	clr r0
	clr r30
ClearLoop:
	inc r30
	st  Z,r0
	tst r30
	brne ClearLoop
	ldi r31,0

Once the app is up and running r4,5,6,7 end up with some random numbers in them. Hard to see how given the ClearMem..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you mean to put

	ldi r31,0

at the end of ClearMem rather than the beginning?

-John

- John

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

further to the last response - The Z register is R30,31 (16 bits) - but you don't load the hi part of this (r31) so it has a random value. The mega8 most likely pays attention to this whereas the tiny may not - thus explaining the difference. So put the ldi r31,0 up the top of your code!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It might also help to clear the first 256 bytes and then initialize the control registers.

-John

- John