#include P16F628.INC
;
               __config        0x3f29
;
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
;
out_byte		EQU		2eh
;
tmp2			EQU		2fh
;
cnt6			EQU		30h
cnt7			EQU		31h
push_w			EQU		32h
;
cnt_prog		EQU		33h
;
tmpLO			EQU		34h
tmpHI			EQU		35h
;
flag_int		EQU		36h
;
cnt_tmr1		EQU		37h
;
ppp				EQU		38h
;
cnt_tmr2		EQU		39h
;
INIT_PORTA		EQU		b'00000000'	
INIT_PORTB		EQU		b'00000110'
;
;

				goto			begin
;
;
				org    			4		
;
				btfsc  			PIR1,RCIF	
				movwf			push_w
				bsf				flag_int,0
				movf			RCREG,0
				movwf			out_byte	
				bcf				T1CON,TMR1ON
				bcf				T2CON,TMR2ON
				bcf				PIR1,RCIF
				call			out
				bcf 			STATUS,RP1
				bcf 			STATUS,RP0
				clrf			TMR1H
				clrf			TMR1L
				clrf			TMR2
				movf			push_w,0
				bcf				PIR1,RCIF
				bsf				T1CON,TMR1ON
				retfie
;
;
out
				movf			out_byte,0
				movwf			tmpLO
				movwf			tmpHI
				movlw			B'00001111'
				andwf			tmpLO,0	
				movwf			PORTA	
				movlw			B'11110110'
				andwf			tmpHI,0
				movwf			PORTB	
				return
;
;
Init
				clrf			flag_int
				clrf 			PORTA
				clrf			PORTB
				clrf 			STATUS
				bcf 			STATUS,RP1
				bcf 			STATUS,RP0
				movlw			07h
				movwf			CMCON
				bcf				INTCON,GIE
				movlw			b'11000000'	
				movwf			INTCON	
				movlw			b'00000011'
				movwf			T2CON
				clrf			TMR2
				movlw			b'00110000'
				movwf			T1CON
				clrf			TMR1H
				clrf			TMR1L
				bcf 			STATUS,RP1
				bsf 			STATUS,RP0
				movlw 			INIT_PORTA
				movwf 			TRISA^80h
				movlw 			INIT_PORTB
				movwf 			TRISB^80h
				bsf				PIE1^80h,RCIE	
				bcf				PIE1^80h,TMR1IE	
				bcf				PIE1^80h,TMR2IE	
				movlw 			.103			
				movwf 			SPBRG^80h
				movlw			b'00100100'	
				movwf 			TXSTA^80h	
				bcf 			STATUS,RP1
				bcf 			STATUS,RP0
				movlw			b'10010000'	
				movwf			RCSTA
				movlw			0ah
				movwf			cnt_tmr1
				movlw			0ffh
				movwf			cnt_tmr2
				return
;
Init2
				clrf			len_tb
				clrf			adrHI
				clrf			adrLO
				clrf			cnt_cikl
				clrf			cnt_adr
				movlw			09h
				movwf			mem
				movlw			15h
				movwf			cnt_prog
				movlw			0h
				movwf			n_tabl
				return
;
;
begin			
				call 			Init
delay_beg		
				bcf				flag_int,0
				bcf				flag_int,1
pause2
				bsf				T1CON,TMR1ON
				bcf				T2CON,TMR2ON
				bcf				flag_int,0
test			
				btfss			PIR1,TMR1IF
				goto			test
				bcf				PIR1,TMR1IF
				decfsz 			cnt_tmr1,1
				goto			test
				movlw			0ah
				movwf			cnt_tmr1
				bcf				T1CON,TMR1ON
				bcf				T1CON,TMR1ON
				bcf 			STATUS,RP1
				bcf 			STATUS,RP0
				clrf			TMR1H
				clrf			TMR1L
				clrf			TMR2
				call 			Init2
;								
;
new_tb
				movlw			5h
				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			
				bsf				T2CON,TMR2ON
pause
				btfsc			flag_int,0
				goto			pause2
				btfss			PIR1,TMR2IF
				goto			pause
				bcf				PIR1,TMR2IF
				decfsz 			cnt_tmr2,1
				goto			pause
				movlw			0ffh
				movwf			cnt_tmr2
				bcf				T2CON,TMR2ON
				bcf 			STATUS,RP1
				bcf 			STATUS,RP0
				clrf			TMR2
;				
				movf			PCLATH,0
				movwf			tmp2
				movf			adrHI,0
				movwf			PCLATH
				movf			adrLO,0
				call			led
				movwf			out_byte
				btfsc			flag_int,0
				goto			pause2
				call			out
				movf			tmp2,0
				movwf			PCLATH
				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			15h
				movwf			cnt_prog
				movlw			0h
				movwf			n_tabl
				goto			new_tb
