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

📄 main.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.
;==================================================================================
										
;==================================================================================
;	Project Name	:	
;	Applied Body	:	SPMC65P2404A
;	Firmware version:
;	Programer		:
;	Date			:	2004-11-10
;	Description		:	slave Communicates with master 
;						
;	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
;************************************************************************************
;*																					*
;*      System Register Define														*
;*																					*
;************************************************************************************
;************************************************************************************
.INCLUDE		SPMC65P2404A.inc					;Define all hardware,Registers and ports.                       
;************************************************************************************		

;************************************************************************************
;*																					*
;*      Data memory Define	                                                        *
;*																					*
;************************************************************************************
.PAGE0										;Define values in the range from 00h to FFh
;************************************************************************************
.DATA										;Define data storage section           
;************************************************************************************
;*																					*
;*      	 Program Area															*
;*																					*
;************************************************************************************
.CODE 
.INCLUDE		  Moment4x4.asm
.INCLUDE		  Subprogram.asm                  
;************************************************************************************
;*																					*
;*      Power on Reset Process	                                                    *
;*																					*
;************************************************************************************
.PUBLIC		V_Reset
V_Reset:
		sei									;Disable interrupt
		ldx		#C_STACK_BOTTOM				;Initial stack pointer at $00FF
		txs	
		lda		#C_T0FCS_Div_4
		sta		GP_IIC_BitRate				;select the Prescaler of Timer1
		jsr		F_IO_Init					;initialize the I/O for display
		jsr		F_Timer2_Init				;initialize the Timer2 for main loop
		jsr		F_Sys_Init					;initialize the I/O,Timer and clock for communication 	
		lda		#%11110001					;require master receive data
		sta		GB_SCommand	
		lda		#2	
		sta		GB_SCapacity				;the size of the data which to been send
		lda		#1
		sta		GB_SData_Addr				;store the Slaver number 
		lda		#$10
		sta		GB_SData_Addr+1	
		cli 		  
L_MainLoop:
		jsr		F_WrData					;dispose when send the data	
		jsr		F_CheckACK					;ACK check
		jsr		F_Moment4x4					;Scanning 4x4 keys
		lda		GB_KeyDownFlag				;Key down?
		beq		?L_Wait						;No
		lda		#0
		sta		GB_KeyDownFlag				;Clear key down flag
		lda		GB_KeyValue
		sta		GB_SData_Addr+1
		jsr		F_Light						;Show the key's value	
?L_Wait:	
		
		lda		P_INT_Flag1					
		and		#C_INT_T2OIF				;time 704us ?
		beq		?L_Wait						;no
		lda		#C_INT_T2OIF
		sta		P_INT_Flag1			
		inc		GB_CSCnt
		lda		GB_CSCnt
		cmp		#3
		bcc		L_MainLoop
		lda		#0
		sta		GB_CSCnt
		sta		GB_INT_Cnt						
		jmp		L_MainLoop
;************************************************************************************
;*																					*
;*      Interrupt Service Process                         	                        *
;*																					*
;************************************************************************************
V_IRQ:
		pha 
		txa
		pha	
;===============================================================================	
;			Timer1 INT
;===============================================================================										
		lda		P_INT_Flag1
		and		#C_INT_T0OIF
		beq		?L_IRQ_INT
		M_ClrSCL;							;clear SCL
		lda		GB_INT_Cnt
		cmp		#8
		bcc		?L_SendData
		M_SDA_Input;						;set free the SDA
		M_DisableT1;						;disable the Timer1	
		inc		GB_TxCnt					
		M_BitSet GB_Flag,0;					;set the flag for check ACK
		jmp		?L_INT_rti			
?L_SendData:										
		asl		GP_IIC_TxBuf
		bcs		?L_OutputH
		M_ClrSDA;							;SDA export '0'
		jmp		?L_Rising
?L_OutputH:
		M_SetSDA;							;SDA export '1'
?L_Rising:										
		inc		GB_INT_Cnt
		M_SetSCL;							;set SCL
		jmp		?L_INT_rti		
		
;===============================================================================	
;			IRQ2 INT
;===============================================================================
?L_IRQ_INT:
		lda		P_INT_Flag0
		and		#(C_INT_IRQ0IF+C_INT_IRQ1IF)
		beq		?L_INT_rti
		
		lda		GB_Flag
		and 	#%10000000	
		beq		?L_NoSart	
		lda		P_IOB_Data
		and		#%00100000					;check the SCL is high ?
		beq		?L_INT_rti					;No
		M_BitClr GB_Flag,7;					;start flag
		lda		#C_IRQOpt1_IRQ1ES			;select rising edge trigger
		sta		P_IRQ_Opt1
		sta		P_IRQ_Opt1
		
		lda		P_INT_Ctrl0
		ora		#C_INT_IRQ1IE				;enable IRQ1
		sta		P_INT_Ctrl0
		jmp		?L_INT_rti		
?L_NoSart:	
		lda		#0
		sta		GB_CSCnt	
		lda		P_IOB_Data					;\
		and		#%00010000					; \
		rol		a							;  + = catch one bit
		rol		a							; /
		rol		a							;/
		rol		a
		rol		GP_IIC_RxBuf						
		inc		GB_INT_Cnt		
		lda		GB_INT_Cnt
		cmp		#8							;catch 8 bit ?
		bcc		?L_INT_rti					;no
		M_RxData;
		inc		GB_RxCnt
		M_BitClr GB_Flag,5;					;clear if receive the command			
		lda		#0
		sta		GB_INT_Cnt

		lda		#00							;select rising edge trigger
		sta		P_IRQ_Opt1
		sta		P_IRQ_Opt1

		lda		P_INT_Ctrl0
		ora		#C_INT_IRQ1IE				;enable IRQ1
		sta		P_INT_Ctrl0
?L_INT_rti:
		lda		#(C_INT_IRQ0IF+C_INT_IRQ1IF)
		sta		P_INT_Flag0
		lda		#C_INT_T0OIF
		sta		P_INT_Flag1
		pla 
		tax
		pla   						
		rti           

V_NMI:
		rti
;************************************************************************************
;*																					*
;*      Interrupt Vector Table														*
;*																					*
;************************************************************************************
VECTOR		.SECTION
		DW		V_NMI						;Non-mask interrupt vector(no use)
		DW		V_Reset						;Reset vector
		DW		V_IRQ						;IRQ interrupt vector
;************************************************************************************
;*																					*
;*      End of Interrupt Vector Table												*
;*																					*
;************************************************************************************
.END

⌨️ 快捷键说明

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