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

📄 esl adc test.asm

📁 ELAN eAM eDSP esL Serial an assembly example that shows how to use the ADC,DAC,MIC macro
💻 ASM
字号:
.include		"vector.def"
.include		"register.def"
.include		"eSLMacro.def"
.include        "ADC.asm"
.include        "DAC.asm"
.include        "MIC.asm"
.include		"ReadKey.asm"

 P_init		.EQU	0x00FF

.GLOBAL			POWERON

.DATA 
;--------------------------------------------------------------------
; RAM define
;--------------------------------------------------------------------
 ReadKeyRAM  	 .DS    4
 Flow_flag	 .DS 	1
 BUF_PD		 .DS	1 

;--------------------------------------------------------------------
; 
;--------------------------------------------------------------------
.CODE
.include 		"eSLMSMacroDefine.def"
.include		"interruptvector.def"


;===============================================================

;===============================================================
POWERON:
	;------------------------------
	; I/O setting 
	;------------------------------
		R0	= #0xFFFF
		IO[PDIRA] 	=R0					;set portA = O/P, Lo
		IO[PCON1B] 	=R0					;set portBL = I/P, pull-up, wakeup
		R0	= #0x5555
		IO[PCON2B] 	=R0					;set portBH = O/P, Lo
		IO[PCONC] 	=R0					;set portC =  O/P, Lo 
	;------------------------------
	; clear	RAM
	;------------------------------
		R0=#0x0000
		R1=#0x0000
		R2=#@__LIB_INITIALSPA			;clear RAM from	#0x0000~#__LIB_INITIALSPA 
	    LOOP R2
	    NOP
	    NOP
		[R0++]=R1
	    .ENDL

    
	;------------------------------
	; Audio	initial	Setting
	;------------------------------
	AUDIO_INI							;speech and melody initial setting
	S1PWMON								;channel 1 play	from PWM OFF
	S1FILTERON
	MS2PWMON							;channel 2 play from PWM ON
	S2FILTERON

	;M_SPI_ON 0,0,0,0,0					;external spi flash initial setting
	;------------------------------
	; Set RAM initial 
	;------------------------------
		R0	= #0x0000
		IO[BSR] 	=R0
		
	;------------------------------
	; read key initial 
	;------------------------------
    R0=#P_init
 	R1=#(ReadKeyRAM+1)
    [R1]=R0
    
    
;------------------------------------------------------------
; MAIN Follow 
;------------------------------------------------------------
Main_Start:

	ReadKey #ReadKeyRAM,#P_init
	BTEST	R0.F_push
	IF TS	JMP	Main_CheckKeyin

Main_END:	
	JMP	SLEEP_Mode
	;==============================
	;------------------------------
	; Keyin check
	;------------------------------
Main_CheckKeyin:					
	   
		R0	=	R0 AND #0X0007			; for read key
		R0	=	SHL	R0
		R0	=	R0	+ #M_Keyin_Definition
	   JMP		R0
M_Keyin_Definition:
	LJMP	K1
	LJMP	K2
	LJMP	K3
	LJMP	K4
	LJMP	K5
	LJMP	K6
	LJMP	K7
	LJMP	K8
;==============================

;------------------------------------------------------------
; Polling Flow 
;------------------------------------------------------------
Main_play_polling:
	ReadKey #ReadKeyRAM,#P_init
	BTEST	R0.F_push
	IF TS	JMP	ReKeyin_CheckKeyin
	R0	=  Flow_flag
	R0	=  R0 AND #0X0007			
	IF NE	JMP	Main_loop

	;S1CHECK	Main_play_polling
	;S2CHECK	Main_play_polling

Main_Play_end:

	JMP	SLEEP_Mode
	;==============================
	;------------------------------
	; Rooling Folw
	;------------------------------
Main_loop:
		R0	= 	R0	-#1
		R0	=	SHL	R0
		R0	=	R0	+ #Rooling_Definition
	JMP		R0
Rooling_Definition:
	LJMP	Main_play_polling	;K1
	LJMP	K2_1				;K2
	LJMP	K3_1				;K3
	LJMP	K4_1				;K4	
	LJMP	K5_1				;K5
	LJMP	Main_play_polling	;K6
	LJMP	Main_play_polling	;K7
	LJMP	Main_play_polling	;K8
;==============================
	;------------------------------
	; ReKeyin check
	;------------------------------
ReKeyin_CheckKeyin:						; Keyin check

		R0	=	R0 AND #0X0007			; for read key
		R0	=	SHL	R0
		R0	=	R0	+ #ReKeyin_Definition
	JMP		R0
ReKeyin_Definition:
	LJMP	K1
	LJMP	K2
	LJMP	K3
	LJMP	K4	
	LJMP	K5
	LJMP	K6
	LJMP	K7
	LJMP	K8
;==============================

;------------------------------------------------------------
; Sleep mode 
;------------------------------------------------------------
SLEEP_Mode:

	MSTOP
	S1STOP
	S2STOP
	PLAYTAIL 100
	
		R0	= #0
		Flow_flag	= R0
;		IO[PORTA]	= R0		
;		IO[PORTB]	= R0		
;		IO[PORTC]	= R0		
;		IO[PORTD]	= R0		
	SLEEPMODE							; Into Sleep mode
	;------------------------------
	; Into Sleep ... 
	;------------------------------
	;Wake Up 
		NOP
		NOP	
		NOP
	JMP	Main_Start
;==============================

;------------------------------------------------------------
;
;------------------------------------------------------------
K1:		
	; ADC Single mode i/p form ch0 (XP)
	;------------------------------

	R0 	= #0				
	Flow_flag = R0				; clear rolling flow flag 
	
	R0	= #0
	BUF_PD	= R0				; clear data_buffer 

	BS	IO[SR].GIE				; GIE active
	BS	IO[INTE1].ADIE			; ADC Interrupt active 
		
	AD_SINGLE	0,6				; set ADC Single mode, ch0, clk6 (=FPLL/512)
	
ADC_WAIT:
		NOP
		NOP
		NOP						; wait ADC interrupt 
	BTEST	BUF_PD.0			; Check ADC convwe end ?
	IF TC	JMP	ADC_WAIT
	
	R0	= BUF_PD				; ADC trans OK, Read data
	IO[PORTA]	= R0			; out read data to PORT A
	
	BC	IO[SR].GIE				; Disable GIE
	BC	IO[INTE1].ADIE			; Disable ADC Interrupt 
	AD_OFF						; ADC OFF
								; Goto main flow

	JMP	Main_play_polling
;==============================
K2:
	; ADC Freerun mode i/p form ch0 (XP)
	;------------------------------
	R0 	= #0x0002	
	Flow_flag = R0				; set rolling flow flag 

	R0	= #0
	BUF_PD	= R0				; clear data_buffer 
	
	BS	IO[SR].GIE				; GIE active
	BS	IO[INTE1].ADIE			; ADC Interrupt active 
	
	AD_FREERUN	0,1				; set ADC FreeRun mode, ch0, clk1 (=FPLL/16)
K2_1:
	BC	BUF_PD.0
	
ADC_WAIT2:
		NOP
		NOP
		NOP						; wait ADC interrupt 
	BTEST	BUF_PD.0			; Check ADC convwe end ?
	IF TC	JMP	ADC_WAIT2
	
	R0	= BUF_PD				; ADC trans OK, Read data
	IO[PORTA]	= R0			; out read data to PORT A
								; Goto Main flow , read ADC again 
	
	JMP	Main_play_polling
;==============================
K3:
	; DAC o/p data form 0 to 0xFFF0 by add 0x0010
	;------------------------------
	R0 = #0x0003	
	Flow_flag = R0				; set main flow flag 

	DA_CON 0,0,7				; set DAC Un-Sign mode, always pass mode, vol=3mA max.
	
	
K3_1:

	R0	= #0x0000				; clear data

DAC_ADDone:		

	IO[0x007D]= R0


	DA_OUT		R0				; Out data to DAC

	IO[PORTA]= R0				; o/p data to PORT A

	R1	=#0x1FFF				; delay 
	LOOP	R1
		NOP
	.ENDL
	
	R0	= R0 + #16				; data+16
	IF	NE	JMP		DAC_ADDone
	
	JMP	Main_play_polling	
;==============================
K4:
	; DAC o/p data form 0xFFF0 to 0 by sub 0x0010
	;------------------------------
	R0 = #0x0004	
	Flow_flag = R0				; set main flow flag 

	DA_CON 0,0,7				; set DAC Un-Sign mode, always pass mode, vol=3mA max.

K4_1:
	R0	= #0xFFF0				; set data max.

DAC_SUBone:		

	IO[0x007D]= R0


	DA_OUT		R0				; Out data to DAC
	
	IO[PORTA]= R0				; o/p data to PORT A

	R1	=#0x1FFF				; delay 
	LOOP	R1
		NOP
	.ENDL
		
	R0	= R0 - #16				; data+16
	IF	NE	JMP		DAC_SUBone
								; Goto main flow, again 
	JMP	Main_play_polling		
;==============================
K5:
	; MIC i/p with ADC ch5 (PC5)
	;------------------------------
	R0 = #0x0005	
	Flow_flag = R0				; set main flow flag
	
	R0		= #0
	BUF_PD	= R0				; clear data_buffer 

	R0	= IO[PCONC]
	R0	= R0 OR #0x0C00
	IO[PCONC] 	=R0				;set portC.5 =  ADC input 
	
	BS	IO[SR].GIE				; GIE active
	BS	IO[INTE1].ADIE			; ADC Interrupt active 

	MIC_ON		1,2				; MIC ON, AGC ON, Gain = 3
	AD_FREERUN	5,1				; set ADC FreeRun mode, ch5, clk1 (=FPLL/16)

	DA_CON 		0,0,7			; set DAC Un-Sign mode, always pass mode, vol=3mA max.
K5_1:	
//	AD_SINGLE	5,1				; set ADC Single mode, ch5, clk1 (=FPLL/16)
	BC	BUF_PD.0

ADC_WAIT5:
		NOP	
		NOP	
		NOP						; wait ADC interrupt 
	BTEST	BUF_PD.0
	IF	TC	JMP	ADC_WAIT5
	
	R0	= BUF_PD				; ADC trans OK, Read data
	IO[PORTA]	= R0			; out read data to PORT A
	DA_OUT		R0				; Out data to DAC
	IO[0x007D]= R0

	JMP	Main_play_polling
;==============================
K6:

	JMP	Main_play_polling
;==============================
K7:

	JMP	Main_play_polling
;==============================
K8:

	BTEST	IO[INTE1].ADIE
	IF TC	JMP	ADC_END

K8_WAIT:
	BC	BUF_PD.0
		NOP
		NOP
		NOP
		NOP						; wait ADC interrupt 
	BTEST	BUF_PD.0
	IF TC	JMP	K8_WAIT

	R3	=  #90					; wait ADC 
	LOOP	R3
		NOP
	.ENDL

ADC_END:
	BC	IO[INTE1].ADIE			; Disable ADC Interrupt 
	BC	IO[SR].GIE				; Disable GIE

	AD_OFF
	MIC_OFF
	DA_OFF

	R0	= IO[PCONC]
	R0	= R0 AND #0x0500
	IO[PCONC] 	=R0				;set portC.5 =  O/P, Lo 

	R0 = #0
	Flow_flag = R0			
	
//	MSTOP
//	S1STOP
//	S2STOP
	
	JMP	Main_play_polling
;==============================

⌨️ 快捷键说明

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