atmega168 and rtc 32768 crystal

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

Again I have no luck with 32khz crystal and timer2
In ohter post in this forum I have try with mega8 and many friends help me with some instruction so finaly i have no erros on complier but the project didnt run.
Because for my project I will need more power μc I choose mega168 and start again the first step to make an overflow every second with 32khz crystal
I work with stk500,I have connect the crystal to expand1 connector on pin portb6,portb7
The jumpers on stk are all by default.
I program fuses 8mhz internal on studio.
And flash with this program, who in my dreams :) ,it will flash the leds on stk500 who is connected to portd.
What is complete wrong?

.INCLUDE "m168def.inc"


.ORG $0000
.def TMP1 = R22 
.def TMP2 = R23 
.DEF COUNTER = R24
RJMP RESET
rjmp TIM2_OVF


RESET:
	   ldi r16, high(RAMEND); Main program start
        out SPH,r16 ; Set Stack Pointer to top of RAM
        ldi r16, low(RAMEND)
        out SPL,r16
		
		LDI R17,0B11111111
		OUT DDRD,R17
		LDI R17,255
		OUT PORTD,R17
		LDI COUNTER,10
		RCALL LDELAY
	     
        LDS R0,5
		STS TCCR2B,R0
		RCALL BUSY
	
		CLR R0
		STS TCCR2A,R0
		RCALL BUSY
		LDS R0,0
	
		STS TCNT2,R0
		RCALL BUSY


		LDS R0,1
		STS TIMSK2,R0

		CLR R0
		STS TIFR2,R0

	    LDS R0,0B00100000
	    STS ASSR,R0

		RCALL LDELAY
		
	
		

		SEI

		
		




START:
RJMP START



TIM2_OVF:


push r16
in r16,SREG
push r16

DEC COUNTER
BRNE EXIT
LDI TMP1,0
OUT PORTD,TMP1
RCALL LDELAY
EXIT:
pop r16
out SREG,r16
pop r16

reti


BUSY:
CLR R0
LDS R0,ASSR
SBRC R0,5
brne BUSY
ret



LDELAY:

		LDI R25,2
D1:
		LDI R26,2
D2: 
		DEC R26
		BRNE D2
		DEC R25
		BRNE D1
		RET
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I work with stk500,I have connect the crystal to expand1 connector on pin portb6,portb7

On the STK500 the PB6 and PB7 pins are not connected to 28 pin chips. Those signals appear on the PORTE header marked X1 and X2.

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

datasheet of mega168 note pb6,pb7 as tosc1,tosc2 and according the stk500 manual this pins are on expand1.
You mean that the correct pins are 17,18 on expand1?
I will try it
The code have any errors?

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

Quote:

.ORG $0000
.def TMP1 = R22
.def TMP2 = R23
.DEF COUNTER = R24
RJMP RESET
rjmp TIM2_OVF


Surely you meant something like

.def TMP1 = R22
.def TMP2 = R23
.DEF COUNTER = R24

.CSEG
.ORG 0x0000
	RJMP RESET
.ORG OVF2addr
	rjmp TIM2_OVF
...	

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
Quote:

.ORG $0000
.def TMP1 = R22
.def TMP2 = R23
.DEF COUNTER = R24
RJMP RESET
rjmp TIM2_OVF


Surely you meant something like

.def TMP1 = R22
.def TMP2 = R23
.DEF COUNTER = R24

.CSEG
.ORG 0x0000
	RJMP RESET
.ORG OVF2addr
	rjmp TIM2_OVF
...	

Yes this is correct

The busy routine is ok? or is endless loop?do you preffer something better?

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

Ok i change the code and the crystal on expand1 connector and again nothing :(