Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Getting TMR0 to work

Status
Not open for further replies.

Thorpydo

New Member
Hey,

I can't seem to get TMR0 to work. This is just a program I'm playing around with it, trying to get it to work.
Code:
	org	0x00
	goto program
	org 0x04
	bcf		INTCON,2
	goto  skip
program
	bsf		STATUS, RP0			;changes banks
	movlw	b'00001111'			;0-4inputs 5,6outputs
	movwf	TRISIO				;setting input/output (1=input)

	bcf		STATUS, RP0			;changes banks 
	
	movlw .7 					;turns off comparators
	movwf CMCON					;turns off comparators

	movlw	b'00000000'			;setting high/low (1=high)
	movwf	GPIO				;setting high/low (1=high)

	bsf		GPIO,4
	bsf		GPIO,5

	bsf		INTCON,7			;enables global interrupts
	bsf		INTCON,4			;enables edge interrupt	
	bsf		INTCON,5			;enables TMR0


	movlw	d'16'								
	movwf	TMR0				
loop
	bcf		GPIO,4
	goto	loop


skip
	bcf		GPIO,5
	bcf		GPIO,4
	goto	skip

	end

Pushing the button works, but the timer doesn't and I can't figure out why!

Any help is greatly appreaciated,
Thanks
 
For a start you don't have any proper routine to service the interrupts!, there's no context saving and no RTI to return from the interrupt routine, so it will crash after a very small number of interrupts as the stack overflows.

If you're using more than one interrupt source you also need to determine which one caused the interrupt, and service them accordingly.
 
Status
Not open for further replies.

Latest threads

Back
Top