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.

cant get timer0 to work

Status
Not open for further replies.

frubo

New Member
I am new to interrupts/timers and I cant seem to get timer0 to work at all. I am simply blinking one led and when the timer overflows it should turn on another led but it isn't. just the first led is blinking.

Code:
	list             p=16f767
	#include	<P16F767.inc>


d1		equ		20h
d2		equ		21h
d3		equ		22h
TEMP	equ		23h
;**********************************************************************
	org		0x0000	
  	goto	START

	org 	0x0004

	movwf	TEMP			; save w register

	bsf		PORTA,1		; turn on led 2

	movfw	TEMP
	bcf		INTCON,T0IF
	retfie
	
START
	bcf	STATUS, RP1

	bcf	STATUS, RP0 ;bank 0
	clrf	PORTA

	bsf	STATUS, RP0 ;bank 1

	movlw	62h   	; 4mhz clk
	movwf	OSCCON

	movlw	00h
	movwf	OSCTUNE

	movlw 	0Fh 	; Configure all pins
	movwf	ADCON1 	; as digital

	movlw 	00h 	; all output
	movwf 	TRISA

	bcf 	STATUS, RP0 	; Bank0

	movlw 	b'00000000'
	movwf	OPTION_REG

	bsf		INTCON,GIE		; enable interrupts
	bsf		INTCON,TMR0IE	; enable timer0
	bcf		INTCON,TMR0IF	; clear timer overflow

LOOP
	bsf		PORTA,0			; turn on led
	movlw	0FFh
	call	DELAY			; delay 255 milli
	bcf		PORTA,0			; turn off led
	movlw	0FFh
	call	DELAY			; delay 255 milli
	goto	LOOP
;---------------------------------
;	DELAY ROUTINE	delays n milliseconds
;---------------------------------
	
DELAY
	movwf	d3

DELAY_1
			;993 cycles
	movlw	0xC6
	movwf	d1
	movlw	0x01
	movwf	d2
DELAY_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	DELAY_0

	decfsz	d3, f
	goto	DELAY_1

	return
	END
 
Last edited:
Which bank is the option_reg in?

Not the one you're currently accessing it from; check the datasheet.

Fix that and it works.

While you're in the datasheet look at the example code for saving the PICs state when entering an interrupt. The code you are using is very bad, not only does it not save the PICs status register, it alters it.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top