Glen wrote: > list p=16F84 ; list directive to define processor > #include ; processor specific variable definitions > __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_OFF & _XT_OSC ; If the following 3 do *not* generate an error, something is badly ; wrong, as they have already been defined in the include file! > STATUS equ 0x03 ;CPU equates (program memory map) > PORTA equ 0x05 ;CPU equates (program memory map) > PORTB equ 0x06 ;CPU equates (program memory map) > strttmr equ 0x0C ; no of counts > counta equ 0x0D ;value of the start timeout low value > countb equ 0x0E ;value of the start timeout high value > togl equ 0x0F > togh equ 0x10 > chksw equ 0x11 ; Similarly, these are defined in the include file and should generate ; errors if defined twice. > w equ 0 ; destination designators > f equ 1 ; destination designators ; This would be wrong. The Zero flag is bit *two* > ;Z equ 0 ... > nop ;WON'T WORK WITHOUT THIS NOP IN PROG ; Why? > MOVF PORTB,W ;get values of RB0 & RB1 > ANDLW 0x03 ; extract out bits 0,1 of PORTB > ; (strttmr sw value) > MOVWF chksw ;put rb0 & rb1 values in register chksw > CALL table ; use look up table ; Of course you realize that having commented out all but the first ; three values in "table", performing this call with the switches ; anything other than both ON will produce an infinite loop? > MOVWF strttmr ;move selected value from table to strttmr > 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 ; If you disable the pull-ups, and the switches are open, what prevents ; B0 and B1 floating at random? > ; ============= initialise timer setup ============== > 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 > CALL sttimer > initmr MOVLW .215 ;40 * .000256 = 10 ms > MOVWF TMR0 > togs CALL tog > ;============= check timer ======== > MOVF TMR0,w ;move f reg to w > BTFSC STATUS,Z ;if !0 ,GOTO loop ; The Z flag is *set* when the value is zero. This instruction ; therefore reads "Skip instruction if *NOT* Zero", so it will *only* ; loop back through "togs" when the timer reaches zero. Is that what ; you wanted? I suspect not. > GOTO togs > DECFSZ strttmr,f ;decrement strttmr by 1 > GOTO initmr ;go around for next delay > ; BTFSS INTCON,T0IF > ; GOTO togs > ; decfsz strttmr,f ;decrement strttmr by 1 > ; GOTO initmr ;go around for next delay ; This code *would* work if you added a " BCF INTCON,T0IF" just after ; the " MOVWF TMR0" after "initmr". > ;********************* delay sub-routines ************************** ; I see no reason at this point to use separate countdown values. ; Why not: delay MACRO count LOCAL loop MOVLW count MOVWF counta loop DECFSZ counta GOTO loop ENDM ;============== start timer ============= sttimer DELAY 0x02 DELAY 0x02 RETURN ;==============toggle outputs ============= tog MOVLW b'00110000' MOVWF PORTB DELAY 0x02 MOVLW b'00000000' MOVWF PORTB DELAY 0x02 RETURN -- Cheers, Paul B.