I have a three digit LED display for a thermometer. I had the multiplexing working fine for the three digits when it was in my main code. I simply decremented a variable that was initialized with a value of 3. For each value, I turned on the respective digit, delayed for a while, and went to the next one. I wanted to make changes to the code that would affect the time delay between displays so I thought I should put the digit multiplexing code in a routine that would be called by a TIMER0 rollover-initiated interrupt. I tested the scheme with a called routine that simply toggled an output, and the interrupt stuff all worked well. Once I got that far, I started working on the multiplexing math and logic but have had no success. This is my first time at using interrupts and I suspect that I am doing something wrong that is messing up my code. I show three versions of my routine below. The first worked fine and showed me that I had the interrupt stuff right. The next two show simple attempts at asserting three outputs in succession, however without success. Can someone tell me the errors of my ways here?!?!?!?! Plus, is there a slicker easier way to do this? Thanks. Mark Peterson DISPLAY movwf _w ; Save swapf status,w ; Save movwf _status ; Save bcf intcon,2 ; Clear interrupt bit movfw LOOP ; LOOP to w movwf portb ; Send to port LOOPDEC decfsz LOOP ; Equal to 0? goto $+3 ; No, leave and do it again later. movlw d'3' ; Yes, reinitialize LOOP variable. movwf LOOP ; Yes, reinitialize LOOP variable. swapf _status,w ; Restore. movwf status ; Restore. swapf _w ; Restore. swapf _w,w ; Restore. retfie ; Return. With the code above, bits 0 and 1 on Portb step through 11, 10, 01 with each rollover of TIMER0. With this success, I moved on to transform the LOOP count into individual bit assertions. DISPLAY movwf _w ; Save swapf status,w ; Save movwf _status ; Save bcf intcon,2 ; Clear interrupt bit movfw LOOP ; LOOP to w call DIGIT_T movwf portb LOOPDEC decfsz LOOP ; Equal to 0? goto $+3 ; No, leave and do it again later. movlw d'3' ; Yes, reinitialize LOOP variable. movwf LOOP ; Yes, reinitialize LOOP variable. swapf _status,w ; Restore. movwf status ; Restore. swapf _w ; Restore. swapf _w,w ; Restore. retfie ; Return. ****Tabel located in main code****** DIGIT_T ; 3 digit display table addwf pcl,f ; Jump into lookup table ; _____321' retlw b'11111011' ; Segment 3 retlw b'11111101' ; Segment 2 retlw b'11111110' ; Segment 1 With the code above, portb bits 0, 1, & 2 are on all the time. It's a simple lookup table yet I can't see what I did wrong. DISPLAY movwf _w ; Save swapf status,w ; Save movwf _status ; Save bcf intcon,2 ; Clear interrupt bit bsf portb,0 ; Turn off 100 digit bsf portb,1 ; Turn off 10 digit bsf portb,2 ; Turn off 1 digit movfw LOOP ; LOOP to w sublw d'3' ; 3 - LOOP in w btfss status,2 ; LOOP = 3? goto LOOPDEC ; No, leave. bcf portb,2 ; Yes, turn on 100 digit goto LOOPDEC ; Yes, leave. movfw LOOP ; LOOP to w sublw d'2' ; 2 - LOOP in w btfss status,2 ; LOOP = 2? goto LOOPDEC ; No, leave. bcf portb,1 ; Yes, turn on 10 digit goto LOOPDEC ; Yes, leave. movfw LOOP ; LOOP to w sublw d'1' ; 1 - LOOP in w btfss status,2 ; LOOP = 1? goto LOOPDEC ; No, leave. bcf portb,0 ; Yes, turn on 1 digit goto LOOPDEC ; Yes, leave. LOOPDEC decfsz LOOP ; Equal to 0? goto $+3 ; No, leave and do it again later. movlw d'3' ; Yes, reinitialize LOOP variable. movwf LOOP ; Yes, reinitialize LOOP variable. swapf _status,w ; Restore. movwf status ; Restore. swapf _w ; Restore. swapf _w,w ; Restore. retfie ; Return. With the code above, portb,2 flashes at the rate that TIMER0 rolls over but bits 0 and 1 are on steady. Again, it's straight forawrd stuff that works in regular main code but I can't get to work inside the interrupt-called routine. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist