;---------------------------------------------------------------------------
; egy kis semmiseg 2x16-os LCD modulra karaktert kiirni 4x4-es keymatrixrol
; +egy AD9835-ot vezerelni hexaval
;---------------------------------------------------------------------------
;
	list 	p=16f877a
	ERRORLEVEL-302
	ERRORLEVEL-205
	#include	<p16f877a.inc>
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _LVP_OFF
		org	0x00
;
;---------------------------------------------------------------------------
;	PORTB =>	4X4 KEYMATRIX:				PORTC => 2X16 caracters LCD modul
;		RB0	<=>	"M" (horizontal)			RC0 <= no connection
;		RB1	<=>	"L" (horizontal)			RC1 <= Read/Write
;		RB2	<=>	"K" (horizontal)			RC2 => "RS" (register select)
;		RB3	<=>	"J" (horizontal)			RC3 => "E"  (register select)
;		RB4	<=>	"E" (vertical)				RC4 => "D4"
;		RB5	<=>	"F" (vertical)				RC5 => "D5"
;		RB6	<=>	"G" (vertical)				RC6 => "D6"
;		RB7	<=>	"H" (vertical)				RC7 => "D7"
;
;	PORTA =>	DDS
;		RA0=SCLK	RA1=SDATA	RA2=FSYNC
;
;	clock=>		20 Megas kvarc
;---------------------------------------------------------------------------
;
;datacourse				
    bsf     STATUS,RP0      ;bank 1
    bcf     STATUS,RP1
	movlw b'00000110'
	movwf ADCON1			;E port digitalisa' konfiguralasa
	movlw	b'11111000'
	movwf	TRISA		
	movlw	b'11110000'
	movwf	TRISB
	movlw	b'00000001'
	movwf	TRISC
;	movlw	b'00000000'
;	movwf	TRISD
;	movlw	b'00000000'
;	movwf	TRISE
	bcf		OPTION_REG,7	;RBPU bittel felhuzoellenallas be
	bcf     STATUS,RP0      ;bank 0
;
;	regiszterek
cblock	0x20
timer1
timer2
timer3
temp1
temp2
ktemp1
ktemp2
puffer
pcounter
pcounter2
hm
lm
hl
ll
	endc
MAIN
	movlw	b'00110011'
	movwf	temp1
	movlw	d'5'
	movwf	temp2
	call	DDSKI
	movlw	b'00100010'
	movwf	temp1
	movlw	d'30'
	movwf	temp2
	call	DDSKI
	movlw	b'00110001'
	movwf	temp1
	movlw	d'184'
	movwf	temp2
	call	DDSKI
	movlw	b'00100000'
	movwf	temp1
	movlw	d'82'
	movwf	temp2
	call	DDSKI
;	clrf	PORTA
;	clrf	pcounter
;	clrf	PORTE
;	call	ON
	call	FUNK
	call	DELETE
	call	DSCURS
	call	DELETE
	call 	INTRO1
	call	T4
	call	DELETE
	call 	INTRO2
	call	T4
	call	DELETE
	call	DDSWPAD
	goto	KEYB
INTRO1
	movlw	'D'
	call	LCDOUTC
	movlw	'i'
	call	LCDOUTC
	movlw	'r'
	call	LCDOUTC
	movlw	'e'
	call	LCDOUTC
	movlw	'c'
	call	LCDOUTC
	movlw	't'
	call	LCDOUTC
	movlw	' '
	call	LCDOUTC
	movlw	'D'
	call	LCDOUTC
	movlw	'i'
	call	LCDOUTC
	movlw	'g'
	call	LCDOUTC
	movlw	'i'
	call	LCDOUTC
	movlw	't'
	call	LCDOUTC
	movlw	'a'
	call	LCDOUTC
	movlw	'l'
	call	LCDOUTC
	movlw	b'10101000'
	call	LCDOUTI
	movlw	'S'
	call	LCDOUTC
	movlw	'y'
	call	LCDOUTC
	movlw	'n'
	call	LCDOUTC
	movlw	't'
	call	LCDOUTC
	movlw	'h'
	call	LCDOUTC
	movlw	'e'
	call	LCDOUTC
	movlw	's'
	call	LCDOUTC
	movlw	'y'
	call	LCDOUTC
	movlw	's'
	call	LCDOUTC
	return
