thanks for your time i originally had the lookup table in the subroutines but moved it to the top. the value supplied to strrttmr from the lookup table is still the first value (.25),regardless of the switch settings (rb0 & rb1). i still am at a loss as too why ! ********************* * ; Notes: This program is to operate as follows , * ; after the zero crossing , start timer times out then * ; 2 outputs ( PORTB bits 4,5 ) toggle (turning off at the end of the * ; each cycle ) after counting for a specific time the outputs stay off* ; * ;********************************************************************** list p=16F84 ; list directive to define processor #include ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_OFF & _XT_OSC ;********************************************************************** ; vars PORTA equ 0x05 ;CPU equates (program memory map) PORTB equ 0x06 ;CPU equates (program memory map) souter equ 0x0c ; sinner equ 0x0d ; inners equ 0x0e ; outers equ 0x0f ; innerf equ 0x10 ; outerf equ 0x11 ; chksw equ 0x12 ; strttmr equ 0x13 ; no of counts STATUS equ 0x03 ;CPU equates (program memory map) w equ 0 ; destination designators f equ 1 ; destination designators ;********************************************************************** org 0x000 ;address 000 program start GOTO start ;jump over table ;********************************************************************** table ANDLW 0x03 CLRF PCLATH ADDWF PCL retlw .25 ;d'25' ; 00 : 250ms (switch position 1) retlw .50 ;d'50' ; 01 : 500ms (switch position 2) retlw .75 ;d'75' ; 10 : 750ms (switch position 3) retlw .100 ;d'100' ; 11 : 1000ms (switch position 4) ;********************************************************************** ; PORTA set-up start MOVLW 0xff ;ff hex moved to w register tris PORTA ;porta set as inputs ; ;********************************************************************** ; PORTB set-up MOVLW 0x0f ;00001111 hex moved to w register tris PORTB ;PORTB set o/p's 4,5,6,7,inputs 0,1,2,3 ; ;********************************************************************** CLRF STATUS CLRF PCLATH ;============= prescaler setup ===pullups enabled=========== MOVLW b'00000111' ;scale 1:256 , pullups enabled OPTION ; ============= counter setup ============== ;code below is used for 2 switches to select a value (0-3) ; from lookup table & place into strttmr MOVF PORTB,w ;get values of RB0 & RB1 ANDLW 0x03 ; extract bits rb0,rb1 of PORTB (switch values) MOVWF chksw ;put rb0 & rb1 values in register chksw CALL table ; get look up table value from sw settings(0-3) MOVWF strttmr ;move selected value from table to strttmr ;********************************************************************** ; ============== program start ============= MOVLW 0x00 ;move 00 hex to register w MOVWF PORTB ;move register w to PORTB (clear PORTB) ;============= prescaler setup ===pullups disabled=========== MOVLW b'10000111' ;scale 1:256 , pullups disabled OPTION ; ============= initialise timer setup ============== initmr MOVLW .215 ;40 * .000256 = 10 ms MOVWF TMR0 loop CALL chcycs ;check for zero crossing CALL sttimer CALL tog ; ============= check timer ============== BTFSS INTCON,T0IF GOTO loop decfsz strttmr,f ;decrement strttmr by 1 GOTO initmr ;go around for next delay ;drop thru to stop stop GOTO stop ;======================================================================= ; delay sub-routine ; ================= ;============= check start cycle / check finish cycle ============= chcycs BTFSC PORTB,3 ;check AC input at port b pin 2 for 0 GOTO chcycs ;check again if still high lw BTFSS PORTB,3 ;check AC input at port b pin 2 for 1 GOTO lw ;check again if still low RETURN ;found zero crossing - rising edge ;********************* delay sub-routines ******************************* ; ; ============== start timer ============= sttimer MOVLW 0x10 ;move 00 hex to register w MOVWF souter ;move register w to "outer" sout MOVLW 0x10 ;move 00 hex to register w MOVWF sinner ;move register w to "inner" sinn decfsz sinner,f ;decrement "inner" each scan, scan for 0 GOTO sinn ;loop "inner" until it = 0 decfsz souter,f ;decrement "outer" each scan, scan for 0 GOTO sout ;loop "outer" until it = 0 RETURN ; ==============toggle outputs ============= tog bsf PORTB,4 ;set PORTB bit 4 high } bsf PORTB,5 ;set PORTB bit 5 high } CALL togs ;CALLs toggle sub-routine } Toggle 4/5 bcf PORTB,4 ;set PORTB bit 4 low } bcf PORTB,5 ;set PORTB bit 5 low } CALL togf ;CALL the delay sub-routine BTFSC PORTB,3 ;skip next if 0 GOTO tog RETURN ; ============== ontime delay ============= togs MOVLW 0x2 ;move 00 hex to register w MOVWF outers ;move register w to "outer" outs MOVLW 0x2 ;move 00 hex to register w MOVWF inners ;move register w to "inner" inns decfsz inners,f ;decrement "inner" each scan, scan for 0 GOTO inns ;loop "inner" until it = 0 decfsz outers,f ;decrement "outer" each scan, scan for 0 GOTO outs ;loop "outer" until it = 0 RETURN ; ============== offtime delay ============= togf MOVLW 0x1 ;move 00 hex to register w MOVWF outerf ;move register w to "outer" outf MOVLW 0x1 ;move 00 hex to register w MOVWF innerf ;move register w to "inner" innf decfsz innerf,f ;decrement "inner" each scan, scan for 0 GOTO innf ;loop "inner" until it = 0 decfsz outerf,f ;decrement "outer" each scan, scan for 0 GOTO outf ;loop "outer" until it = 0 RETURN ;********************************************************************** END ; directive 'end of program' ;thankyou for your helping a begginner glen