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

📄 serial.asm

📁 uart-I2C, working on PIC18F2420
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	return
;----------------------------
state_aum
	bcf		FLAG1,b_pending
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error
;now send mute off
	bsf		FLAG2,b_tdaonly
	movlw	0x06
	movwf	current_subadd
	movlw	0x01
	movwf	current_data
	movlw	1
	movwf	current_channel
	call	send2TDA			;ch 1
	incf	current_channel,f
	call	wait_4
	call	send2TDA			;ch 2
	incf	current_channel,f
	call	wait_4
	call	send2TDA			;ch 3
	incf	current_channel,f
	call	wait_4
	call	send2TDA			;ch 4
	incf	current_channel,f
	call	wait_4
	call	send2TDA			;ch 5
	incf	current_channel,f
	call	wait_4
	call	send2TDA			;ch 6
;don't forget to clear the state....
	bcf		FLAG2,b_tdaonly
	clrf	current_state
	bcf		FLAG3,b_TILDA
	return	

wait_4
	call	WAIT_STATE
	call	WAIT_STATE
	call	WAIT_STATE
	call	WAIT_STATE
	return
;---------------------------------
state_avlx
	bcf		FLAG1,b_pending
	movlw	d'74'
	movwf	current_state
	clrf	vl_val				;clear holding spot
	call	convert_recbuff_dec ;convert first ascii value to hex
	movf	RECBUFF,w
	movwf	vl_val				;mov into temp vl_val variable
	swapf	vl_val,f			;swap into high byte
	return
state_avlxx
	bcf		FLAG1,b_pending
	movlw	d'76'
	movwf	current_state
	call	convert_recbuff_dec	;convert low byte into hex
	movf	RECBUFF,w
	addwf	vl_val,f			;by adding, we mov lowbyte into vl_val
;vl_val now holds full "decimal equivalent" of inputted volume, ie if you entered
;"35" in decimal, vl_val now holds "35", all though it is in HEX. Will have to 
;convert to a useabkle number before can use in lookup table (see "trans_vol")
;However, use this point to store current_volume settings for this channel.
	return

state_avlxx_end
	bcf		FLAG1,b_pending
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error
	clrf	current_state
;we have hex value in vl_val - need to convert through lookup into volume
;hex setting. vl_should hold 00-81....use STOR_VOL first!
	movlw	1
	movwf	current_channel
	call	stor_vol			;ch 1
	incf	current_channel,f
	call	stor_vol			;ch 2
	incf	current_channel,f
	call	stor_vol			;ch 3
	incf	current_channel,f
	call	stor_vol			;ch 4
	incf	current_channel,f
	call	stor_vol			;ch 5
	incf	current_channel,f
	call	stor_vol			;ch 6


;Rev 3.0 chnages to accept balance
;We will now use trans_vol twice, once for each side
;we return from stor-vol with value in w and current_vl_n

;send channel 1
	
	bsf		FLAG4,b_ch_left		;left side first, set flag for trans_vol to know is left
	call	trans_vol 
	movwf	current_data
	bsf		FLAG2,b_tdaonly
	movlw	1
	movwf	current_channel		;ch 1
	movlw	0x03
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE
;same for right
	call	trans_vol			;added 3.0
	movwf	current_data		;added 3.0
	movlw	0x04
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE

;send channel 2
	bsf		FLAG4,b_ch_left		;added 3.0
	call	trans_vol			;added 3.0
	movwf	current_data
	incf	current_channel,f	;ch 2
;now send volume left
	movlw	0x03
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE
;same for right
	call	trans_vol			;added 3.0
	movwf	current_data		;added 3.0
	movlw	0x04
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE

;send channel 3
	bsf		FLAG4,b_ch_left		;added 3.0
	call	trans_vol			;added 3.0
	movwf	current_data
	incf	current_channel,f	;ch 3
;now send volume left
	movlw	0x03
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE
;same for right
	call	trans_vol			;added 3.0
	movwf	current_data		;added 3.0
	movlw	0x04
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE

;send channel 4
	bsf		FLAG4,b_ch_left		;added 3.0
	call	trans_vol			;added 3.0
	movwf	current_data
	incf	current_channel,f	;ch 4
;now send volume left
	movlw	0x03
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE
;same for right
	call	trans_vol			;added in 3.0
	movwf	current_data		;added in 3.0
	movlw	0x04
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE


;send channel 5
	bsf		FLAG4,b_ch_left		;added 3.0
	call	trans_vol			;added 3.0
	movwf	current_data
	incf	current_channel,f	;ch 5
;now send volume left
	movlw	0x03
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE
;same for right
	call	trans_vol			;added 3.0
	movwf	current_data		;added 3.0
	movlw	0x04
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE

;channel 6
	bsf		FLAG4,b_ch_left		;added 3.0
	call	trans_vol			;added 3.0
	movwf	current_data
	incf	current_channel,f	;ch 6
;now send volume left
	movlw	0x03
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE
;same for right
	call	trans_vol			;add 3.0
	movwf	current_data		;add 3.0
	movlw	0x04
	movwf	current_subadd
	call	send2TDA
	call	WAIT_STATE
	call	WAIT_STATE

;don't forget to clear the state....
	bcf		FLAG2,b_tdaonly
	clrf	current_state
	bcf		FLAG3,b_TILDA
	return

;---------------------------------
state_aslx
	bcf		FLAG1,b_pending
	movlw	d'78'
	movwf	current_state
	movf	RECBUFF,w
	call	convert_recbuff_dec
	movf	RECBUFF,w
	movwf	current_data
	return
state_asl_end
	bcf		FLAG1,b_pending
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error


;We need to use the decode and send routine as a call - else we will be copying it 6 times!
	bsf		FLAG2,b_tdaonly
	movlw	1
	movwf	current_channel
	movf	current_data,w
	movwf	sl_data				;Will need backup copy of data if input 4-7
	call	all_select			;ch 1

	incf	current_channel,f
	movf	sl_data,w
	movwf	current_data		;restore data
	call	all_select			;ch 2

	incf	current_channel,f
	movf	sl_data,w
	movwf	current_data
	call	all_select			;ch 3

	incf	current_channel,f
	movf	sl_data,w
	movwf	current_data
	call	all_select			;ch 4

	incf	current_channel,f
	movf	sl_data,w
	movwf	current_data
	call	all_select			;ch 5

	incf	current_channel,f
	movf	sl_data,w
	movwf	current_data
	call	all_select			;ch 6

	bcf		FLAG2,b_tdaonly
	clrf	current_state
	bcf		FLAG3,b_TILDA
	movf	sl_data,w
	movwf	current_sl_1	;current input for channel 1
	movwf	current_sl_2	;current input for channel 2
	movwf	current_sl_3	;current input for channel 3
	movwf	current_sl_4	;current input for channel 4
	movwf	current_sl_5	;current input for channel 5
	movwf	current_sl_6	;current input for channel 6
	return

all_select
;current data is a little more tricky...
;inputs 7-5 are tarnslated to input 4 (switching is external through the mux)
;now we need to send the current channel and decode the current input,
; and send it to the TDA using state8 routine

	clrf	current_subadd		;sub address is 0 for input select
	movlw	d'7'
	cpfseq	current_data
	bra		sa9_2
	call	ain6k7
	movlw	0x023
	movwf	current_data				;see data table for tda
	call 	send2TDA
	return
sa9_2
	movlw	d'6'
	cpfseq	current_data
	bra		sa9_3
	call	ain6k7
	movlw	0x023				;see data table for tda
	movwf	current_data
	call 	send2TDA
	return
sa9_3
	movlw	d'5'
	cpfseq	current_data
	bra		sa9_4
	call	ain6k7
	movlw	0x023				;see data table for tda
	movwf	current_data
	call 	send2TDA
	return
sa9_4
	movlw	d'4'
	cpfseq	current_data
	bra		sa9_5
	call	ain6k7
	movlw	0x023
	movwf	current_data
	call	send2TDA
	return
sa9_5
	movlw	d'3'
	cpfseq	current_data
	bra		sa9_6
	movlw	0x022
	movwf	current_data
	call	send2TDA
	return
sa9_6
	movlw	d'2'
	cpfseq	current_data
	bra		sa9_7
	movlw	0x021
	movwf	current_data
	call	send2TDA
	return
sa9_7
	movlw	0x020
	movwf	current_data
	call	send2TDA
	return

;only use this section if it is a 6K7....
ain6k7
	movf	current_data,w
	movwf	I2CBUF2				;copy current input into send buffer
	swapf	I2CBUF2,f			;mov to high nibble
	movf	current_channel,w	;copy current channel into w
	iorwf	I2CBUF2,f			;logical or with send buffer
;format for channel/input -
;upper nibble is source (4/5/6/7)
;lower nibble is channel (1-6)
;example - set channel 6 to input 1 = 0110 0001 or 0x061 hex
	call	START_PIC
	call	SEND_PIC
	btfsc	FLAG2,b_ACKERROR2
	call	String_ERROR4	
	bcf		FLAG2,b_ACKERROR2	
	call	STOP_PIC
	return

state_aof
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error
;now goto all off - use same as keypads...or call it?
	call	k_all_off			;k_done returns, better call :)		


;don't forget to clear the state....
	bcf		FLAG1,b_pending
	bcf		FLAG2,b_tdaonly
	clrf	current_state
	bcf		FLAG3,b_TILDA
	return	






;--------------------------------------------------------------------------------------------------------------
stateb
;--------------------------------------------------------------------------------------------------------------
;we have a b, now get value. Then merge back with current_bt and send...

	bcf		FLAG1,b_pending
;"b" got us here, now load state for "bx" and return
	movlw	d'46' 					;point to bx
	movwf	current_state
	return
statebx
	bcf		FLAG1,b_pending
	movlw	d'48'					;point to bx_end
	movwf	current_state
	call	convert_recbuff_dec		;convert ASCII TO HEX
	call	translate_bt			;translate the RECBUFF from 0-15 into useable character set
;hit the correct channel!

	nop
	movf	PCL,w					;false read to update PCU,PCH
	rlncf	current_channel,w
	addwf	PCL,F					;jump to correct TDA!
	nop								;place holder - cannot be 0
	bra		bx1
	bra		bx2
	bra		bx3
	bra		bx4
	bra		bx5
	bra		bx6

bx1 
	movlw	0x0f
	andwf	current_bt1,f			;clear upper nibble of bt1				
	swapf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt1,f			;new value into bt1
	movf	current_bt1,w			;into w
	movwf	current_data
	return
bx2 
	movlw	0x0f
	andwf	current_bt2,f			;clear upper nibble of bt1				
	swapf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt2,f			;new value into bt1
	movf	current_bt2,w			;into w
	movwf	current_data
	return	
bx3 
	movlw	0x0f
	andwf	current_bt3,f			;clear upper nibble of bt1				
	swapf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt3,f			;new value into bt1
	movf	current_bt3,w			;into w
	movwf	current_data
	return
bx4 
	movlw	0x0f
	andwf	current_bt4,f			;clear upper nibble of bt1				
	swapf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt4,f			;new value into bt1
	movf	current_bt4,w			;into w
	movwf	current_data
	return
bx5 
	movlw	0x0f
	andwf	current_bt5,f			;clear upper nibble of bt1				
	swapf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt5,f			;new value into bt1
	movf	current_bt5,w			;into w
	movwf	current_data
	return
bx6 
	movlw	0x0f
	andwf	current_bt6,f			;clear upper nibble of bt1				
	swapf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt6,f			;new value into bt1
	movf	current_bt6,w			;into w
	movwf	current_data
	return
statebx_end
	bcf		FLAG1,b_pending
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error
;we have hex value in current_bt(n), whre (n) = channel
;send bt
	movlw	0x05
	movwf	current_subadd
	bsf		FLAG2,b_tdaonly
	call	send2TDA
;don't forget to clear the state....
	bcf		FLAG2,b_tdaonly
	clrf	current_state
	bcf		FLAG3,b_TILDA

	call	save_bt

	return


;--------------------------------------------------------------------------------------------------------------
statet
;--------------------------------------------------------------------------------------------------------------
;we have a t, now get value. Then merge back with current_bt and send...

	bcf		FLAG1,b_pending
;"t" got us here, now load state for "tx" and return
	movlw	d'50' 	;point to tx
	movwf	current_state
	return
statetx
	bcf		FLAG1,b_pending
	movlw	d'52'	;point to tx_end
	movwf	current_state
	call	convert_recbuff_dec		;convert ASCII TO HEX
	call	translate_bt			;translate the RECBUFF from 0-15 into useable character set
;hit the correct channel!
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop


	nop
	movf	PCL,w					;false read to update PCU,PCH
	rlncf	current_channel,w
	addwf	PCL,F					;jump to correct TDA!
	nop								;place holder - cannot be 0
	bra		tx1
	bra		tx2
	bra		tx3
	bra		tx4
	bra		tx5
	bra		tx6

tx1 
	movlw	0xf0
	andwf	current_bt1,f			;clear upper nibble of bt1				
	movf	RECBUFF,w
	iorwf	current_bt1,f			;new value into bt1
	movf	current_bt1,w			;into w
	movwf	current_data
	return
tx2 
	movlw	0xf0
	andwf	current_bt2,f			;clear upper nibble of bt1				
	movf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt2,f			;new value into bt1
	movf	current_bt2,w			;into w
	movwf	current_data
	return	
tx3 
	movlw	0xf0
	andwf	current_bt3,f			;clear upper nibble of bt1				
	movf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt3,f			;new value into bt1
	movf	current_bt3,w			;into w
	movwf	current_data
	return
tx4 
	movlw	0xf0
	andwf	current_bt4,f			;clear upper nibble of bt1				
	movf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt4,f			;new value into bt1
	movf	current_bt4,w			;into w
	movwf	current_data
	return
tx5 
	movlw	0xf0
	andwf	current_bt5,f			;clear upper nibble of bt1				
	movf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt5,f			;new value into bt1
	movf	current_bt5,w			;into w
	movwf	current_data
	return
tx6 
	movlw	0xf0
	andwf	current_bt6,f			;clear upper nibble of bt1				
	movf	RECBUFF,w				;move new bass value into high byte in w
	iorwf	current_bt6,f			;new value into bt1
	movf	current_bt6,w			;into w
	movwf	current_data
	return
statetx_end
	bcf		FLAG1,b_pending
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error

⌨️ 快捷键说明

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