#include P12F675.INC
;
               __config        0x3f84
;
cnt0			EQU		20h
cnt1			EQU		21h
cnt2			EQU		22h
;
cnt3			EQU		23h
cnt4			EQU		24h
cnt5			EQU		25h
;
adrHI			EQU		26h
adrLO			EQU		27h
len_tb			EQU		28h
;
n_tabl			EQU		29h
;
cnt_cikl		EQU		2ah
cnt_adr			EQU		2bh
tmp				EQU		2ch
;
mem				EQU		2dh
;
speed			EQU		2eh
;
tmp2			EQU		2fh
;
cnt6			EQU		30h
cnt7			EQU		31h
;
cnt_prog		EQU		32h
;
tmpLO			EQU		33h
tmpHI			EQU		34h
;
tmp3			EQU		35h
;

INIT_PORT		EQU		b'00000011'	
;
;
DATAPORT        EQU     05h
;
;
;
				goto			begin
;
;
out
				movwf			tmpLO
				movwf			tmpHI
				movlw			B'00000011'
				andwf			tmpLO,1		
				movlw			B'00001100'
				andwf			tmpHI,1	
				rlf				tmpHI,1
				rlf				tmpHI,0
				addwf			tmpLO,0
				return
;
delay01			
				movwf 			cnt3
delay10			movlw 			.10
				movwf 			cnt4
delay11			movlw 			.10
				movwf 			cnt5
delay12			nop
				nop
				decfsz 			cnt5,f
				goto 			delay12
				decfsz 			cnt4,f
				goto 			delay11
				decfsz 			cnt3,f
				goto 			delay10
				return
;
pause			macro			dlit
				movlw			dlit
				call			delay01
				endm
;
Init
				bsf 			STATUS,RP0
				call			3ffh
				movwf			OSCCAL
				bcf 			STATUS,RP0
				movlw			07h
				movwf			CMCON
				bcf 			STATUS,RP1
				bsf 			STATUS,RP0
				movlw 			0h
				movwf 			ANSEL^80h
				movlw 			0ch
				movwf 			TRISIO^80h
				movlw 			0h
				movwf 			WPU
				bcf				OPTION_REG,NOT_GPPU
				bcf				INTCON,GIE
				bcf 			STATUS,RP0
				movlw			09h
				movwf			mem
				movlw			05h
				movwf			speed
				movlw			22h
				movwf			cnt_prog
				movlw			0h
				movwf			n_tabl
				clrf 			STATUS
				clrf 			DATAPORT
				clrf			len_tb
				clrf			adrHI
				clrf			adrLO
				clrf			cnt_cikl
				clrf			cnt_adr
				clrf			GPIO
				return
;
flash			
				movf			GPIO,0
				movwf			tmp3
				movlw			0ffh
				movwf			GPIO
				pause			.180
				movlw			0h
				movwf			GPIO
				pause			.180
				movlw			0ffh
				movwf			GPIO
				pause			.180
				movlw			0h
				movwf			GPIO
				pause			.180
				movf			tmp3,0
				movwf			GPIO
				return
;
delay			movf			speed,0
				movwf 			cnt0
delay0			movlw 			.50
				movwf 			cnt1
delay1			movlw 			.250
				movwf 			cnt2
delay2			nop
				nop
				call 			opros_kb
				decfsz 			cnt2,f
				goto 			delay2
				decfsz 			cnt1,f
				goto 			delay1
				movf			cnt0,0
				xorlw			0h
				btfsc			STATUS,Z
				goto			null
				decfsz 			cnt0,f
				goto 			delay0
null			return
;
opros_kb		
;				bsf				GPIO,2
;				bsf				GPIO,3
				btfss			GPIO,2
				goto			plus
				btfss			GPIO,3
				goto			minus
				return
;
plus			
				movf			speed,0
				xorlw			0h
				btfsc			STATUS,Z
				goto			l1
				decfsz			speed,1
				pause			.30
				call			flash
				return
l1	
				movlw			0ah
				movwf			speed
				pause			.30
				call			flash
				return
;
minus			
				movlw			01h
				movwf			cnt_cikl
				movlw			01h
				movwf			len_tb
				pause			.30
				call			flash
				return
;
;
;
begin			
				call 			Init
new_tb
				movlw			.50
				movwf			cnt_cikl
new_cikl
				movf			n_tabl,0
				movwf			tmp
				rlf				tmp,1
				addwf			tmp,1
				movf			tmp,0
				call			adr_tb
				movwf			adrHI
				incf			tmp,1
				movf			tmp,0
				call			adr_tb
				movwf			adrLO
				incf			tmp,1
				movf			tmp,0
				call			adr_tb
				movwf			len_tb
				movlw			0h
				movwf			cnt_adr
start			
				movf			PCLATH,0
				movwf			tmp2
				movf			adrHI,0
				movwf			PCLATH
				movf			adrLO,0
				call			led
				call			out
				movwf           GPIO
				movf			tmp2,0
				movwf			PCLATH
				call			delay
				incf			adrLO,1
				decfsz			len_tb,1
				goto			start
				decfsz			cnt_cikl,1
				goto			new_cikl
				incf			n_tabl
				decfsz			cnt_prog,1
				goto			new_tb
				movlw			22h
				movwf			cnt_prog
				movlw			0h
				movwf			n_tabl
				goto			new_tb
;
;
adr_tb			addwf			PCL,1
				dt				high(bt0)
				dt				low(bt0)
				dt				low(et0)-low(bt0)
				dt				high(bt1)
				dt				low(bt1)
				dt				low(et1)-low(bt1)
				dt				high(bt2)
				dt				low(bt2)
				dt				low(et2)-low(bt2)
				dt				high(bt3)
				dt				low(bt3)
				dt				low(et3)-low(bt3)
				dt				high(bt4)
				dt				low(bt4)
				dt				low(et4)-low(bt4)
				dt				high(bt5)
				dt				low(bt5)
				dt				low(et5)-low(bt5)
				dt				high(bt6)
				dt				low(bt6)
				dt				low(et6)-low(bt6)
				dt				high(bt7)
				dt				low(bt7)
				dt				low(et7)-low(bt7)
				dt				high(bt8)
				dt				low(bt8)
				dt				low(et8)-low(bt8)
				dt				high(bt9)
				dt				low(bt9)
				dt				low(et9)-low(bt9)
				dt				high(bt10)
				dt				low(bt10)
				dt				low(et10)-low(bt10)
				dt				high(bt11)
				dt				low(bt11)
				dt				low(et11)-low(bt11)
				dt				high(bt12)
				dt				low(bt12)
				dt				low(et12)-low(bt12)
				dt				high(bt13)
				dt				low(bt13)
				dt				low(et13)-low(bt13)
				dt				high(bt14)
				dt				low(bt14)
				dt				low(et14)-low(bt14)
				dt				high(bt15)
				dt				low(bt15)
				dt				low(et15)-low(bt15)
				dt				high(bt16)
				dt				low(bt16)
				dt				low(et16)-low(bt16)
				dt				high(bt17)
				dt				low(bt17)
				dt				low(et17)-low(bt17)
				dt				high(bt18)
				dt				low(bt18)
				dt				low(et18)-low(bt18)
				dt				high(bt19)
				dt				low(bt19)
				dt				low(et19)-low(bt19)
				dt				high(bt20)
				dt				low(bt20)
				dt				low(et20)-low(bt20)
;
;
				org 			100h
;
led				
				movwf			PCL
bt0				dt				01h,02h,04h,08h,04h,02h,01h,02h,04h,08h,04h,02h
et0
bt1				dt				01h,03h,07h,0Fh,07h,03h,01h,03h,07h,0Fh,07h,03h
et1
bt2				dt				01h,08h,01h,08h,02h,08h,02h,08h,04h,08h,04h,08h
et2
bt3				dt				05h,0Ah,05h,0Ah,05h,0Ah
et3
bt4				dt				01h,03h,07h,0Fh,0Eh,0Ch,08h,01h,03h,07h,0Fh,0Eh,0Ch,08h
et4
bt5				dt				01h,02h,04h,08h,01h,03h,07h,0Fh,0Eh,0Ch,08h,01h,02h,04h,08h,01h,03h,07h,0Fh,0Eh,0Ch,08h
et5
bt6				dt				01h,03h,07h,0Fh,07h,03h,01h,03h,07h,0Fh,07h,03h,01h
et6
bt7				dt				01h,03h,07h,0Fh,0Eh,0Ch,08h,01h,03h,07h,0Fh,0Eh,0Ch,08h,0Ch,0Eh,0Fh,07h,03h,01h,08h,0Ch,0Eh,0Fh,07h,03h,01h
et7
bt8				dt				01h,03h,07h,0Fh,0Eh,0Ch,08h,01h,03h,07h,0Fh,0Eh,0Ch,08h,0Ch,0Eh,0Fh,07h,03h,01h,08h,0Ch,0Eh,0Fh,07h,03h,01h
et8
bt9				dt				01h,02h,04h,08h,09h,0Ah,0Ch,0Dh,0Eh,0Fh,07h,0Bh,03h,05h,09h,01h,02h,04h,08h,00h
et9
bt10			dt				01h,08h,02h,04h,02h,04h,01h,08h
et10
bt11			dt				05h,0Ah,05h,0Ah,0Fh,0Ah,0Fh,05h,0Fh,05h,0Fh
et11
bt12			dt				01h,02h,04h,08h,03h,06h,0Ch,07h,0Eh,0Fh,0Eh,07h,0Ch,06h,03h,08h,04h,02h
et12
bt13			dt				0Fh,07h,0Fh,07h,0Fh,0Bh,0Fh,0Bh,0Fh,0Dh,0Fh,0Dh,0Fh,0Eh,0Fh,0Eh
et13
bt14			dt				0Fh,0Ch,0Fh,0Ch,0Fh,09h,0Fh,09h,0Fh,03h,0Fh,03h
et14
bt15			dt				01h,02h,04h,08h,04h,02h,01h,02h,04h,08h,04h,02h
et15
;
				org				200h
;
bt16			dt				0Fh,01h,0Fh,01h,0Fh,02h,0Fh,02h,0Fh,04h,0Fh,04h,0Fh,08h,0Fh,08h
et16
bt17			dt				0Fh,07h,0Fh,07h,0Fh,0Bh,0Fh,0Bh,0Fh,0Dh,0Fh,0Dh,0Fh,0Eh,0Fh,0Eh
et17
bt18			dt				0Fh,07h,0Fh,07h,0Fh,0Bh,0Fh,0Bh,0Fh,0Dh,0Fh,0Dh,0Fh,0Eh,0Fh,0Eh
et18
bt19			dt				01h,02h,04h,08h,09h,0Ah,0Ch,0Dh,0Eh,0Fh,07h,0Bh,03h,05h,09h,01h,02h,04h,08h,00h
et19
bt20			dt				01h,02h,04h,08h,03h,06h,0Ch,07h,0Eh,0Fh,0Eh,07h,0Ch,06h,03h,08h,04h,02h
et20
;
				org				3ffh
				retlw			0d4h
;
				end