;
INTRO2
	movlw	' '
	call	LCDOUTC
	movlw	' '
	call	LCDOUTC
	movlw	' '
	call	LCDOUTC
	movlw	'D'
	call	LCDOUTC
	movlw	'D'
	call	LCDOUTC
	movlw	'S'
	call	LCDOUTC
	movlw	' '
	call	LCDOUTC
	movlw	'w'
	call	LCDOUTC
	movlw	'i'
	call	LCDOUTC
	movlw	'd'
	call	LCDOUTC
	movlw	'h'
	call	LCDOUTC
	movlw	't'
	call	LCDOUTC
	movlw	b'10101000'
	call	LCDOUTI
	movlw	' '
	call	LCDOUTC
	movlw	' '
	call	LCDOUTC
	movlw	' '
	call	LCDOUTC
	movlw	'A'
	call	LCDOUTC
	movlw	'D'
	call	LCDOUTC
	movlw	'9'
	call	LCDOUTC
	movlw	'8'
	call	LCDOUTC
	movlw	'3'
	call	LCDOUTC
	movlw	'5'
	call	LCDOUTC
	movlw	'B'
	call	LCDOUTC
	movlw	'R'
	call	LCDOUTC
	movlw	'R'
	call	LCDOUTC
	movlw	'U'
	call	LCDOUTC
	movlw	'Z'
	call	LCDOUTC
	return
DDSWPAD
	movlw	'T'
	call	LCDOUTC
	movlw	'u'
	call	LCDOUTC
	movlw	'n'
	call	LCDOUTC
	movlw	'i'
	call	LCDOUTC
	movlw	'n'
	call	LCDOUTC
	movlw	'g'
	call	LCDOUTC
	movlw	' '
	call	LCDOUTC
	movlw	'W'
	call	LCDOUTC
	movlw	'o'
	call	LCDOUTC
	movlw	'r'
	call	LCDOUTC
	movlw	'd'
	call	LCDOUTC
	movlw	b'10101000'
	call	LCDOUTI
	movlw	'H'
	call	LCDOUTC
	movlw	'E'
	call	LCDOUTC
	movlw	'X'
	call	LCDOUTC
	movlw	':'
	call	LCDOUTC
	movlw	b'00001111'
	call	LCDOUTI
	return
;------------------------	;billentyuzet olvasas
KEYB
	clrf	PORTB
    bsf     STATUS,RP0      ;bank 1
    bcf     STATUS,RP1
	movlw	b'11110000'
	movwf	TRISB
	bcf     STATUS,RP0      ;bank 0
ETEST
	btfsc	PORTB,4	;E
	goto	FTEST
	goto	JUMPE
FTEST
	btfsc	PORTB,5	;F
	goto	GTEST
	goto	JUMPF
GTEST
	btfsc	PORTB,6	;G
	goto	HTEST
	goto	JUMPG
HTEST
	btfsc	PORTB,7	;H
	goto	ETEST
	goto	JUMPH
JUMPE
	movlw	b'00000001'
	movwf	ktemp1
    bsf     STATUS,RP0      ;bank 1
    bcf     STATUS,RP1
	swapf	TRISB,1
	bcf     STATUS,RP0      ;bank 0
	goto	SWAT
JUMPF
	movlw	b'00000010'
	movwf	ktemp1
    bsf     STATUS,RP0      ;bank 1
    bcf     STATUS,RP1
	swapf	TRISB,1
	bcf     STATUS,RP0      ;bank 0
	goto	SWAT
JUMPG
	movlw	b'00000100'
	movwf	ktemp1
    bsf     STATUS,RP0      ;bank 1
    bcf     STATUS,RP1
	swapf	TRISB,1
	bcf     STATUS,RP0      ;bank 0
	goto	SWAT
JUMPH
	movlw	b'00001000'
	movwf	ktemp1
    bsf     STATUS,RP0      ;bank 1
    bcf     STATUS,RP1
	swapf	TRISB,1
	bcf     STATUS,RP0      ;bank 0
	goto	SWAT
SWAT
	nop
MTEST
	btfsc	PORTB,0	;M
	goto	LTEST
	goto	JUMPM
LTEST
	btfsc	PORTB,1	;L
	goto	KTEST
	goto	JUMPL
KTEST
	btfsc	PORTB,2	;K
	goto	JTEST
	goto	JUMPK
JTEST
	btfsc	PORTB,3	;J
	goto	HIBA
	goto	JUMPJ
JUMPM
	bsf		ktemp1,4
	goto	VALID
JUMPL
	bsf		ktemp1,5
	goto	VALID
JUMPK
	bsf		ktemp1,6
	goto	VALID
JUMPJ
	bsf		ktemp1,7
	goto	VALID
VALID
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00010010'
	xorwf	ktemp2,1		;0
	btfsc	ktemp2,7
	goto	TEST1
	btfsc	ktemp2,6
	goto	TEST1
	btfsc	ktemp2,5
	goto	TEST1
	btfsc	ktemp2,4
	goto	TEST1
	btfsc	ktemp2,3
	goto	TEST1
	btfsc	ktemp2,2
	goto	TEST1
	btfsc	ktemp2,1
	goto	TEST1
	btfsc	ktemp2,0
	goto	TEST1
	goto	VA0
TEST1
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'10000001'
	xorwf	ktemp2,1		;1
	btfsc	ktemp2,7
	goto	TEST2
	btfsc	ktemp2,6
	goto	TEST2
	btfsc	ktemp2,5
	goto	TEST2
	btfsc	ktemp2,4
	goto	TEST2
	btfsc	ktemp2,3
	goto	TEST2
	btfsc	ktemp2,2
	goto	TEST2
	btfsc	ktemp2,1
	goto	TEST2
	btfsc	ktemp2,0
	goto	TEST2
	goto	VA1
TEST2
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'10000010'
	xorwf	ktemp2,1		;2
	btfsc	ktemp2,7
	goto	TEST3
	btfsc	ktemp2,6
	goto	TEST3
	btfsc	ktemp2,5
	goto	TEST3
	btfsc	ktemp2,4
	goto	TEST3
	btfsc	ktemp2,3
	goto	TEST3
	btfsc	ktemp2,2
	goto	TEST3
	btfsc	ktemp2,1
	goto	TEST3
	btfsc	ktemp2,0
	goto	TEST3
	goto	VA2
TEST3
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'10000100'	;b'01000001'
	xorwf	ktemp2,1		;3
	btfsc	ktemp2,7
	goto	TEST4
	btfsc	ktemp2,6
	goto	TEST4
	btfsc	ktemp2,5
	goto	TEST4
	btfsc	ktemp2,4
	goto	TEST4
	btfsc	ktemp2,3
	goto	TEST4
	btfsc	ktemp2,2
	goto	TEST4
	btfsc	ktemp2,1
	goto	TEST4
	btfsc	ktemp2,0
	goto	TEST4
	goto	VA3
TEST4
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'01000001'	;b'10000100'
	xorwf	ktemp2,1		;4
	btfsc	ktemp2,7
	goto	TEST5
	btfsc	ktemp2,6
	goto	TEST5
	btfsc	ktemp2,5
	goto	TEST5
	btfsc	ktemp2,4
	goto	TEST5
	btfsc	ktemp2,3
	goto	TEST5
	btfsc	ktemp2,2
	goto	TEST5
	btfsc	ktemp2,1
	goto	TEST5
	btfsc	ktemp2,0
	goto	TEST5
	goto	VA4
TEST5
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'01000010'
	xorwf	ktemp2,1		;5
	btfsc	ktemp2,7
	goto	TEST6
	btfsc	ktemp2,6
	goto	TEST6
	btfsc	ktemp2,5
	goto	TEST6
	btfsc	ktemp2,4
	goto	TEST6
	btfsc	ktemp2,3
	goto	TEST6
	btfsc	ktemp2,2
	goto	TEST6
	btfsc	ktemp2,1
	goto	TEST6
	btfsc	ktemp2,0
	goto	TEST6
	goto	VA5
TEST6
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'01000100'
	xorwf	ktemp2,1		;6
	btfsc	ktemp2,7
	goto	TEST7
	btfsc	ktemp2,6
	goto	TEST7
	btfsc	ktemp2,5
	goto	TEST7
	btfsc	ktemp2,4
	goto	TEST7
	btfsc	ktemp2,3
	goto	TEST7
	btfsc	ktemp2,2
	goto	TEST7
	btfsc	ktemp2,1
	goto	TEST7
	btfsc	ktemp2,0
	goto	TEST7
	goto	VA6
TEST7
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00100001'
	xorwf	ktemp2,1		;7
	btfsc	ktemp2,7
	goto	TEST8
	btfsc	ktemp2,6
	goto	TEST8
	btfsc	ktemp2,5
	goto	TEST8
	btfsc	ktemp2,4
	goto	TEST8
	btfsc	ktemp2,3
	goto	TEST8
	btfsc	ktemp2,2
	goto	TEST8
	btfsc	ktemp2,1
	goto	TEST8
	btfsc	ktemp2,0
	goto	TEST8
	goto	VA7
TEST8
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00100010'
	xorwf	ktemp2,1		;8
	btfsc	ktemp2,7
	goto	TEST9
	btfsc	ktemp2,6
	goto	TEST9
	btfsc	ktemp2,5
	goto	TEST9
	btfsc	ktemp2,4
	goto	TEST9
	btfsc	ktemp2,3
	goto	TEST9
	btfsc	ktemp2,2
	goto	TEST9
	btfsc	ktemp2,1
	goto	TEST9
	btfsc	ktemp2,0
	goto	TEST9
	goto	VA8
TEST9
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00100100'
	xorwf	ktemp2,1		;9
	btfsc	ktemp2,7
	goto	TESTA
	btfsc	ktemp2,6
	goto	TESTA
	btfsc	ktemp2,5
	goto	TESTA
	btfsc	ktemp2,4
	goto	TESTA
	btfsc	ktemp2,3
	goto	TESTA
	btfsc	ktemp2,2
	goto	TESTA
	btfsc	ktemp2,1
	goto	TESTA
	btfsc	ktemp2,0
	goto	TESTA
	goto	VA9
TESTA
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00010001'
	xorwf	ktemp2,1		;A
	btfsc	ktemp2,7
	goto	TESTB
	btfsc	ktemp2,6
	goto	TESTB
	btfsc	ktemp2,5
	goto	TESTB
	btfsc	ktemp2,4
	goto	TESTB
	btfsc	ktemp2,3
	goto	TESTB
	btfsc	ktemp2,2
	goto	TESTB
	btfsc	ktemp2,1
	goto	TESTB
	btfsc	ktemp2,0
	goto	TESTB
	goto	VAA
TESTB
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00010100'
	xorwf	ktemp2,1		;B
	btfsc	ktemp2,7
	goto	TESTC
	btfsc	ktemp2,6
	goto	TESTC
	btfsc	ktemp2,5
	goto	TESTC
	btfsc	ktemp2,4
	goto	TESTC
	btfsc	ktemp2,3
	goto	TESTC
	btfsc	ktemp2,2
	goto	TESTC
	btfsc	ktemp2,1
	goto	TESTC
	btfsc	ktemp2,0
	goto	TESTC
	goto	VAB
TESTC
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00011000'
	xorwf	ktemp2,1		;C
	btfsc	ktemp2,7
	goto	TESTD
	btfsc	ktemp2,6
	goto	TESTD
	btfsc	ktemp2,5
	goto	TESTD
	btfsc	ktemp2,4
	goto	TESTD
	btfsc	ktemp2,3
	goto	TESTD
	btfsc	ktemp2,2
	goto	TESTD
	btfsc	ktemp2,1
	goto	TESTD
	btfsc	ktemp2,0
	goto	TESTD
	goto	VAC
TESTD
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'00101000'
	xorwf	ktemp2,1		;D
	btfsc	ktemp2,7
	goto	TESTE
	btfsc	ktemp2,6
	goto	TESTE
	btfsc	ktemp2,5
	goto	TESTE
	btfsc	ktemp2,4
	goto	TESTE
	btfsc	ktemp2,3
	goto	TESTE
	btfsc	ktemp2,2
	goto	TESTE
	btfsc	ktemp2,1
	goto	TESTE
	btfsc	ktemp2,0
	goto	TESTE
	goto	VAD
TESTE
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'01001000'
	xorwf	ktemp2,1		;E
	btfsc	ktemp2,7
	goto	TESTF
	btfsc	ktemp2,6
	goto	TESTF
	btfsc	ktemp2,5
	goto	TESTF
	btfsc	ktemp2,4
	goto	TESTF
	btfsc	ktemp2,3
	goto	TESTF
	btfsc	ktemp2,2
	goto	TESTF
	btfsc	ktemp2,1
	goto	TESTF
	btfsc	ktemp2,0
	goto	TESTF
	goto	VAE
TESTF
	movf	ktemp1,0
	movwf	ktemp2
	movlw	b'10001000'
	xorwf	ktemp2,1		;F
	btfsc	ktemp2,7
	goto	HIBA
	btfsc	ktemp2,6
	goto	HIBA
	btfsc	ktemp2,5
	goto	HIBA
	btfsc	ktemp2,4
	goto	HIBA
	btfsc	ktemp2,3
	goto	HIBA
	btfsc	ktemp2,2
	goto	HIBA
	btfsc	ktemp2,1
	goto	HIBA
	btfsc	ktemp2,0
	goto	HIBA
	goto	VAF
VA0
	movlw	'0'
	call	LCDOUTC
	movlw	d'0'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA1
	movlw	'1'
	call	LCDOUTC
	movlw	d'1'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA2
	movlw	'2'
	call	LCDOUTC
	movlw	d'2'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA3
	movlw	'3'
	call	LCDOUTC
	movlw	d'3'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA4
	movlw	'4'
	call	LCDOUTC
	movlw	d'4'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA5
	movlw	'5'
	call	LCDOUTC
	movlw	d'5'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA6
	movlw	'6'
	call	LCDOUTC
	movlw	d'6'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA7
	movlw	'7'
	call	LCDOUTC
	movlw	d'7'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA8
	movlw	'8'
	call	LCDOUTC
	movlw	d'8'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VA9
	movlw	'9'
	call	LCDOUTC
	movlw	d'9'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VAA
	movlw	'A'
	call	LCDOUTC
	movlw	h'A'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VAB
	movlw	'B'
	call	LCDOUTC
	movlw	h'B'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VAC
	movlw	'C'
	call	LCDOUTC
	movlw	h'C'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VAD
	movlw	'D'
	call	LCDOUTC
	movlw	h'D'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VAE
	movlw	'E'
	call	LCDOUTC
	movlw	h'E'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
VAF
	movlw	'F'
	call	LCDOUTC
	movlw	h'F'
	movwf	puffer
	incf	pcounter,1
	call	T5
	clrf	ktemp1
	clrf	ktemp2
	call	DDS
	goto	KEYB
HIBA
	clrf	ktemp1
	goto	KEYB
;
;-----------------------
ON
	call	T1
	movlw	b'00111000'
	movwf	PORTC
	call	T2
	bcf		PORTC,3
	call	T1
	bsf		PORTC,3
	call	T2
	bcf		PORTC,3
	call	T2
	bsf		PORTC,3
	call	T2
	bcf		PORTC,3
	call	T3
	call	FUNK
	call	DSCURS
	call	DELETE
	return
FUNK
	movlw	b'00001110'
	call	LCDOUTI
	call	T1
	movlw	b'00100000'
	call	LCDOUTI
	call	T1
	movlw	b'00101000'
	call	LCDOUTI
	call	T1
	return
DSCURS
	movlw	b'00001100'
	call	LCDOUTI
	return
DELETE
	movlw	b'00000001'
	call	LCDOUTI
	return
;
LCDOUTC
	movwf	temp1
	movwf	temp2
;	bsf		PORTC,3	;E
;	bsf		PORTC,2	;RS
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bsf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T3
	bcf		PORTC,3
	call	T3
	bsf		PORTC,3	;E
	bsf		PORTC,2	;RS
	movf	temp1,0
	movwf	temp2
	swapf	temp2,1
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bsf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T3
	bcf		PORTC,3
	call	T3
	bsf		PORTC,3
	return
;
LCDOUTI
	movwf	temp1
	movwf	temp2
;	bsf		PORTC,3	;E
;	bsf		PORTC,2	;RS
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bcf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T2
	bcf		PORTC,3
	call	T2
	bsf		PORTC,3	;E
	bcf		PORTC,2	;RS
	movf	temp1,0
	movwf	temp2
	swapf	temp2,1
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bcf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T2
	bcf		PORTC,3
	call	T2
	bsf		PORTC,3		
	return
;
;
;LED
;	bsf		PORTA,0		;!!!!!
;	call	T2
;	bcf		PORTA,0
;	return
;
;
DDS
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'1'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	TV1
	btfsc	pcounter2,2
	goto	TV1
	btfsc	pcounter2,1
	goto	TV1
	btfsc	pcounter2,0
	goto	TV1
	goto	SETHMU
TV1
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'2'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	TV2
	btfsc	pcounter2,2
	goto	TV2
	btfsc	pcounter2,1
	goto	TV2
	btfsc	pcounter2,0
	goto	TV2
	goto	SETHMD
TV2
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'3'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	TV3
	btfsc	pcounter2,2
	goto	TV3
	btfsc	pcounter2,1
	goto	TV3
	btfsc	pcounter2,0
	goto	TV3
	goto	SETLMU
TV3
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'4'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	TV4
	btfsc	pcounter2,2
	goto	TV4
	btfsc	pcounter2,1
	goto	TV4
	btfsc	pcounter2,0
	goto	TV4
	goto	SETLMD
TV4
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'5'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	TV5
	btfsc	pcounter2,2
	goto	TV5
	btfsc	pcounter2,1
	goto	TV5
	btfsc	pcounter2,0
	goto	TV5
	goto	SETHLU
TV5
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'6'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	TV6
	btfsc	pcounter2,2
	goto	TV6
	btfsc	pcounter2,1
	goto	TV6
	btfsc	pcounter2,0
	goto	TV6
	goto	SETHLD
TV6
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'7'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	TV7
	btfsc	pcounter2,2
	goto	TV7
	btfsc	pcounter2,1
	goto	TV7
	btfsc	pcounter2,0
	goto	TV7
	goto	SETLLU
TV7
	movf	pcounter,0
	movwf	pcounter2
	movlw	d'8'
	xorwf	pcounter2,1
	btfsc	pcounter2,3
	goto	CLEAR
	btfsc	pcounter2,2
	goto	CLEAR
	btfsc	pcounter2,1
	goto	CLEAR
	btfsc	pcounter2,0
	goto	CLEAR
	goto	SETLLD
CLEAR
	call	DELETE
	call	DDSWPAD
	clrf	hm
	clrf	lm
	clrf	hl
	clrf	ll
	clrf	pcounter2
	clrf	pcounter
	goto	KEYB
SETHMU
	swapf	puffer,1
	movf	puffer,0
	movwf	hm
	goto	KEYB
SETHMD
	bsf		hm,3
	bsf		hm,2	
	bsf		hm,1
	bsf		hm,0
	bsf		puffer,7
	bsf		puffer,6
	bsf		puffer,5
	bsf		puffer,4
	movf	puffer,0
	andwf	hm,1
	goto	KEYB
;
SETLMU
	swapf	puffer,1
	movf	puffer,0
	movwf	lm
	goto	KEYB
SETLMD
	bsf		lm,3
	bsf		lm,2	
	bsf		lm,1
	bsf		lm,0
	bsf		puffer,7
	bsf		puffer,6
	bsf		puffer,5
	bsf		puffer,4
	movf	puffer,0
	andwf	lm,1
	goto	KEYB
;
SETHLU
	swapf	puffer,1
	movf	puffer,0
	movwf	hl
	goto	KEYB
SETHLD
	bsf		hl,3
	bsf		hl,2	
	bsf		hl,1
	bsf		hl,0
	bsf		puffer,7
	bsf		puffer,6
	bsf		puffer,5
	bsf		puffer,4
	movf	puffer,0
	andwf	hl,1
	goto	KEYB
;
SETLLU
	swapf	puffer,1
	movf	puffer,0
	movwf	ll
	goto	KEYB
SETLLD
	bsf		ll,3
	bsf		ll,2	
	bsf		ll,1
	bsf		ll,0
	bsf		puffer,7
	bsf		puffer,6
	bsf		puffer,5
	bsf		puffer,4
	movf	puffer,0
	andwf	ll,1
	call	DDSTUNING
	goto	KEYB
	return
;
;
DDSTUNING
;	call	LED			;!!!!!!!!
	movlw	b'11111000'
	movwf	temp1
	movlw	d'0'
	movwf	temp2
	call	DDSKI
	movlw	b'00110011'
	movwf	temp1
	movf	hm,0
	movwf	temp2
	call	DDSKI
	movlw	b'00100010'
	movwf	temp1
	movf	lm,0
	movwf	temp2
	call	DDSKI
	movlw	b'00110001'
	movwf	temp1
	movf	hl,0
	movwf	temp2
	call	DDSKI
	movlw	b'00100000'
	movwf	temp1
	movf	ll,0
	movwf	temp2
	call	DDSKI
	movlw	b'11000000'
	movwf	temp1
	movlw	d'0'
	movwf	temp2
	call	DDSKI
	return
DDSKI
	bsf		PORTA,2
	bcf		PORTA,2
	bsf		PORTA,0
;
	btfsc	temp1,7
	bsf		PORTA,1
	btfss	temp1,7
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp1,6
	bsf		PORTA,1
	btfss	temp1,6
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp1,5
	bsf		PORTA,1
	btfss	temp1,5
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp1,4
	bsf		PORTA,1
	btfss	temp1,4
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp1,3
	bsf		PORTA,1
	btfss	temp1,3
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp1,2
	bsf		PORTA,1
	btfss	temp1,2
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp1,1
	bsf		PORTA,1
	btfss	temp1,1
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp1,0
	bsf		PORTA,1
	btfss	temp1,0
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
;
;
;
	btfsc	temp2,7
	bsf		PORTA,1
	btfss	temp2,7
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp2,6
	bsf		PORTA,1
	btfss	temp2,6
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp2,5
	bsf		PORTA,1
	btfss	temp2,5
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp2,4
	bsf		PORTA,1
	btfss	temp2,4
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp2,3
	bsf		PORTA,1
	btfss	temp2,3
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp2,2
	bsf		PORTA,1
	btfss	temp2,2
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp2,1
	bsf		PORTA,1
	btfss	temp2,1
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
	btfsc	temp2,0
	bsf		PORTA,1
	btfss	temp2,0
	bcf		PORTA,1
	bcf		PORTA,0
	bsf		PORTA,0
;
;
	bsf		PORTA,2
	return
;-------------------------------------
T1
	movlw	d'255'	; dec.255
	movwf	timer1
	call	TIMER
	return
;--------------------------------------
T2
	movlw	d'16'	; dec16	
	movwf	timer1
	call	TIMER
	return
;-------------------------------------
T3
	movlw	d'2'	; dec2
	movwf	timer1
	call	TIMER
	return
;-------------------------------------
T4
	movlw	d'200'	;d200
	movwf	timer3
T4B
	decfsz	timer3,1
	goto	T4A
	return	
T4A
	movlw	d'20'	;d20
	movwf	timer1
	call	TIMER
	goto	T4B
;------------------------------------
T5
	movlw	d'40'	;d20
	movwf	timer3
T5B
	decfsz	timer3,1
	goto	T5A
	return	
T5A
	movlw	d'20'	;d20
	movwf	timer1
	call	TIMER
	goto	T5B
;------------------------------------
TIMER
	decfsz	timer1,1
	goto 	T1A
	return
T1A
	movlw	d'255'	; dec.255 ~255uS
	movwf	timer2
REV1
	nop
	nop
	nop
	decfsz	timer2,1
	goto	REV1
	goto	TIMER
;
	end
