• 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.

Using TMR0 to increment a timer pleeease help

Status
Not open for further replies.

Harpua

New Member
Yeah this is a repeat post but im really struggling to see whats wrong here. Im using the Timer feature of TMR0 module. The prescalar is set to 1:256 and an initial value of d'252' is loaded into TMR0 for an interrupt to occur every millesecond. It runs off the internal clock (4Mhz). Goto ISR is placed at the 0x04 locatioin, but it seems that it either doesn't go to the ISR or TMR0 does not incremment. Any help, its greatly appreciated.




TMR0Setup
bcf STATUS, RP1
bcf STATUS, RP0
movlw b'00010111'
movwf OPTION_REG
movlw b'10100000'
movwf INTCON movlw d'252'
movwf TMR0 bcf INTCON, TMR0IF


ISR
bcf INTCON, GIE comf PORTB
SaveSettings
movwf Temp_W
swapf STATUS, W
movwf Temp_STATUS
incf MS_TIMER
ResetTimer0
movlw d'252'
movwf TMR0 bcf INTCON, TMR0IF
bsf INTCON, GIE
RestoreSettings
swapf Temp_STATUS, W
movwf STATUS swapf Temp_W, F swapf Temp_W, W
retfie
 

Exo

Active Member
First of all, OPTION_REG is in bank1, you're writing to it while in bank 0.
Then when you enter your ISR you do not know in wich bank you are when you enter so you must banksel after context .Also make sure that the variables you use for context saving are shared between banks for the same reason.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top