⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moment4x4.asm

📁 用凌阳单片机的普通IO口
💻 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.
;==================================================================================
																					
;==================================================================================
;  Program Name		:	Moment4x4.asm
;  Description		:	4X4 key-pad scan and LED Display		 
;  Reference		:	SPMC65P2404A/2408A Data Sheet
;  Revision history	:
;---------------------------------------------------------------------------------- 
;  Version		Date 		Description
;  1.0.0    	2004-10-22	First Edition
;==================================================================================

.SYNTAX  6502								;Process standard 6502 addressing syntax
.LINKLIST									;Generate linklist information
.SYMBOLS									;Generate symbolic debug information
;**********************************************************************************
;constant
CB_CmpTimers		EQU		15				;The maximum times of compare
;**********************************************************************************
.PAGE0 
GB_KeyValue			DS		1				;The specific keys value	
GB_KeyDownFlag		DS		1				;Keys-down flag,"1" represents down.
IB_KeyupFlag		DS		1				;Keys-up flag,"0" represents up. 
IB_CmpTimers		DS		1				;The times of comparine
IB_LastValue		DS		1				;The row scanning value
IB_LineScan			DS		1				;The line scanning value
.DATA
;**********************************************************************************
.CODE
;==================================================================================
;	Function:		F_Moment4x4
;	Description:	Scanning 4x4 Keys
;	Input:			None
;	Output:			GB_KeyValue---------Keys value
;					GB_KeyDownFlag------Key-down flag
;	Destroy:		A,X,Y
;	Stacks:			1
;==================================================================================
.PUBLIC			F_Moment4x4
F_Moment4x4:
		lda		#$F0						;4 scanning lines ouput high 
		sta		P_IOA_Data					;Scanning Keys
		nop
		lda		P_IOA_Data					
		and		#$0F						;row status
		tax	
		
		lda		IB_KeyupFlag				;Key up?
		bne		?L_JudgeUp0					;No
		
		txa									;key down?
		beq		?L_CmpClr0					;No	
		cmp		IB_LastValue				;The Keyvalue is equal to last time's?
		beq		?L_TimersInc				;Yes
		sta		IB_LastValue				;Save the latest keyvalue
?L_CmpClr0:		
		jmp		?L_CmpClr
				
?L_TimersInc:
		inc		IB_CmpTimers				;\
		lda		IB_CmpTimers				;+ 
		cmp		#CB_CmpTimers				;+ = 6-time Comparing end? no	
		bcc		?L_SWx4Exit0				;/  
		
		;---------------------------------------------------------------
		;6-time Comparing have ended,scanning the specific key value
?L_GetValue:
		ldx		#0
		lda		#$08
		sta		IB_LineScan
?L_Lsr:		
		asl 	IB_LineScan					;Scanning lines one by one
		bcs		?L_KeyCope					;4 lines has been scaned? yes
		lda		IB_LineScan
		sta		P_IOA_Data					;Output high in one scanning line
		nop
		nop
		lda		P_IOA_Data					;\
		and		#$0F						;/= Get the row value,any keys down?
		beq		?L_Lsr						;No
		inx									;The numbers of keys that are down
		sta		IB_LastValue				;Save row value
		ldy		IB_LineScan					;Save line value
		jmp		?L_Lsr
		
?L_SWx4Exit0:		
		jmp		?L_SWx4Exit
?L_JudgeUp0:
		jmp		?L_JudgeUp		
		
?L_KeyCope:
		cpx		#1							;The keys that are down more than one?
		bne		?L_KeyUp					;Yes
					
		;---------------------------------------------------------------
		;the specific keyvalue=(row value*4) + (converted line value)
?L_Calculate:
		;---------------------------------------------------------------
		;row value*4
		ldx		#0							
?L_Cal:		
		ror		IB_LastValue		
		bcs		?L_CalMul4				
		inx
		cpx		#4				
		bcs		?L_CmpClr					;Avoid cycling endless
		jmp		?L_Cal
?L_CalMul4:
		txa
		asl		a							
		asl		a							
		sta     GB_KeyValue
		
		;---------------------------------------------------------------
		;convert line value
		ldx		#0
		sty		IB_LineScan			
?L_CalAdd:		
		lda		IB_LineScan		
		and		#$10
		bne		?L_KeyValue
		lsr		IB_LineScan
		inx
		cpx		#4
		bcs		?L_CmpClr					;Avoid cycling endless
		jmp		?L_CalAdd
		
		;---------------------------------------------------------------
		;get the specific keyvalue
?L_KeyValue:
		txa
		clc
		adc		GB_KeyValue
		sta		GB_KeyValue
		lda		#1
		sta		GB_KeyDownFlag				;Set the Key-down flag
?L_KeyUp:		
		lda		#1
		sta		IB_KeyupFlag				;Keys not up 
		jmp		?L_CmpClr
		
?L_JudgeUp:
		txa									;Key up?
		bne		?L_CmpClr					;no
		inc		IB_CmpTimers				;\
		lda		IB_CmpTimers				;+ = Compare 6 times untile all Keys up
		cmp		#CB_CmpTimers				;+ 
		bcc		?L_SWx4Exit					;/
		lda		#0							
		sta		IB_KeyupFlag				;Keys up
?L_CmpClr:		
		lda		#0
		sta		IB_CmpTimers
?L_SWx4Exit:		
		rts     
		       
		       
;==================================================================================
;	Function:		F_Light
;	Description:	light LEDs to reflect the Key value
;	Input:			GB_KeyValue------Key value
;	Output:			none
;	Destroy:		A
;	Stacks:			1
;==================================================================================
.PUBLIC			F_Light
F_Light:
		lda		P_IOC_Data
		and		#$F0
		ora		GB_KeyValue
		eor		#$FF
		sta		P_IOC_Data		
		rts            
;==================================================================================
;	Function:		F_Timer2_Init
;	Description:	set 2ms interrupt
;	Input:			none
;	Output:			none
;	Destroy:		A
;	Stacks:			1
;==================================================================================
.PUBLIC			F_Timer2_Init
F_Timer2_Init:
		lda		#C_T2FCS_Div_512			;8000000/512/32=488Hz=2048us
		sta		P_TMR2_3_Ctrl1
		lda		#224
		sta		P_TMR2_Preload
		lda		#C_T28B_Timer
		sta		P_TMR2_3_Ctrl0			
		lda 	#$FF
		sta 	P_INT_Flag0 				;Clear INT request flag
		sta 	P_INT_Flag1 
		sta		P_INT_Flag2				
		rts         
;==================================================================================
;	Function:		F_IO_Init
;	Description:	Initialize PF0~PF3 as input with pull low,PF4~PF7 and PE0~PE3 
;					as output "0"
;	Input:			none
;	Output:			none
;	Destroy:		A
;	Stacks:			1
;==================================================================================
.PUBLIC			F_IO_Init
F_IO_Init:
		lda		#0
		sta		P_IOA_Attrib
		lda		#$F0
		sta		P_IOA_Dir
		sta		P_IOA_Data
		
		lda		P_IOC_Dir
		ora		#$F
		sta		P_IOC_Dir
		lda		P_IOC_Attrib
		and		#$F0
		sta		P_IOC_Attrib
		lda		P_IOC_Data
		and		#$F0
		sta		P_IOC_Data
		rts            
;==================================================================================
;	Function:		F_Moment4X4_Init
;	Description:	Initialize variables
;	Input:			none
;	Output:			none
;	Destroy:		A
;	Stacks:			1
;==================================================================================
.PUBLIC			F_Moment4X4_Init  
F_Moment4X4_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 + -