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

📄 key4x4_4led.asm

📁 软件部分。本系统应用于SUNPLUS SPMC65x series上
💻 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			:	2004-1-17
;	Description		:	The Program presents an example of stopwatch.
;						
;	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		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 compare
IB_LastValue		DS		1				;The latest key value
IB_LineScan			DS		1				;The line scanning value
IB_RowScan			DS		1				;The row scanning value
IB_Delay			DS		1				;for delay
;Key cope
IB_2msCount			DS		1				;2ms Stopwatch counting
IB_10msCount		DS		1				;10ms Stopwatch counting
IB_1sCount			DS		1				;1s Stopwatch counting
IB_Start			DS		1				;stopwatch "start" or "stop" flag
IB_Open 			DS		1				;stopwatch "open" or "close" flag
;LED scanning
GB_ShowBuf			DS		4				;Define a four_byte area 
IB_IndexCom			DS		1				;The value controll the showing order of LEDs
.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		#0
		sta		P_IOC_Data

		lda		#0
		sta		P_IOA_Attrib
		lda		#$0F						;4 scanning lines ouput low 
		sta		P_IOA_Data					;Scanning Keys
		lda		#$F0					
		sta		P_IOA_Dir
		nop
		nop
		lda		P_IOA_Data					
		and		#$0F						;row status
		tax	
		
		lda		IB_KeyupFlag				;Key up?
		bne		?L_JudgeUp0					;No
		
		txa									
		cmp		#$0F						;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		#$EF
		sta		IB_LineScan
		jmp		?L_Lsr_First
?L_Lsr:		
		asl 	IB_LineScan					;Scanning lines one by one
		lda		IB_LineScan
		cmp		#$F0
		beq		?L_KeyCope					;4 lines has been scaned? yes
		lda		IB_LineScan					
?L_Lsr_First:
		and		#$F0						;\ when one line is scanning,
		sta		P_IOA_Attrib				;/ other lines are floating 
		ora		#$0F
		sta		P_IOA_Data					;Output low in one scanning line
?L_Delay:
		inc		IB_Delay
		lda		IB_Delay
		bne		?L_Delay		

		lda		P_IOA_Data					;\
		and		#$0F						;/= Get the row value,any keys down?
		cmp		#$0F
		beq		?L_Lsr						;No
		inx									;The numbers of keys that are down
		sta		IB_RowScan					;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
		
		tya
		and		#$F0
		ora		IB_RowScan
		sta		IB_LastValue				;Combine the status of line and row

?L_Calculate:
		ldx		#0							;\		
?L_Calculate_Loop:							;+		
		lda		?L_TB_KeyTable,x			;+						
		cmp		IB_LastValue				;+ = transfer the status of line  									
		beq		?L_KeyDown					;+ = and row to key value			
		inx									;+													
		cpx		#$10						;+
		bcs		?L_KeyUp					;/								
		jmp		?L_Calculate_Loop
?L_KeyDown:		
		stx		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:
		cpx		#$0F						;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:		
		lda		#0					
		sta		P_IOA_Data			
		rts     
?L_TB_KeyTable:
DB		$EE,$DE,$BE,$7E		
DB		$ED,$DD,$BD,$7D		
DB		$EB,$DB,$BB,$7B		
DB		$E7,$D7,$B7,$77	

;====================================================================================
;	Function:		F_KeyCope
;	Description:	Stopwatch "open" "close" "start counting" "stop counting" 
;	Input:			GB_KeyDownFlag----Keys-down flag
;					GB_KeyValue-------Key Value
;	Output:			GB_ShowBuf--------showing buffer
;	Destroy:		A
;	Stacks:			none
;====================================================================================
F_KeyCope:
		lda		GB_KeyDownFlag			;Key down?
		beq		?L_Counter   			;No
		lda		#0
		sta		GB_KeyDownFlag			;Clear key down flag

		lda		GB_KeyValue
		beq		?L_Clear				;stopwatch shows "0"? yes
		cmp		#1
		bne		?L_Close				;close stopwatch? yes
		
		lda		IB_Open					;stopwatch is open?
		beq		?L_KeyCope_Exit			;no
		lda		IB_Start
		eor		#$FF					
		sta		IB_Start				;stopwatch starts or stops counting
		beq		?L_KeyCope_Exit			;stopwatch stops counting? yes
		
?L_Counter:
		lda		IB_Open
		and		IB_Start
		beq		?L_KeyCope_Exit			;stopwatch continues counting? no
			
		sed
		clc
		lda		#1
		adc		IB_2msCount				;2ms counting
		sta		IB_2msCount
		cmp		#$5						;10ms comming?
		bne		?L_KeyCope_Exit			;no
		lda		#0
		sta		IB_2msCount
		
?L_10ms:
		clc
		lda		#$1
		adc		IB_10msCount			;10ms counting
		sta		IB_10msCount
		bcc		?L_DisplayBuf			;1s comming? no
		
?L_1s:
		clc
		lda		#$1
		adc		IB_1sCount				;1s counting
		sta		IB_1sCount				
		jmp		?L_DisplayBuf
		
?L_Close:
		lda		#0
		sta		IB_Open					;stopwatch is closed
		lda		#$AA					;stopwatch shows black
		jmp		?L_Move
		
?L_Clear:
		lda		#$FF
		sta		IB_Open					;stopwatch is opened
		lda		#0
		sta		IB_Start
?L_Move:		
		sta		IB_2msCount
		sta		IB_10msCount
		sta		IB_1sCount
					
?L_DisplayBuf:
		;-------------------------------------------------
		;move showing datas to showing buffer
		lda		IB_10msCount		
		and		#$F
		sta		GB_ShowBuf
		lda		IB_10msCount		
		lsr		a
		lsr		a
		lsr		a
		lsr		a
		sta		GB_ShowBuf+1
		lda		IB_1sCount		
		and		#$F
		sta		GB_ShowBuf+2
		lda		IB_1sCount		
		lsr		a
		lsr		a
		lsr		a
		lsr		a
		sta		GB_ShowBuf+3
?L_KeyCope_Exit:
		cld
		rts		       		       
		       
;====================================================================================
;	Function:		F_LED_4Disp
;	Description:	Show the datas saved in a four_byte area inducted by [GB_ShowBuf]
;	Input:			Four-byte showing datas 
;	Output:			none
;	Destroy:		A,X
;	Stacks:			none
;====================================================================================
F_LED_4Disp:
		lda		#$FF
		sta		P_IOA_Dir
		lda		#0
		sta		P_IOA_Attrib
		sta		P_IOA_Data
		
		ldx		IB_IndexCom				
		inx							;LED com ++							
		cpx		#4					;LED com scanning over ?			
		bcs		?L_ClearX			;Yes
		stx		IB_IndexCom			
		jmp		?L_Show			
?L_ClearX:						
		ldx		#$00			
		stx		IB_IndexCom		    ;Showing from the first LED		
?L_Show:		
		lda		#$00
		sta		P_IOA_Data			;Clear the screen			
		lda		T_SevenComTable,x
		sta		P_IOC_Data			;Move common word to PC				
		lda		GB_ShowBuf,x		;Reach the data from showing buffer
		tax                        
		lda		T_SevenSegTable,x	;Get the segment  
		sta		P_IOA_Data			;Move the segment word to PA		
?L_Div_End:
		rts

;==================================================================================
;	Function:		F_IO_Init
;	Description:	Initialize PA0~PA3 as input with pull low,PA4~PA7 and PC
;					as output "0"
;	Input:			none
;	Output:			none
;	Destroy:		A
;	Stacks:			1
;==================================================================================
F_IO_Init:
		lda		#0
		sta		P_IOA_Attrib
		lda		#$F0
		sta		P_IOA_Dir
		sta		P_IOA_Data
		
		lda		#$FF
		sta		P_IOC_Dir
		lda		#0
		sta		P_IOC_Attrib
		sta		P_IOC_Data		
		rts            
;==================================================================================
;	Function:		F_Variable_Init
;	Description:	Initialize variables
;	Input:			none
;	Output:			none
;	Destroy:		A
;	Stacks:			1
;==================================================================================
F_Variable_Init:
        lda		#0
		sta		GB_KeyValue					;key value   
        sta		GB_KeyDownFlag				;Keys are not down in initial state 
        sta		IB_KeyupFlag				;Keys are all up in initial state
        sta		IB_CmpTimers				;The times of compare is 0 in initial state
		sta		IB_2msCount					;2ms Stopwatch counting		
		sta		IB_10msCount				;10ms Stopwatch counting		
		sta		IB_1sCount					;1s Stopwatch counting				
		sta		IB_Start					;stopwatch "start" or "stop" flag		
		sta		IB_Open 					;stopwatch "open" or "close" flag		
		sta		IB_IndexCom					;The value controll the showing order of LEDs
		sta		IB_Delay
		lda		#$A
		sta		GB_ShowBuf					;\
		sta		GB_ShowBuf+1				;+ = showing buffer	
		sta		GB_ShowBuf+2				;+
		sta		GB_ShowBuf+3				;/			
		rts 
;************************************************************************************
;*																					*
;*				The Com and Segment Table of LED									*
;*																					*
;************************************************************************************
T_SevenComTable:       			;The com table of led			
		DB      %00000001       ;LED '1'
		DB      %00000010       ;LED '2'
		DB      %00000100       ;LED '3'
		DB      %00001000       ;LED '4'
                 
T_SevenSegTable:				;The segment table of led
		DB		%00111111		;Character '0'
		DB		%00000110		;Character '1'
		DB		%01011011		;Character '2'
		DB		%01001111		;Character '3'
		DB		%01100110		;Character '4'
		DB		%01101101		;Character '5'
		DB		%01111101		;Character '6'
		DB		%00000111		;Character '7'
		DB		%01111111		;Character '8'
		DB		%01101111		;Character '9'
		DB		%00000000		;Character 'black'

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -