;=======================================================
; Проект 13. Счётчик 0..99 на двух индикаторах
; PIC16F84A, 4 МГц. Сегменты RB0..RB6, разряды RA0, RA1
;=======================================================
        LIST    p=16F84A
        #include <p16f84a.inc>
        __CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF

        cblock  0x0C
        d1, tens, ones, loops
        endc

        ORG     0x000
        goto    Start

Table
        addwf   PCL,f
        retlw   b'00111111'
        retlw   b'00000110'
        retlw   b'01011011'
        retlw   b'01001111'
        retlw   b'01100110'
        retlw   b'01101101'
        retlw   b'01111101'
        retlw   b'00000111'
        retlw   b'01111111'
        retlw   b'01101111'

Start
        bsf     STATUS,RP0
        clrf    TRISB
        clrf    TRISA
        bcf     STATUS,RP0
        clrf    tens
        clrf    ones

Main
        movlw   .100            ; ~1 с подсветки числа
        movwf   loops
Show
        bcf     PORTA,1
        movf    tens,w
        call    Table
        movwf   PORTB
        bsf     PORTA,0
        call    Delay5ms

        bcf     PORTA,0
        movf    ones,w
        call    Table
        movwf   PORTB
        bsf     PORTA,1
        call    Delay5ms
        decfsz  loops,f
        goto    Show

        ;--- увеличиваем счётчик ---
        incf    ones,f
        movf    ones,w
        xorlw   .10
        btfss   STATUS,Z
        goto    Main
        clrf    ones            ; перенос в десятки
        incf    tens,f
        movf    tens,w
        xorlw   .10
        btfsc   STATUS,Z
        clrf    tens            ; после 99 — снова 00
        goto    Main

Delay5ms
        movlw   .250
        movwf   d1
D5      nop
        nop
        nop
        nop
        nop
        decfsz  d1,f
        goto    D5
        return

        END