;
;
adr_tb			addwf			PCL,1
				dt				high(bt0),low(bt0),low(et0)-low(bt0)
				dt				high(bt1),low(bt1),low(et1)-low(bt1)
				dt				high(bt2),low(bt2),low(et2)-low(bt2)
				dt				high(bt3),low(bt3),low(et3)-low(bt3)
				dt				high(bt4),low(bt4),low(et4)-low(bt4)
				dt				high(bt5),low(bt5),low(et5)-low(bt5)
				dt				high(bt6),low(bt6),low(et6)-low(bt6)
				dt				high(bt7),low(bt7),low(et7)-low(bt7)
				dt				high(bt8),low(bt8),low(et8)-low(bt8)
				dt				high(bt9),low(bt9),low(et9)-low(bt9)
				dt				high(bt10),low(bt10),low(et10)-low(bt10)
				dt				high(bt11),low(bt11),low(et11)-low(bt11)
				dt				high(bt12),low(bt12),low(et12)-low(bt12)
				dt				high(bt13),low(bt13),low(et13)-low(bt13)
				dt				high(bt14),low(bt14),low(et14)-low(bt14)
				dt				high(bt15),low(bt15),low(et15)-low(bt15)
				dt				high(bt16),low(bt16),low(et16)-low(bt16)
				dt				high(bt17),low(bt17),low(et17)-low(bt17)
				dt				high(bt18),low(bt18),low(et18)-low(bt18)
				dt				high(bt19),low(bt19),low(et19)-low(bt19)
				dt				high(bt20),low(bt20),low(et20)-low(bt20)
;
;
				org 			100h
;
led				
				movwf			PCL
bt0				dt				01h,02h,04h,08h,10h,20h,40h,80h,0C0h,60h,30h,18h,0Ch,06h,03h,07h,0Eh,1Ch,38h,70h,0E0h,0e0h,78h,3Ch,1Eh,0Fh,1Fh,3Eh,7Ch,0F8h,0FCh,7Eh,3Fh,7Fh,0FEh,0FFh
et0
bt1				dt				80h,0C0h,0E0h,0F0h,0F8h,0FCh,0FEh,0FFh,7Fh,3Fh,1Fh,0Fh,07h,03h,01h
et1
bt2				dt				01h,02h,04h,08h,10h,20h,40h,80h,40h,20h,10h,08h,04h,02h
et2
bt3				dt				0FFh,7Fh,0BFh,0DFh,0EFh,0F7h,0FBh,0FDh,0FEh,0FFh,7Fh,0BFh,0DFh,0EFh,0F7h,0FBh,0FDh,0FEh
et3
bt4				dt				81h,42h,24h,18h,24h,42h,81h,0C3h,66h,3Ch,18h,3Ch,66h,0C3h,0E7h,7Eh,3Ch,7Eh,0E7h,0FFh
et4
bt5				dt				81h,42h,24h,18h,3Ch,7Eh,0FFh,81h,42h,24h,18h,3Ch,7Eh,0FFh
et5
bt6				dt				81h,42h,24h,18h,99h,5Ah,3Ch,0BDh,7Eh,0FFh,0E7h,0DBh,0BDh,7Eh,66h,5Ah,3Ch,24h,18h,00h
et6
bt7				dt				01h,05h,15h,55h,80h,0A0h,0A8h,0AAh,01h,05h,15h,55h,80h,0A0h,0A8h,0AAh
et7
bt8				dt				80h,40h,20h,10h,08h,04h,02h,01h,00h,80h,0C0h,0E0h,0F0h,0F8h,0FCh,0FEh,0FFh,00h
et8
bt9				dt				80h,0C0h,0E0h,0F0h,0F8h,0FCh,0FEh,0FFh,0FEh,0FCh,0F8h,0F0h,0E0h,0C0h
et9
bt10			dt				80h,81h,0C1h,0C3h,0E3h,0E7h,0F7h,0FFh,7Fh,7Eh,3Eh,3Ch,1Ch,18h,08h,00h
et10
bt11			dt				81h,42h,24h,18h,99h,5Ah,3Ch,0BDh,7Eh,0FFh,0E7h,0DBh,0BDh,7Eh,66h,5Ah,3Ch,24h,18h,00h
et11
bt12			dt				80h,40h,20h,10h,08h,04h,02h,01h,81h,41h,21h,11h,09h,05h,03h,83h,43h,23h,13h,0Bh,07h,87h,47h,27h,17h,0Fh,8Fh,4Fh,2Fh,1Fh,9Fh,5Fh,3Fh,0BFh,7Fh,0FFh
et12
;
				org 			200h
;
bt13			dt				81h,42h,24h,18h,99h,5Ah,3Ch,0BDh,7Eh,0FFh,0E7h,0DBh,0BDh,7Eh,66h,5Ah,3Ch,24h,18h,00h
et13
bt14			dt				0FFh,7Fh,0BFh,0DFh,0EFh,0F7h,0FBh,0FDh,0FEh,0FFh,7Fh,0BFh,0DFh,0EFh,0F7h,0FBh,0FDh,0FEh
et14
bt15			dt				01h,02h,04h,08h,10h,20h,40h,80h,40h,20h,10h,08h,04h,02h
et15
bt16			dt				81h,42h,24h,18h,3Ch,7Eh,0FFh,81h,42h,24h,18h,3Ch,7Eh,0FFh
et16
bt17			dt				01h,05h,15h,55h,80h,0A0h,0A8h,0AAh,01h,05h,15h,55h,80h,0A0h,0A8h,0AAh
et17
bt18			dt				80h,0C0h,0E0h,0F0h,0F8h,0FCh,0FEh,0FFh,0FEh,0FCh,0F8h,0F0h,0E0h,0C0h
et18
bt19			dt				80h,40h,20h,10h,08h,04h,02h,01h,81h,41h,21h,11h,09h,05h,03h,83h,43h,23h,13h,0Bh,07h,87h,47h,27h,17h,0Fh,8Fh,4Fh,2Fh,1Fh,9Fh,5Fh,3Fh,0BFh,7Fh,0FFh
et19
bt20			dt				81h,42h,24h,18h,99h,5Ah,3Ch,0BDh,7Eh,0FFh,0E7h,0DBh,0BDh,7Eh,66h,5Ah,3Ch,24h,18h,00h
et20
;
				end
