Код: Выделить всё
list P=16F84A ;THE COUNTER WITH THE GENERAL CATODE
__config 03FFBh
STATUS EQU 03h
PORTB EQU 06h
PORTA EQU 05h
TRISB EQU 06h
TRISA EQU 05h
PCL equ 02h
Reg_1 equ 0Ch
Reg_2 equ 0Dh
RPO EQU 5
Z equ 2
GIE equ 7
LED1 EQU 10h
LED2 EQU 11h
LED3 EQU 12h
LED4 EQU 13h
registr equ 0Fh
registr1 equ 1Fh
reg equ 0Eh
reg1 equ 1Eh
EEData equ 08h
EECon1 equ 08h
EEAdr equ 09h
EECon2 equ 09h
Intcon equ 0Bh
;---------------------------------------
org 0
goto Start
;----------------------------------------
Start clrf Intcon
clrf PORTA
clrf PORTB
bsf STATUS,RPO
MOVLW B'00010000'
movwf TRISA
movlw B'10000000'
movwf TRISB
bcf STATUS,RPO
;----------------------------------------
movlw .10
movwf LED1
movwf LED2
movwf LED3
movwf LED4
goto Ind1
on clrf LED1
clrf LED2
clrf LED3
clrf LED4
nop
call Pause
movlw 0
movwf EEAdr
nop
bsf STATUS,RPO
bsf EECon1,0
bcf STATUS,RPO
nop
movf EEData,W
movwf LED1
nop
nop
call Pause
movlw 1
movwf EEAdr
nop
bsf STATUS,RPO
bsf EECon1,0
bcf STATUS,RPO
nop
movf EEData,W
movwf LED2
nop
nop
call Pause
movlw 2
movwf EEAdr
nop
bsf STATUS,RPO
bsf EECon1,0
bcf STATUS,RPO
nop
movf EEData,W
movwf LED3
nop
nop
call Pause
movlw 3
movwf EEAdr
nop
bsf STATUS,RPO
bsf EECon1,0
bcf STATUS,RPO
nop
movf EEData,W
movwf LED4
nop
nop
movlw .255
movwf registr1
movwf reg1
movlw .10
movwf registr
movlw .50
movwf reg
movf reg1,w
bcf STATUS,2
xorwf LED1,w
btfsc STATUS,2
goto off
movf reg1,w
bcf STATUS,2
xorwf LED2,w
btfsc STATUS,2
goto off
movf reg1,w
bcf STATUS,2
xorwf LED3,w
btfsc STATUS,2
goto off
movf reg1,w
bcf STATUS,2
xorwf LED4,w
btfsc STATUS,2
goto off
bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
Poz0 bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
BTFSS PORTB,1
SLEEP
bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTA,4
GOTO Poz1
BTFSS PORTB,7
GOTO Poz2
GOTO Ind4
Poz1 CALL Ind2
bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
BTFSS PORTB,1
SLEEP
bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
BTFSC PORTA,4
GOTO Poz0
BTFSS PORTB,7
goto Poz3
GOTO Poz1
Poz2 CALL Ind2
bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
BTFSS PORTB,1
SLEEP
bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
BTFSC PORTB,7
GOTO Poz0
BTFSS PORTA,4
goto Poz4
GOTO Poz2
Poz3 call Ind2
bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
BTFSS PORTB,1
SLEEP
bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
BTFSC PORTB,7
goto Poz1
BTFSC PORTA,4
goto Poz5
goto Poz3
Poz4 call Ind2
bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
BTFSS PORTB,1
SLEEP
bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
BTFSC PORTA,4
goto Poz2
BTFSC PORTB,7
goto Poz6
goto Poz4
Poz5 call Ind2
bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
BTFSS PORTB,1
SLEEP
bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTA,4
goto Poz3
BTFSC PORTB,7
goto PLUS
goto Poz5
Poz6 call Ind2
bsf STATUS,RPO
MOVLW B'10000110'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,2
goto off
BTFSS PORTB,1
SLEEP
bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
BTFSS PORTB,7
goto Poz4
BTFSC PORTA,4
goto MINUS
goto Poz6
Tab addwf PCL,f
retlw B'00111111' ;0
retlw B'00000110' ;1
retlw B'01011011' ;2
retlw B'01001111' ;3
retlw B'01100110' ;4
retlw B'01101101' ;5
retlw B'01111101' ;6
retlw B'00000111' ;7
retlw B'01111111' ;8
retlw B'01101111' ;9
retlw b'01000000' ;-
;------------я------------------
Ind1 decfsz reg,f
goto $+2
goto on
bcf PORTA,0
movf LED1,W
call Tab
movwf PORTB
call Pause
bsf PORTA,0
bcf PORTA,3
movf LED2,W
call Tab
movwf PORTB
call Pause
bsf PORTA,3
bcf PORTA,2
movf LED3,W
call Tab
movwf PORTB
call Pause
bsf PORTA,2
bcf PORTA,1
movf LED4,W
call Tab
movwf PORTB
call Pause
bsf PORTA,1
goto Ind1
Ind2 bcf PORTA,0
movf LED1,W
call Tab
movwf PORTB
call Pause
bsf PORTA,0
bcf PORTA,3
movf LED2,W
call Tab
movwf PORTB
call Pause
bsf PORTA,3
bcf PORTA,2
movf LED3,W
call Tab
movwf PORTB
call Pause
bsf PORTA,2
bcf PORTA,1
movf LED4,W
call Tab
movwf PORTB
call Pause
bsf PORTA,1
RETURN
Ind3 bcf PORTA,0
movf LED1,W
call Tab
movwf PORTB
call Pause
bsf PORTA,0
call PAM1
bcf PORTA,3
movf LED2,W
call Tab
movwf PORTB
call Pause
bsf PORTA,3
call PAM2
bcf PORTA,2
movf LED3,W
call Tab
movwf PORTB
call Pause
bsf PORTA,2
call PAM3
bcf PORTA,1
movf LED4,W
call Tab
movwf PORTB
call Pause
bsf PORTA,1
call PAM4
goto Poz0
Ind4 bcf PORTA,0
movf LED1,W
call Tab
movwf PORTB
call Pause
bsf PORTA,0
bcf PORTA,3
movf LED2,W
call Tab
movwf PORTB
call Pause
bsf PORTA,3
bcf PORTA,2
movf LED3,W
call Tab
movwf PORTB
call Pause
bsf PORTA,2
bcf PORTA,1
movf LED4,W
call Tab
movwf PORTB
call Pause
bsf PORTA,1
goto Poz0
;delay = 4'000 machine cycles
Pause movlw .48
movwf Reg_1
movlw .6
movwf Reg_2
wr decfsz Reg_1, F
goto wr
decfsz Reg_2, F
goto wr
nop
return
PLUS call Ind2
BTFSS PORTB,7
goto PLUS
bsf Intcon,GIE
movf registr,w
incf LED1,f
bcf STATUS,2
xorwf LED1,w
btfss STATUS,2
goto Ind3
clrf LED1
movf registr,w
incf LED2,f
bcf STATUS,2
xorwf LED2,w
btfss STATUS,2
goto Ind3
clrf LED2
movf registr,w
incf LED3,f
bcf STATUS,2
xorwf LED3,w
btfss STATUS,2
goto Ind3
clrf LED3
movf registr,w
incf LED4,f
bcf STATUS,2
xorwf LED4,w
btfss STATUS,2
goto Ind3
clrf LED4
goto Ind3
MINUS call Ind2
BTFSS PORTA,4
goto MINUS
movf registr1,w
decf LED1,f
bcf STATUS,2
xorwf LED1,w
btfss STATUS,2
goto Ind3
movlw .9
movwf LED1
movf registr1,w
decf LED2,f
bcf STATUS,2
xorwf LED2,w
btfss STATUS,2
goto Ind3
movlw .9
movwf LED2
movf registr1,w
decf LED3,f
bcf STATUS,2
xorwf LED3,w
btfss STATUS,2
goto Ind3
movlw .9
movwf LED3
movf registr1,w
decf LED4,f
bcf STATUS,2
xorwf LED4,w
btfss STATUS,2
goto Ind3
movlw .9
movwf LED4
goto Ind3
PAM1 bcf Intcon,GIE
movlw 0
movwf EEAdr
movf LED1,w
movwf EEData
bsf STATUS,RPO
bsf EECon1,2
btfsc EECon1,1
goto $-1
movlw 055h
movwf EECon2
movlw 0AAh
movwf EECon2
bsf EECon1,1
bcf EECon1,4
bcf STATUS,RPO
return
PAM2 bcf Intcon,GIE
movlw 1
movwf EEAdr
movf LED2,w
movwf EEData
bsf STATUS,RPO
bsf EECon1,2
btfsc EECon1,1
goto $-1
movlw 055h
movwf EECon2
movlw 0AAh
movwf EECon2
bsf EECon1,1
bcf EECon1,4
bcf STATUS,RPO
return
PAM3 bcf Intcon,GIE
movlw 2
movwf EEAdr
movf LED3,w
movwf EEData
bsf STATUS,RPO
bsf EECon1,2
btfsc EECon1,1
goto $-1
movlw 055h
movwf EECon2
movlw 0AAh
movwf EECon2
bsf EECon1,1
bcf EECon1,4
bcf STATUS,RPO
return
PAM4 bcf Intcon,GIE
movlw 3
movwf EEAdr
movf LED4,w
movwf EEData
bsf STATUS,RPO
bsf EECon1,2
btfsc EECon1,1
goto $-1
movlw 055h
movwf EECon2
movlw 0AAh
movwf EECon2
bsf EECon1,1
bcf EECon1,4
bcf STATUS,RPO
return
off bsf STATUS,RPO
MOVLW B'10000000'
movwf TRISB
bcf STATUS,RPO
movlw .0
movwf LED1
movwf LED2
movwf LED3
movwf LED4
goto Ind3
;----------------------------------------
end
P/S Совсем забыл, сначала делал как на схеме кондёр С1 22 пик. ставил схема запустилась считала обнуляла, но сохранение в EEPROM не работало. Увеличил емкость до 53 пик и все заработало как часы.