Wan Zulhelmi Wan Ahmad Kamar wrote : > Hi, i've been trying to simulate a timer interrupt but it doesn't > work. Anybody have any suggestion? Based on the code elow tmrcounter > should increment on every interrupt so that i can calculate time more > than the 16 bit timer register. The scale of the timer is 1:8. > Thanks in advance. > > LIST p=18f252 > INCLUDE > > CounterA equ 0x00 > CounterB equ 0x01 > CounterC equ 0x02 > tmrcounter equ 0x03 > W_SAVE equ 0x05 > STATUS_SAVE equ 0x06 You don't need W_SAVE and STATUS_SAVE on the PIC18. > > ORG 0000H > GOTO MAIN > ORG 0008H > GOTO INT_SERV > > MAIN > CLRF PIR2,1 ;Register Overflow What us ",1" ? Use the symbols in the INC file ! > CLRF TMR3H > CLRF TMR3L > MOVLW 0x80 > MOVWF INTCON > MOVLW 0x02 > MOVWF PIE2 ;TMR3 Overflow Interrupt > MOVLW B'00110000' > MOVWF T3CON > BSF T3CON,0 What us ",0" ? Use the symbols in the INC file ! > > ; Loop for 1 second What are you waiting for ? > movlw D'26' > movwf CounterC > movlw D'119' > movwf CounterB > movlw D'87' > movwf CounterA > loop > decfsz CounterA,1 > goto loop > decfsz CounterB,1 > goto loop > decfsz CounterC,1 > goto loop > > BCF T3CON,0 > GOTO FINISH > > INT_SERV ;Interrupt Routine > > MOVWF W_SAVE ; save W > SWAPF STATUS, W ; save STATUS > MOVWF STATUS_SAVE No need to do that on the PIC18 ! > > INCF tmrcounter, 1 ;increment on every overflow Do not use ",1". Use the symbols in the INC file. > > SWAPF STATUS_SAVE, W > MOVWF STATUS; restore W and STATUS > SWAPF W_SAVE, F > SWAPF W_SAVE, W No need to do that. > CLRF PIR2,1 ; CLEAR Register Overflow Use the symbols in the INC file. > RETFIE Use "RETFIE, FAST" > > FINISH > END Here the PIC will just run thought the rest of the prog mem and restart from h'0000'. Is that realy what you want ? Jan-Erik. PS. I changed *one single bit in one register" and your code works just as you posted it... Hint : check PEIE :-) _______________________________________________ http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist