;**********************************************************************
; Filename: kuku.asm *
; Date: 2001/11/11 *
; File Version: *
;**********************************************************************
list p=16F84 ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
;***** VARIABLE DEFINITIONS
w_temp EQU 0x0C ; variable used for context saving
status_temp EQU 0x0D ; variable used for context saving
input_p EQU 0x10 ;input pointa
key_data1 EQU 0x11 ;key scan data1
key_data2 EQU 0x12 ;key scan data2
key_no EQU 0x13 ;key No.
key_buff EQU 0x14 ;last key No.
wait_data EQU 0x15 ;wait data ram
d_offset EQU 0x16 ;suji data offset
taihi EQU 0x17 ;taihi data
out_data EQU 0x18 ;out data
suji_k1 EQU 0x19 ;suji_1(keta1)
suji_k2 EQU 0x1a ;suji_2(keta2)
suji_k3 EQU 0x1b ;suji_3(kotae1)
suji_k4 EQU 0x1c ;suji_4(kotae2)
suji_m EQU 0x1d ;suji matome
kekka EQU 0x1e ;keisan kekka
keta10 EQU 0x20 ;keta10 disp data
keta11 EQU 0x21 ;keta11 disp data
keta12 EQU 0x22 ;keta12 disp data
keta13 EQU 0x23 ;keta13 disp data
keta14 EQU 0x24 ;keta14 disp data
keta20 EQU 0x25 ;keta20 disp data
keta21 EQU 0x26 ;keta21 disp data
keta22 EQU 0x27 ;keta22 disp data
keta23 EQU 0x28 ;keta23 disp data
keta24 EQU 0x29 ;keta24 disp data
kotae10 EQU 0x2a ;kotae10 disp data
kotae11 EQU 0x2b ;kotae11 disp data
kotae12 EQU 0x2c ;kotae12 disp data
kotae13 EQU 0x2d ;kotae13 disp data
kotae14 EQU 0x2e ;kotae14 disp data
kotae20 EQU 0x2f ;kotae20 disp data
kotae21 EQU 0x30 ;kotae21 disp data
kotae22 EQU 0x31 ;kotae22 disp data
kotae23 EQU 0x32 ;kotae23 disp data
kotae24 EQU 0x33 ;kotae24 disp data
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
;---------------------------------------------------------------
;---------------------------------------------------------------
int_end
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
;--------------------------------------------------------------------------
main
call port_set
movlw 0ffh
movwf PORTA
movlw 0c0h
movwf PORTB
call timer0_set
call pointa_shoki
call suji_shoki
call suji_tenso
;--------------------------------------
main_loop
call key_scan
movwf key_data1
call key_scan
movwf key_data2
subwf key_data1,0
btfss STATUS,2
goto main_key_e
;---------------------- key ok
movf key_data2,0
sublw 0x0f
btfsc STATUS,2
goto main_key_e
;---------------------- key on
movf key_data2,0
call key_henkan
movwf key_no
subwf key_buff,0
btfsc STATUS,2
goto main_key_n
;---------------------- key new
movf input_p,0
sublw 0x00
btfss STATUS,2
goto main_k2
movf key_no,0
sublw 0x0c
btfss STATUS,2
goto main_k11
;--- [C]
main_k10
call pointa_shoki
call suji_shoki
goto main_ke2
main_k11
movf key_no,0
sublw 0x0d
btfss STATUS,2
goto main_k12
;--- [R]
goto main_ke2
main_k12
call suji_shoki
movf key_no,0
movwf suji_k1
movlw 0x01
main_ke
movwf input_p
main_ke2
call suji_tenso
goto main_key_n
;----------------------
main_k2
movf input_p,0
sublw 0x01
btfss STATUS,2
goto main_k3
movf key_no,0
sublw 0x0c
btfss STATUS,2
goto main_k21
;--- [C]
goto main_k10
main_k21
movf key_no,0
sublw 0x0d
btfss STATUS,2
goto main_k22
;--- [R]
goto main_ke2
main_k22
movf key_no,0
movwf suji_k2
movlw 0x03
goto main_ke
;----------------------
main_k3
;----------------------
main_k4
movf input_p,0
sublw 0x03
btfss STATUS,2
goto main_k5
movf key_no,0
sublw 0x0c
btfss STATUS,2
goto main_k41
;--- [C]
goto main_k10
main_k41
movf key_no,0
sublw 0x0d
btfss STATUS,2
goto main_k42
;--- [R]
goto main_ke2
main_k42
movf key_no,0
movwf suji_k4
movlw 0x04
goto main_ke
;----------------------
main_k5
movf input_p,0
sublw 0x04
btfss STATUS,2
goto main_k6
movf key_no,0
sublw 0x0c
btfss STATUS,2
goto main_k51
;--- [C]
goto main_k10
main_k51
movf key_no,0
sublw 0x0d
btfss STATUS,2
goto main_k52
;--- [R]
call check
goto main_ke2
main_k52
movf suji_k4,0
sublw 0x00
btfss STATUS,2
goto main_53
movlw 0x0b
goto main_54
main_53
movf suji_k4,0
main_54
movwf suji_k3
movf key_no,0
movwf suji_k4
main_k6 movlw 0x04
goto main_ke
;-----------------------
main_key_n
movf key_no,0
movwf key_buff
goto main_led
main_key_e movlw 0x0f
movwf key_no
movwf key_buff
;---------------------------------------
main_led
;---------------------- 0
movlw 0x10
call sub_1
movf keta10,0
call data_out
movlw 0xff
call data_out
call sub_2
;---------------------- 1
movlw 0x11
call sub_1
movf keta11,0
call data_out
movlw 0xeb
call data_out
call sub_2
;---------------------- 2
movlw 0x12
call sub_1
movf keta12,0
call data_out
movlw 0xeb
call data_out
call sub_2
;---------------------- 3
movlw 0x13
call sub_1
movf keta13,0
call data_out
movlw 0xeb
call data_out
call sub_2
;---------------------- 4
movlw 0x14
call sub_1
movf keta14,0
call data_out
movlw 0xff
call data_out
call sub_2
;---------------------- 5
movlw 0x15
call sub_1
movlw 0xff
call data_out
movf kotae10,0
call data_out
call sub_2
;---------------------- 6
movlw 0x16
call sub_1
movlw 0xdb
call data_out
movf kotae11,0
call data_out
call sub_2
;---------------------- 7
movlw 0x17
call sub_1
movlw 0xe7
call data_out
movf kotae12,0
call data_out
call sub_2
;---------------------- 8
movlw 0x18
call sub_1
movlw 0xe7
call data_out
movf kotae13,0
call data_out
call sub_2
;---------------------- 9
movlw 0x19
call sub_1
movlw 0xdb
call data_out
movf kotae14,0
call data_out
call sub_2
;---------------------- 10
movlw 0x1a
call sub_1
movlw 0xff
call data_out
movlw 0xff
call data_out
call sub_2
;---------------------- 11
movlw 0x1b
call sub_1
movf keta20,0
call data_out
movf kotae20,0
call data_out
call sub_2
;---------------------- 12
movlw 0x1c
call sub_1
movf keta21,0
call data_out
movf kotae21,0
call data_out
call sub_2
;---------------------- 13
movlw 0x1d
call sub_1
movf keta22,0
call data_out
movf kotae22,0
call data_out
call sub_2
;---------------------- 14
movlw 0x1e
call sub_1
movf keta23,0
call data_out
movf kotae23,0
call data_out
call sub_2
;---------------------- 15
movlw 0x1f
call sub_1
movf keta24,0
call data_out
movf kotae24,0
call data_out
call sub_2
;---------------------------------------
goto main_loop
;-------------------------------------------------------------------------------
sub_1
movwf PORTA
bsf PORTB,2
nop
return
;------------------------------------
sub_2
bcf PORTB,2
nop
bcf PORTA,4
nop
call wait_1
bsf PORTA,4
nop
return
;-------------------------------------------------------------------------------
wait_0
movlw 0ffh
movwf wait_data
goto wait_2
wait_1
movlw 0ffh
movwf wait_data
wait_2
nop
decfsz wait_data,1
goto wait_2
return
;-------------------------------------------------------------------------------
data_out
movwf out_data
bcf PORTB,1
btfsc out_data,0
bsf PORTB,1
call clk
bcf PORTB,1
btfsc out_data,1
bsf PORTB,1
call clk
bcf PORTB,1
btfsc out_data,2
bsf PORTB,1
call clk
bcf PORTB,1
btfsc out_data,3
bsf PORTB,1
call clk
bcf PORTB,1
btfsc out_data,4
bsf PORTB,1
call clk
bcf PORTB,1
btfsc out_data,5
bsf PORTB,1
call clk
bcf PORTB,1
btfsc out_data,6
bsf PORTB,1
call clk
bcf PORTB,1
btfsc out_data,7
bsf PORTB,1
call clk
return
;--------------------------------------------------------------------------------
clk
bsf PORTB,0
nop
bcf PORTB,0
nop
return
;--------------------------------------------------------------------------------
suji_shoki movlw 0x0a
movwf suji_k1
movlw 0x0a
movwf suji_k2
movlw 0x0b
movwf suji_k3
movlw 0x0b
movwf suji_k4
return
;--------------------------------------------------------------------------------
offset_shoki
movlw 0x00
movwf d_offset
return
;--------------------------------------------------------------------------------
pointa_shoki
movlw 0x00
movwf input_p
return
;--------------------------------------------------------------------------------
suji_tenso
call offset_shoki
suji_tenso_0
movlw keta10
addwf d_offset,0
movwf FSR
movf suji_k1,0
call suji_data
movwf INDF
incf d_offset,1
movf d_offset,0
sublw 0x05
btfss STATUS,2
goto suji_tenso_0
call offset_shoki
suji_tenso_1
movlw keta20
addwf d_offset,0
movwf FSR
movf suji_k2,0
call suji_data
movwf INDF
incf d_offset,1
movf d_offset,0
sublw 0x05
btfss STATUS,2
goto suji_tenso_1
call offset_shoki
suji_tenso_2
movlw kotae10
addwf d_offset,0
movwf FSR
movf suji_k3,0
call suji_data
movwf INDF
incf d_offset,1
movf d_offset,0
sublw 0x05
btfss STATUS,2
goto suji_tenso_2
call offset_shoki
suji_tenso_3
movlw kotae20
addwf d_offset,0
movwf FSR
movf suji_k4,0
call suji_data
movwf INDF
incf d_offset,1
movf d_offset,0
sublw 0x05
btfss STATUS,2
goto suji_tenso_3
return
;--------------------------------------------------------------------------------
suji_data movwf taihi
bcf STATUS,0
rlf taihi,1
rlf taihi,1
rlf taihi,1
movf taihi,0
addwf d_offset,0
movwf taihi
movlw low(suji_table)
addwf taihi,1
movlw high(suji_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
suji_table ;----------- 0
retlw 0C1
retlw 0BE
retlw 0BE
retlw 0BE
retlw 0C1
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 1
retlw 0FF
retlw 0FD
retlw 0FD
retlw 080
retlw 0FF
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 2
retlw 09D
retlw 0AE
retlw 0B6
retlw 0B6
retlw 0B9
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 3
retlw 0DD
retlw 0BE
retlw 0B6
retlw 0B6
retlw 0C9
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 4
retlw 0E7
retlw 0EB
retlw 0ED
retlw 080
retlw 0EF
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 5
retlw 0D8
retlw 0BA
retlw 0BA
retlw 0BA
retlw 0C6
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 6
retlw 0C3
retlw 0B5
retlw 0B6
retlw 0B6
retlw 0CF
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 7
retlw 0FE
retlw 0FE
retlw 08E
retlw 0F2
retlw 0FC
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 8
retlw 0C9
retlw 0B6
retlw 0B6
retlw 0B6
retlw 0C9
retlw 0ff
retlw 0ff
retlw 0ff
;----------- 9
retlw 0F9
retlw 0B6
retlw 0B6
retlw 0D6
retlw 0E1
retlw 0ff
retlw 0ff
retlw 0ff
;----------- a(mark)
retlw 0FF
retlw 0E3
retlw 0E3
retlw 0E3
retlw 0FF
retlw 0ff
retlw 0ff
retlw 0ff
;----------- b(space)
retlw 0ff
retlw 0ff
retlw 0ff
retlw 0ff
retlw 0ff
retlw 0ff
retlw 0ff
retlw 0ff
;----------- c(OK)
retlw 0E3
retlw 0DD
retlw 0D5
retlw 0DD
retlw 0E3
retlw 0ff
retlw 0ff
retlw 0ff
;----------- d(NG)
retlw 0DD
retlw 0EB
retlw 0F7
retlw 0EB
retlw 0DD
retlw 0ff
retlw 0ff
retlw 0ff
;--------------------------------------------------------------------------------
key_henkan movwf taihi
movlw low(henkan_table)
addwf taihi,1
movlw high(henkan_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
henkan_table ;-----------
retlw 00
retlw 08
retlw 0D
retlw 05
retlw 0C
retlw 02
retlw 09
retlw 07
retlw 06
retlw 04
retlw 03
retlw 01
retlw 0f
retlw 0f
retlw 0f
retlw 0f
;-------------------------------------------------------------------------------
keisan movwf taihi
movlw low(check_table)
addwf taihi,1
movlw high(check_table)
movwf PCLATH
addcf PCLATH,1
movf taihi,0
movwf PCL
check_table ;-----------
retlw 0b0 ;00
retlw 0b0 ;01
retlw 0b0 ;02
retlw 0b0 ;03
retlw 0b0 ;04
retlw 0b0 ;05
retlw 0b0 ;06
retlw 0b0 ;07
retlw 0b0 ;08
retlw 0b0 ;09
retlw 00 ;0a
retlw 00 ;0b
retlw 00 ;0c
retlw 00 ;0d
retlw 00 ;0e
retlw 00 ;0f
retlw 0b0 ;10
retlw 0b1 ;11
retlw 0b2 ;12
retlw 0b3 ;13
retlw 0b4 ;14
retlw 0b5 ;15
retlw 0b6 ;16
retlw 0b7 ;17
retlw 0b8 ;18
retlw 0b9 ;19
retlw 00 ;1a
retlw 00 ;1b
retlw 00 ;1c
retlw 00 ;1d
retlw 00 ;1e
retlw 00 ;1f
retlw 0b0 ;20
retlw 0b2 ;21
retlw 0b4 ;22
retlw 0b6 ;23
retlw 0b8 ;24
retlw 10 ;25
retlw 12 ;26
retlw 14 ;27
retlw 16 ;28
retlw 18 ;29
retlw 00 ;2a
retlw 00 ;2b
retlw 00 ;2c
retlw 00 ;2d
retlw 00 ;2e
retlw 00 ;2f
retlw 0b0 ;30
retlw 0b3 ;31
retlw 0b6 ;32
retlw 0b9 ;33
retlw 12 ;34
retlw 15 ;35
retlw 18 ;36
retlw 21 ;37
retlw 24 ;38
retlw 27 ;39
retlw 00 ;3a
retlw 00 ;3b
retlw 00 ;3c
retlw 00 ;3d
retlw 00 ;3e
retlw 00 ;3f
retlw 0b0 ;40
retlw 0b4 ;41
retlw 0b8 ;42
retlw 12 ;43
retlw 16 ;44
retlw 20 ;45
retlw 24 ;46
retlw 28 ;47
retlw 32 ;48
retlw 36 ;49
retlw 00 ;4a
retlw 00 ;4b
retlw 00 ;4c
retlw 00 ;4d
retlw 00 ;4e
retlw 00 ;4f
retlw 0b0 ;50
retlw 0b5 ;51
retlw 10 ;52
retlw 15 ;53
retlw 20 ;54
retlw 25 ;55
retlw 30 ;56
retlw 35 ;57
retlw 40 ;58
retlw 45 ;59
retlw 00 ;5a
retlw 00 ;5b
retlw 00 ;5c
retlw 00 ;5d
retlw 00 ;5e
retlw 00 ;5f
retlw 0b0 ;60
retlw 0b6 ;61
retlw 12 ;62
retlw 18 ;63
retlw 24 ;64
retlw 30 ;65
retlw 36 ;66
retlw 42 ;67
retlw 48 ;68
retlw 54 ;69
retlw 00 ;6a
retlw 00 ;6b
retlw 00 ;6c
retlw 00 ;6d
retlw 00 ;6e
retlw 00 ;6f
retlw 0b0 ;70
retlw 0b7 ;71
retlw 14 ;72
retlw 21 ;73
retlw 28 ;74
retlw 35 ;75
retlw 42 ;76
retlw 49 ;77
retlw 56 ;78
retlw 63 ;79
retlw 00 ;7a
retlw 00 ;7b
retlw 00 ;7c
retlw 00 ;7d
retlw 00 ;7e
retlw 00 ;7f
retlw 0b0 ;80
retlw 0b8 ;81
retlw 16 ;82
retlw 24 ;83
retlw 32 ;84
retlw 40 ;85
retlw 48 ;86
retlw 56 ;87
retlw 64 ;88
retlw 72 ;89
retlw 00 ;8a
retlw 00 ;8b
retlw 00 ;8c
retlw 00 ;8d
retlw 00 ;8e
retlw 00 ;8f
retlw 0b0 ;90
retlw 0b9 ;91
retlw 18 ;92
retlw 27 ;93
retlw 36 ;94
retlw 45 ;95
retlw 54 ;96
retlw 63 ;97
retlw 72 ;98
retlw 81 ;99
retlw 00 ;9a
retlw 00 ;9b
retlw 00 ;9c
retlw 00 ;9d
retlw 00 ;9e
retlw 00 ;9f
;-------------------------------------------------------------------------------
check
movf suji_k1,0
movwf suji_m
swapf suji_m,1
movf suji_k2,0
xorwf suji_m,1
movf suji_m,0
call keisan
movwf kekka
movf suji_k3,0
movwf suji_m
swapf suji_m,1
movf suji_k4,0
xorwf suji_m,1
movf kekka,0
subwf suji_m,0
btfss STATUS,2
goto check_ng
check_ok
movlw 0x0c
movwf suji_k3
movlw 0x0c
check_2 movwf suji_k4
call pointa_shoki
return
check_ng
movlw 0x0d
movwf suji_k3
movlw 0x0d
goto check_2
;-------------------------------------------------------------------------------
key_scan
bcf PORTB,3
nop
bcf PORTB,4
nop
bcf PORTB,5
nop
call wait_0
btfsc PORTB,6
goto key_next2
movlw 0x00
key_end
bsf PORTB,3
nop
bsf PORTB,4
nop
bsf PORTB,5
return
key_next2
btfsc PORTB,7
goto key_next3
movlw 0x01
goto key_end
key_next3
bsf PORTB,3
nop
bcf PORTB,4
nop
bcf PORTB,5
nop
call wait_0
btfsc PORTB,6
goto key_next4
movlw 0x02
goto key_end
key_next4
btfsc PORTB,7
goto key_next5
movlw 0x03
goto key_end
key_next5
bcf PORTB,3
nop
bsf PORTB,4
nop
bcf PORTB,5
nop
call wait_0
btfsc PORTB,6
goto key_next6
movlw 0x04
goto key_end
key_next6
btfsc PORTB,7
goto key_next7
movlw 0x05
goto key_end
key_next7
bsf PORTB,3
nop
bsf PORTB,4
nop
bcf PORTB,5
nop
call wait_0
btfsc PORTB,6
goto key_next8
movlw 0x06
goto key_end
key_next8
btfsc PORTB,7
goto key_next9
movlw 0x07
goto key_end
key_next9
bcf PORTB,3
nop
bcf PORTB,4
nop
bsf PORTB,5
nop
call wait_0
btfsc PORTB,6
goto key_nexta
movlw 0x08
goto key_end
key_nexta
btfsc PORTB,7
goto key_nextb
movlw 0x09
goto key_end
key_nextb
bsf PORTB,3
nop
bcf PORTB,4
nop
bsf PORTB,5
nop
call wait_0
btfsc PORTB,6
goto key_nextc
movlw 0x0a
goto key_end
key_nextc
btfsc PORTB,7
goto key_nextd
movlw 0x0b
goto key_end
key_nextd
movlw 0x0f
goto key_end
;-------------------------------------------------------------------------------
port_set ;RA0,RA1,RA2,RA3,RA4(OUT)
;RB0,RB1,RB2,RB3,RB4,RB5(OUT)
;RB6,RB7(IN)
bsf STATUS,RP0
clrf TRISA
clrf TRISB
bsf TRISB,7
nop
bsf TRISB,6
nop
bcf STATUS,RP0
return
timer0_set
bsf STATUS,RP0
movlw 086h ;(1)PORTB NOT PULLUP
;(0)INTEDG
;(0)TOCS
;(0)TOSE
;(0)PSA
;(110)1/128
movwf OPTION_REG
bcf STATUS,RP0
return
END ; directive 'end of program'
|