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

📄 access4096.asm

📁 利用PWM功能实现语音播放功能。本系统应用于Suplus SPMC65* 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.
;==================================================================================
																					
;==================================================================================
;  Program Name		:	Access4096.asm
;  Description		:	get the data from SPR4096 		 
;  Reference		:	SPMC65P2404A/2408A Data Sheet
;  Revision history	:
;---------------------------------------------------------------------------------- 
;  Version		Date 		Description
;  1.0.0    	2005-5-10	First Edition
;==================================================================================

.SYNTAX  6502							;Process standard 6502 addressing syntax
.LINKLIST								;Generate linklist information
.SYMBOLS								;Generate symbolic debug information
;************************************************************************************
;*																					*
;*      System Register Define														*
;*																					*
;************************************************************************************

;************************************************************************************
.INCLUDE		Macro4096.inc					;Define all hardware,Registers and ports.		
;************************************************************************************
C_SCK_PIN				EQU		0x02
C_SDA_PIN				EQU		0x01
;************************************************************************************
;*																					*
;*      Data memory Define	                                                        *
;*																					*
;************************************************************************************
.PAGE0									;Define values in the range from 00h to FFh
GB_OpCode			DS		1
GB_Addr_HL			DS		1
GB_Addr_LH			DS		1
GB_Addr_LL			DS		1
GB_Rd_Buf			DS		1
GB_Wr_Buf			DS		1
;-----------------------------
GB_ReadFlag			DS		1
GB_Rd_OverFlag		DS		1
GB_Size_Cnt			DS		3
GB_Size_Cnt_LL		EQU		GB_Size_Cnt
GB_Size_Cnt_LH		EQU		GB_Size_Cnt+1
GB_Size_Cnt_HL		EQU		GB_Size_Cnt+2
;************************************************************************************
.DATA										;Define data storage section           

;************************************************************************************
;*																					*
;*      	 Program Area															*
;*																					*
;************************************************************************************
.CODE                   
;************************************************************************************
;*																					*
;*      Power on Reset Process	                                                    *
;*																					*
;************************************************************************************
;====================================================================================
;	Function:		F_SPR4096_Initial
;	Description:	Initialize the IO and Timer
;	Input:			none
;	Output:         none
;	Destroy:		A
;====================================================================================
.PUBLIC		F_SPR4096_Initial
F_SPR4096_Initial:
		;Initial SCK pin(PD1) output with low;
		;Initial SDA pin(PD0) output with low;		
		lda		#%00000000			;\
		sta		P_IOD_Data			;+	 
		lda		#%00000000			;+ = PD0~PD1-->output high
		sta		P_IOD_Attrib		;+	 
		lda		#%11111111			;+
		sta		P_IOD_Dir			;/		
		set		P_IOD_Data,1
		
		lda		#C_WDT_Clr
		sta		P_WDT_Clr  
		lda		#(C_WDT_SCKEN+C_WDT_Div_1024)
		sta		P_WDT_Ctrl
		sta		P_WDT_Ctrl
		M_StopSignal;						; stop signal
				
		lda		#128
		sta		P_TMR2_Count
		lda		#C_T2FCS_Div_8
		sta		P_TMR2_3_Ctrl1
		lda		#C_T28B_Timer		
		sta		P_TMR2_3_Ctrl0				;Timer2 counter overflow with 8KHz 
		
		lda     #C_T1FCS_Div_1              ;Timer1 Clock=8M 
		sta		P_TMR0_1_Ctrl1
		
		lda 	#$FF
		sta 	P_INT_Flag0 				;Clear INT request flag
		sta 	P_INT_Flag1 
		sta		P_INT_Flag2
	
		rts
;====================================================================================
;	Function:		F_ClrRAM
;	Description:	clear Ram
;	Input:			none
;	Output:         none
;	Destroy:		A
;====================================================================================  
F_ClrRAM:
        ldx     #$60             		; Clear RAM $80 ~ $FF
		lda     #$00
?L_ClrRAM:
		sta		$00,X			
        inx
        cpx		#$90
		bne		?L_ClrRAM
        rts 		
;====================================================================================
;	Function:		F_RdCtrl
;	Description:	get the size of the speech file 
;	Input:			none
;	Output:         none
;	Destroy:		A
;====================================================================================
.PUBLIC		F_RdCtrl
F_RdCtrl:
		lda		GB_ReadFlag
		bne		?L_RdID
		M_StartSignal;
		lda		#00100000B
		sta		GB_OpCode
		lda		#$00
		sta		GB_Addr_HL
		lda		#$00
		sta		GB_Addr_LH
		lda		#40
		sta		GB_Addr_LL					
		jsr		F_WrAddr
		inc		GB_ReadFlag	
		M_SetIO_Input;			
		jmp		?L_RdCtrlRts
?L_RdID:
		cmp		#$04
		bcs		?L_ENINT	
		jsr		F_Read8Bit	
		lda		GB_Rd_Buf	
		ldx		GB_ReadFlag		
		dex	
		sta		GB_Size_Cnt,x				;get the size of the file
		inc		GB_ReadFlag
		jmp		?L_RdCtrlRts
?L_ENINT:
		cmp		#$05
		bcs		?L_RdCtrlRts
		lda		#C_INT_T2OIE
		sta		P_INT_Ctrl1
;		lda		#C_T112B_PWM				;Set Timer1 is 12-bit PWM
;		sta		P_TMR0_1_Ctrl0
		lda		#$FF
		sta		P_TMR1_DutyPeriod
		lda		#0
      	sta		P_TMR1_PWMPeriod			;period low byte
		inc		GB_ReadFlag
		cli
?L_RdCtrlRts:
		rts
;====================================================================================
;	Function:		F_GetData
;	Description:	get the speech resource 
;	Input:			none
;	Output:         none
;	Destroy:		A
;====================================================================================
.PUBLIC		F_GetData
F_GetData:	
		lda		GB_Rd_OverFlag
		bne		?L_EndData
		jsr		F_Read8Bit		
		jsr		F_RdData_Cnt
		jmp		?L_RdCtrlRts		
?L_EndData:		
		jsr		F_RdEnd8Bit
		lda		#0							;disable Timer1 when play over
		sta		P_TMR0_1_Ctrl0
		lda		#0
		sta		P_INT_Ctrl1	
		M_SetIO_Output;	
		M_StopSignal;		
?L_RdCtrlRts:
		rts	
;====================================================================================
;	Function:		F_WrAddr
;	Description:	write SPR4096 address
;	Input:			GB_OpCode,GB_Addr_HL,GB_Addr_LH,GB_Addr_LL
;	Output:         none
;	Destroy:		A
;====================================================================================
.PUBLIC		F_WrAddr
F_WrAddr:
		lda		GB_OpCode
		sta		GB_Wr_Buf
		jsr		F_Write6Bit
		lda		GB_Addr_HL
		sta		GB_Wr_Buf
		jsr		F_Write3Bit
		lda		GB_Addr_LH
		sta		GB_Wr_Buf
		jsr		F_Write8Bit
		lda		GB_Addr_LL
		sta		GB_Wr_Buf
		jsr		F_Write8Bit
		rts		
;====================================================================================
;	Function:		F_Read8Bit
;	Description:	read 8 bit data
;	Input:			none
;	Output:         GB_Rd_Buf
;	Destroy:		A,Y
;====================================================================================
.PUBLIC			F_Read8Bit
F_Read8Bit:
		ldy		#8
?L_Loop:
		asl		GB_Rd_Buf
		lda		P_IOD_Data					;read the data				
		and		#%00000001
		ora		GB_Rd_Buf					
		sta		GB_Rd_Buf					;store the data to GB_Rd_Buf		
		jsr		F_CreateSCK
		dey
		bne		?L_Loop						
		rts
;====================================================================================
;	Function:		F_RdEnd8Bit
;	Description:	read the last 8 bit data
;	Input:			none
;	Output:         GB_Rd_Buf
;	Destroy:		A,Y
;====================================================================================
.PUBLIC			F_RdEnd8Bit
F_RdEnd8Bit:
		ldy		#8
?L_Loop:
		asl		GB_Rd_Buf
		lda		P_IOD_Data					;read the data				
		and		#%00000001
		ora		GB_Rd_Buf					
		sta		GB_Rd_Buf					;store the data to GB_Rd_Buf
		
		cpy		#1
		beq		?L_End	
		jsr		F_CreateSCK
		dey
		bne		?L_Loop
?L_End:
		jsr		F_CreateEndSCK						
		rts
;====================================================================================
;	Function:		F_Write8Bit
;	Description:	write 8 bit data
;	Input:			none
;	Output:         GB_Wr_Buf
;	Destroy:		A,Y
;====================================================================================
.PUBLIC			F_Write8Bit
F_Write8Bit:
		ldy		#8
?L_Loop:
		asl		GB_Wr_Buf					;the buffer shift left
		bcs		?L_Set_SDA
		M_ClrSDA;							;SDA export '0'
		jmp		?L_Check
?L_Set_SDA:
		M_SetSDA;							;SDA export '1'
?L_Check:
		jsr		F_CreateSCK
		dey
		bne		?L_Loop						
		rts
;====================================================================================
;	Function:		F_Write6Bit
;	Description:	write 6 bit data
;	Input:			none
;	Output:         GB_Wr_Buf
;	Destroy:		A,Y
;====================================================================================
.PUBLIC			F_Write6Bit
F_Write6Bit:
		ldy		#6
?L_Loop:
		lda		GB_Wr_Buf
		and		#00100000B
		bne		?L_Set_SDA
		M_ClrSDA;							;SDA export '0'
		jmp		?L_Check
?L_Set_SDA:
		M_SetSDA;							;SDA export '1'
?L_Check:
		asl		GB_Wr_Buf					;the buffer shift left
		jsr		F_CreateSCK
		dey
		bne		?L_Loop						
		rts	
;====================================================================================
;	Function:		F_Write3Bit
;	Description:	write 3 bit data
;	Input:			none
;	Output:         GB_Wr_Buf
;	Destroy:		A,Y
;====================================================================================
.PUBLIC			F_Write3Bit
F_Write3Bit:
		ldy		#3
?L_Loop:
		lda		GB_Wr_Buf
		and		#00000100B
		bne		?L_Set_SDA
		M_ClrSDA;							;SDA export '0'
		jmp		?L_Check
?L_Set_SDA:
		M_SetSDA;							;SDA export '1'
?L_Check:
		asl		GB_Wr_Buf					;the buffer shift left
		jsr		F_CreateSCK
		dey
		bne		?L_Loop						
		rts	
;====================================================================================
;	Function:		F_CreateSCK
;	Description:	create the clock
;	Input:			none
;	Output:         none
;	Destroy:		A
;====================================================================================
.PUBLIC		F_CreateSCK		
F_CreateSCK:
		M_ClrSCK;
		M_SckDelay
		M_SetSCK;
		M_SckDelay
		M_ClrSCK;
		rts
;====================================================================================
;	Function:		F_CreateEndSCK
;	Description:	create the last clock
;	Input:			none
;	Output:         none
;	Destroy:		A
;====================================================================================
.PUBLIC		F_CreateEndSCK		
F_CreateEndSCK:
		M_ClrSCK;
		M_SckDelay;
		M_SetSCK;
		rts

;====================================================================================
;	Function:		F_RdData_Cnt
;	Description:	check the end of the file
;	Input:			none
;	Output:         none
;	Destroy:		A
;====================================================================================
.PUBLIC		F_RdData_Cnt		
F_RdData_Cnt:
		sec
		lda		GB_Size_Cnt_LL
		sbc		#1
		sta		GB_Size_Cnt_LL
		lda		GB_Size_Cnt_LH
		sbc		#0
		sta		GB_Size_Cnt_LH
		lda		GB_Size_Cnt_HL
		sbc		#0
		sta		GB_Size_Cnt_HL
		ora		GB_Size_Cnt_LH
		ora		GB_Size_Cnt_LL
		bne		?L_RdDataRts
		lda		#$55
		sta		GB_Rd_OverFlag
		lda		#0							;Set Timer1 is 12-bit PWM
		sta		P_TMR0_1_Ctrl0
		sei	
?L_RdDataRts:
		rts
		

⌨️ 快捷键说明

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