; program using BTFSS and BTFSC

; BTFSS = Check status of the specified bit number,

                ;skip one (1) instruction if set as high (on state)

; BTFSC = Check status of the specified bit number,

                ;skip one (1) instruction if set as low (off state)

; mcu = pic16f84A

; simulate using picsimulatoride

 

; Set up the pins of the microcontroller

BSF STATUS,5          ; bit set on pin 5 of status register

                                            ; from bank0 to bank1 on register file map

MOVLW 0X10            ; move literal binary value 0001 0000

MOVWF TRISA         ; set porta pin RA4 as input and RA0-RA3 as output

BCF STATUS,5         ; bit clear on pin 5 of status register

                                            ; from bank1 to bank0 on register file map

MOVLW 0X64            ; move literal value decimal 100 to w register

MOVWF 0X21            ; store decimal value 100 to 0x21


;main program , light pattern changes every time we change the status of RA4


OFF     MOVLW 0X00            ; no light should be ON

           MOVWF PORTA

            BTFSS PORTA,4        ; check status of RA4, lights off if low and blinking if high

            GOTO OFF


; blinking light


BLINK    MOVLW 0X0F            ; move literal value 01111 to w register

MOVWF PORTA        ; set high output on pins 0,1,2 and 3

CALL DELAY             ; set some delay

MOVLW 0X00            ; move literal value 00000 to w register

MOVWF PORTA        ; set low output on pins 0,1,2 and 3

CALL DELAY             ; set delay

BTFSC PORTA,4        ; check status of RA4, blinking if high and change pattern if low

            GOTO BLINK


; running light 


RUN  MOVLW 0X01     

         MOVWF PORTA    ; only pin RA0 lights will be on

         CALL DELAY

         MOVLW 0X02

         MOVWF PORTA    ; only pin RA1 lights will be on

         CALL DELAY

         MOVLW 0X04

         MOVWF PORTA    ;only pin RA2 lights will be on

         CALL DELAY

         MOVLW 0X08

         MOVWF PORTA    ;only pin RA2 lights will be on

         CALL DELAY

         BTFSS PORTA,4    ; check status of RA4, running lights if low and alternating lights if on

         GOTO RUN


; alternating light

ALTER MOVLW 0X06

           MOVWF PORTA    ; RA1 and RA2 lights will be on

           CALL DELAY

           MOVLW 0X09

           MOVWF PORTA    ;RA0 and RA3 lights will be on

           CALL DELAY

           BTFSC PORTA,4    ; check status of RA4, alternating lights if high and off lights if low

           GOTO ALTER

           GOTO OFF


; subroutine delay

DELAY  DECFSZ 0X20,1        ; decrement by 1 the value in 0x20

GOTO DELAY            ; go to label DELAY

DECFSZ 0X21,1         ; decrement by 1 the value in 0x21

GOTO DELAY            ; go to label DELAY

MOVLW 0X64            ; move literal value decimal 100 to w register

MOVWF 0X21            ; store decimal value 100 to 0x21

RETURN                    ; return

END                                      ; end of program