📄 ad_key.asm
字号:
;==================================================================================
; The information contained herein is the exclusive property of
; Sunplus Technology Co. And shall not be distributed, reproduced,
; or disclosed in whole in part without prior written permission.
; (C) COPYRIGHT 2004 SUNPLUS TECHNOLOGY CO.
; ALL RIGHTS RESERVED
; The entire notice above must be reproduced on all authorized copies.
;==================================================================================
;==================================================================================
; Project Name :
; Applied Body : SPMC65P2404A
; Firmware version:
; Programer :
; Date : 2005-1-19
; Description : The Program presents how to scan 16 Keys with the function
; of ADC.
;
; Hardware Connect:
; Link File :
; IDE Version : V1.6.5
; BODY Version : V1.0.0A
;==================================================================================
.SYNTAX 6502 ;Process standard 6502 addressing syntax
.LINKLIST ;Generate linklist information
.SYMBOLS ;Generate symbolic debug information
;**********************************************************************************
;constant
CB_CmpTimers EQU 4 ;The maximum times of compare
;**********************************************************************************
.PAGE0
GB_KeyValue DS 1 ;Keys value
GB_KeyDownFlag DS 1 ;Keys-down flag,"1" represents down.
IB_KeyupFlag DS 1 ;Keys-up flag,"0" represents up.
IB_KeyValue DS 1 ;Keys value for comparing
IB_CmpTimers DS 1 ;The times of comparing
.DATA
;**********************************************************************************
.CODE
;==================================================================================
; Function: F_ADKeyx16
; Description: Scanning 16 Keys
; Input: None
; Output: GB_KeyValue---------Keys value
; GB_KeyDownFlag------Key-Down flag
; Destroy: A
; Stacks: 1
;==================================================================================
F_ADKeyx16:
;----------------------------------------
;AD convert
;----------------------------------------
lda P_AD_Ctrl0
and #11111110B ;start convert
sta P_AD_Ctrl0
L_TestAdcL2:
lda P_AD_Ctrl0
and #00000001B ;convertion OK ?
beq L_TestAdcL2 ;no
lda IB_KeyupFlag ;Key up?
bne ?L_JudgeUp ;No
?L_KeyCope:
lda P_AD_DataHi ;AD high 8bit value
and #$F ;\
cmp #$4 ;+
bcc ?L_CmpClr ;+ = The AD value exceed rang? yes
cmp #$C ;+
bcs ?L_Keyup ;/
lda P_AD_DataHi
and #$F0
cmp IB_KeyValue ;Compare AD value with the last time
beq ?L_Inc ;Equal?yes
sta IB_KeyValue
jmp ?L_CmpClr
?L_Inc:
inc IB_CmpTimers ;\
lda IB_CmpTimers ;+ = 4-time Comparing end? no
cmp #CB_CmpTimers ;+
bcc ?L_ADKeyx16Exit ;/
lda IB_KeyValue ;\
lsr a ;+
lsr a ;+ = Get the key value
lsr a ;+
lsr a ;+
sta GB_KeyValue ;/
lda #1
sta GB_KeyDownFlag ;Set the Key-down flag
?L_Keyup:
lda #1
sta IB_KeyupFlag ;Key not up
jmp ?L_CmpClr
?L_JudgeUp:
lda P_AD_DataHi
cmp #$4 ;Key up?
bcs ?L_CmpClr ;No
inc IB_CmpTimers ;\
lda IB_CmpTimers ;+ = Compare 4 times untile all Keys up
cmp #CB_CmpTimers ;+
bcc ?L_ADKeyx16Exit ;/
lda #0
sta IB_KeyupFlag ;Keys up
?L_CmpClr:
lda #0
sta IB_CmpTimers
?L_ADKeyx16Exit:
rts
;==================================================================================
; Function: F_Light
; Description: light LEDs to reflect the Keys value
; Input: GB_KeyValue------Keys value
; Output: none
; Destroy: A
; Stacks: 1
;==================================================================================
.PUBLIC F_Light
F_Light:
lda GB_KeyValue
sta P_IOC_Data
rts
;==================================================================================
; Function: F_AD_KeyInit
; Description: initialize PC as output "0", set ADC
; Input: none
; Output: none
; Destroy: A
; Stacks: 1
;==================================================================================
F_AD_KeyInit:
lda #0
sta P_IOC_Attrib
sta P_IOC_Data
lda #$FF
sta P_IOC_Dir
lda #(C_AD_CE+C_AD_Ch0) ;Select channel 0 (AN0)
sta P_AD_Ctrl2
lda #(C_AD_EN+C_AD_CS_32) ;Fcpu/32
ora #00000001B
sta P_AD_Ctrl0
lda #C_AD_Pin0 ;Analog input : channel 0
sta P_AD_Ctrl1
rts
;==================================================================================
; Function: F_Variable_Init
; Description: Initialize variables
; Input: none
; Output: none
; Destroy: A
; Stacks: 1
;==================================================================================
F_Variable_Init:
lda #0
sta GB_KeyDownFlag ;Keys are not down in initial state
sta IB_CmpTimers ;The times of compare is 0 in initial state
sta IB_KeyupFlag ;Keys are all up in initial state
sta GB_KeyValue ;Key value
rts
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -