Hi Yettie,
I couldn't get your code to compile without errors. Try this;
Look in the manual, and at some of the MeLabs examples for assembler interrupts to find out why it works.Code:@ DEVICE MCLR_OFF,LVP_OFF,HS_OSC,WDT_OFF DEFINE OSC 8 define debug_reg porta 'nevermind my serial LCD display debugger define debug_bit 0 define debug_baud 2400 define debug_mode 1 define inthand checkNow CMCON=7 TRISB.3=0 'Variables for saving state in interrupt handler wsave VAR BYTE $70 system ' Saves W ssave VAR BYTE bank0 system ' Saves STATUS psave VAR BYTE bank0 system ' Saves PCLATH fsave VAR BYTE bank0 system ' Saves FSR time var word flag var byte decideTimeInterval var word TIMEINTERVAL con 600 ;----------------------- setup: debug 12,"Starting",10,13," Program",4 pause 2000 intcon = %11000000 ;setting up gie and peie bits time = 3036 ;calibrated to have 31.25ms scale tmr1H = time.highbyte tmr1L = time.lowbyte ;65536 - time (preload value) flag = 0 decideTimeInterval = 0 PIR1.0 = 0 PIE1.0 = 1 T1CON = %00110001 ;setting up to 1:8 prescale ;31.25ms x 8 = 250ms/count ;-------------------------------- main: if flag = 4 then ;(250ms x 4 = 1s) second ticker flag = 0 decideTimeInterval = decideTimeInterval + 1 gosub updateTime endif if decideTimeInterval = TIMEINTERVAL then ;this one is the notorious routine. it's just a reset condition. decideTimeInterval = 0 ;It resets unexpectedly. In contrast to this, endif ;changing the decideTimeInterval to BYTE and of course ;TIMEINTERVAL <= 255 will function properly goto main ;---------------------------- updateTime: DEBUG "Time:",#decideTimeInterVal return ;------------------------ ;interrupt handler asm checkNow ; Save FSR, PCLATH, STATUS and W registers movwf wsave ; Save W swapf STATUS, W ; Swap STATUS to W (swap avoids changing STATUS) clrf STATUS ; Clear STATUS movwf ssave ; Save swapped STATUS movf PCLATH, W ; Move PCLATH to W movwf psave ; Save PCLATH ; isr routine bsf STATUS,RP0 ; bank 1 bcf PIE1,0 bcf STATUS,RP0 ; bank 0 incf _flag,f ; increment flag movlw 0x8 xorwf PORTB,f ; toggle portb.3 movf _time,W movwf TMR1L movf _time+1,W movwf TMR1H bcf PIR1,0 bsf STATUS,RP0 ; bank 1 bsf PIE1,0 bcf STATUS,RP0 ; bank 0 ; Restore FSR, PCLATH, STATUS and W registers movf fsave, W ; retrieve FSR value movwf FSR ; Restore it to FSR movf psave, W ; Retrieve PCLATH value movwf PCLATH ; Restore it to PCLATH swapf ssave, W ; Retrieve the swapped STATUS value (swap to avoid changing STATUS) movwf STATUS ; Restore it to STATUS swapf wsave, F ; Swap the stored W value swapf wsave, W ; Restore it to W (swap to avoid changing STATUS) retfie ; Return from the interrupt endasm end




Bookmarks