Hi,
Me doing some switch testing and i am just trying to turn LEDs on and off to detect a positive switch change..For ST_ST_button, i am just trying to detect whether led has been on or off, if it was off then on it, if it was on then off it..but is only able to detect an ON led and off it but when it is off, it is unable to ON the led..why is this so?I thought the btfss command wld be suffice enough to detect the state of the led.pls point out what has gone wrong for this simple code.Thanks
Also how come even using code tags, the code seems messy and out of place?
Me doing some switch testing and i am just trying to turn LEDs on and off to detect a positive switch change..For ST_ST_button, i am just trying to detect whether led has been on or off, if it was off then on it, if it was on then off it..but is only able to detect an ON led and off it but when it is off, it is unable to ON the led..why is this so?I thought the btfss command wld be suffice enough to detect the state of the led.pls point out what has gone wrong for this simple code.Thanks
Code:
org 0x0000 ;org sets the origin, 0x0000 for the 16F628
goto MAIN ;this is where the program starts running
INIT movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
BANK1 ;select bank 1
movlw b'00000000'
movwf TRISB ;set PortB all outputs
movlw b'00111111'
movwf TRISA ;set PortA to be 6 inputs and 2 outputs
BANK0 ;select bank 0
clrf PORTB ;set all outputs low
CHKBUTTON btfss PORTA,sw0 ;Note when swtiched is closed/push, it goes LOW
call MIN_button ;Switch 1 is pressed
btfss PORTA,sw1
call SEC_button ;Switch 2 is pressed
btfss PORTA,sw2
call ST_ST_button ;Switch 3 is pressed
;btfss PORTA,sw3
;call RESET_button ;Switch 4 is pressed
;btfss PORTA,sw4
;call TRANSMIT_button ;Switch 5 is pressed
goto CHKBUTTON ;Go back and check the state of the switches
;----------------------------------------------------------------------
MIN_button call Switchdelay ;call debounce delay
btfsc PORTA,sw0 ;is switch still pressed?
goto CHKBUTTON ;switch has been released
call UP_DOWN_MIN ;yes,switch still closed
return
UP_DOWN_MIN clrf PORTB
bsf PORTB,0
return
;------------------------------------------------------------------------
SEC_button call Switchdelay ;call debounce delay
btfsc PORTA,sw1 ;is switch still pressed?
goto CHKBUTTON ;switch has been released
call UP_DOWN_SEC ;yes,switch still closed
return
UP_DOWN_SEC clrf PORTB
bcf PORTB,0
return
;-------------------------------------------------------------------------
ST_ST_button call Switchdelay ;call debounce delay
btfsc PORTA,sw2 ;is switch still pressed?
goto CHKBUTTON ;switch has been released
call START_STOP ;yes,switch still closed
return
START_STOP clrf PORTB
btfss PORTB,0 ;chk if led is ON
bsf PORTB,0 ;its OFF, then switch LED ON
bcf PORTB,0 ;its ON,then switch led OFF
return
Also how come even using code tags, the code seems messy and out of place?