Progetto per PIC16c57 : contatore controllato da due ingressi : Clear e Jump; dispone di due bit d’uscita.
list p=16c57
#include.inc>
__CONFIG _XT_OSC & _CP_OFF & _WDT_OFF
; portA(0) = Clock; portA(1) = Clear; portA(2)= Jump
; portB(0) = Out1 portB(1) = Out2
RADIX DEC
CK_PREC EQU 0x08
TEMP EQu 0x09 ; cntrolla indirizzo
CONT EQU 0x0A
ORG 0x7ff
goto START
ORG 0x00
START
CLRW
TRIS PORTB
MOVLW b'111'
TRIS PORTA ; 3 ingressi
CLRF CK_PREC
CLRF CONT
LOOP
BTFSC CK_PREC,0
GOTO UPDATE
BTFSS PORTA,0
GOTO UPDATE
GOTO MAIN
UPDATE
MOVF PORTA,CK_PREC
GOTO LOOP
MAIN
BTFSC PORTA,1 ; CLEAR = ?
GOTO CLEAR ; 1
BTFSC PORTA,2 ; JUMP = ?
GOTO JUMP
INCF CONT,F
GOTO CHECK
CLEAR
CLRF CONT
GOTO STAMPA
JUMP
MOVLW 2
ADDWF CONT,F
GOTO CHECK
CHECK
MOVLW 4
SUBWF CONT,W
BTFSC STATUS,Z ; cont=4 ?
GOTO SET_ONE
MOVLW 5
SUBWF CONT,W
BTFSC STATUS,Z
GOTO SET_TWO
STAMPA
MOVF CONT, PORTB
GOTO LOOP
SET_ONE
MOVLW 1
MOVF W, CONT
GOTO STAMPA
SET_TWO
MOVLW 2
MOVF W,CONT
GOTO STAMPA
END