ASM – Encoder

encoder-16f74.asm:

...

; _________
; KONSTANTY

#DEFINE     BANK_1                  STATUS,RP0          ; PREPINANI BANK0 / BANK1

#DEFINE     x_TRIS_ENC_TL           TRISB,6
#DEFINE     x_TRIS_ENC_R            TRISB,5
#DEFINE     x_TRIS_ENC_L            TRISB,4

#DEFINE     k_PORT_ENC              PORTB
#DEFINE     x_PORT_ENC_TL           PORTB,6
#DEFINE     x_PORT_ENC_R            PORTB,5
#DEFINE     x_PORT_ENC_L            PORTB,4
    

MEM_ENCODER         UDATA_SHR

r_ENCODER_PRODLEVA              RES 1                   ; PROTIZAKMITOVA PRODLEVA

;___________
;PODPROGRAMY

CODE_ENCODER  CODE  

;###################################################################################################
_ENCODER__INIT:
;---------------------------------------------------------------------------------------------------

        ; --- INICIALIZACE PORTU ---

        BSF     BANK_1                                  ; BANKA -> 1

        BSF     x_TRIS_ENC_TL                           ; VSTUPNI: ENCODER TLACITKO
        BSF     x_TRIS_ENC_L                            ; VSTUPNI: ENCODER VLEVO
        BSF     x_TRIS_ENC_R                            ; VSTUPNI: ENCODER PRAVO

        BCF     OPTION_REG,NOT_RBPU                     ; AKTIVACE PULL-UP

        BCF     BANK_1                                  ; BANKA -> 0

        ; --- INICIALIZACE PRERUSENI ---

        MOVF    k_PORT_ENC,w                            ; SHOZENI POZADAVKU NA PRERUSENI OD PORTU B
        BCF     INTCON,RBIF  

        BSF     INTCON,RBIE                             ; POVOLENI PRERUSENI NA PORTU B

    RETURN

;###################################################################################################
_ENCODER__UDALOST:
;---------------------------------------------------------------------------------------------------
; * PRIPOJENI ENCODERU NA PORTY RB4 = L, RB5 = R, RB6 = TLACITKO NA PIC16F73,74,76,77
;
; * SEPNUTY KONTAKT JE ZDE BRAN V '0'.
;
; * PRI POVOLENEM PREUSENI INTCON,RBIE SE SEPNUTIM KONTAKTU VYVOLA PRERUSENI OD ZMENY STAVU NA PORTU
;   RB4, RB5, RB6, KTERY NAHODI PRIZNAK INTCON,RBIF.
;
; * V PRERUSENI SE TESTUJE PRIZNAK INTCON,RBIF A DALE PORTY RB4, RB5, RB6 PRO SELEKCI KONTAKTU.
;
; * NA KONCI ZPRACOVANI PRERUSENI SE MUSI PRIZNAK INTCON,RBIF RUCNE SHODIT.
;
; * KROK ENCODERU ZACNE POSTUPNYM SEPNUTIM L->R NEBO R->L.        ___             ___
;   UPROSTRED KRORKU JSOU SEPNUTE OBA KONTAKTY.             L:  _|  _|___     ___|_  |_
;   UKONCENI KROKU ZAS POSTUPNE KONTAKTY ROZEPNE.           R:  ___|   |_     _|   |___
;
; * SEJMUTI STAVU KONTAKTU MUSI BYT V JEJICH USTALENEM STAVU (NARPIKLAD PRODLEVOU OSETRIT ZAKMITY).
;---------------------------------------------------------------------------------------------------

        CALL    _ENCODER__PRODLEVA                      ; PROTIZAKMITOVA PRODLEVA
        CALL    _ENCODER__PRODLEVA                      ; PROTIZAKMITOVA PRODLEVA

        BTFSS   x_PORT_ENC_L                            ; ?? SEPNUT KONTAKT L ??
        GOTO    _ENCODER__UDALOST_L                     ; 'ANO'

        BTFSS   x_PORT_ENC_R                            ; ?? SEPNUT KONTAKT R ??
        GOTO    _ENCODER__UDALOST_R                     ; 'ANO'

        BTFSS   x_PORT_ENC_TL                           ; ?? SEPNUTO TLACITKO ??
        GOTO    _ENCODER__UDALOST_TL                    ; 'ANO'

        MOVF    k_PORT_ENC,w
        BCF     INTCON,RBIF                             ; SHOZENI POZADAVKU NA PRERUSENI OD PORTU RB

    RETURN

;###################################################################################################
_ENCODER__UDALOST_TL:
;---------------------------------------------------------------------------------------------------

        BTFSS   x_PORT_ENC_TL                           ; ?? SEPNUTO TLACITKO ??
        GOTO    _ENCODER__UDALOST_TL                    ; 'ANO'

        CALL    _ENCODER__PRODLEVA                      ; PROTIZAKMITOVA PRODLEVA
        CALL    _ENCODER__PRODLEVA                      ; PROTIZAKMITOVA PRODLEVA

... OBSLUZNY PROGRAM ...

        MOVF    k_PORT_ENC,w
        BCF     INTCON,RBIF                             ; SHOZENI POZADAVKU NA PRERUSENI OD PORTU RB

    RETURN

;###################################################################################################
_ENCODER__UDALOST_L:
;---------------------------------------------------------------------------------------------------

        BTFSS   x_PORT_ENC_L                            ; ?? SEPNUT KONTAKT L ??
        GOTO    _ENCODER__UDALOST_L                     ; 'ANO'

        BTFSS   x_PORT_ENC_R                            ; ?? SEPNUT KONTAKT R ??
        GOTO    $-1                                     ; 'ANO'

        CALL    _ENCODER__PRODLEVA                      ; PROTIZAKMITOVA PRODLEVA

... OBSLUZNY PROGRAM ...

        MOVF    k_PORT_ENC,w
        BCF     INTCON,RBIF                             ; SHOZENI POZADAVKU NA PRERUSENI OD PORTU RB

    RETURN

;###################################################################################################
_ENCODER__UDALOST_R:
;---------------------------------------------------------------------------------------------------

        BTFSS   x_PORT_ENC_R                            ; ?? SEPNUT KONTAKT R ??
        GOTO    _ENCODER__UDALOST_R                     ; 'ANO'

        BTFSS   x_PORT_ENC_L                            ; ?? SEPNUT KONTAKT L ??
        GOTO    $-1                                     ; 'ANO'

        CALL    _ENCODER__PRODLEVA                      ; PROTIZAKMITOVA PRODLEVA

... OBSLUZNY PROGRAM ...

        MOVF    k_PORT_ENC,w
        BCF     INTCON,RBIF                             ; SHOZENI POZADAVKU NA PRERUSENI OD PORTU RB

    RETURN

;###################################################################################################
_ENCODER__PRODLEVA:
;---------------------------------------------------------------------------------------------------
; PROTIZAKMITOVA PRODLEVA

        CLRF    r_ENCODER_PRODLEVA

        DECFSZ  r_ENCODER_PRODLEVA,f
        GOTO    $-1

    RETURN

;###################################################################################################
    END