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

📄 serial.asm

📁 uart-I2C, working on PIC18F2420
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;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

;---------------------------------
translate_bt
;---------------------------------
;value ot be translated is in the recbuff, 0-e, f same as zero, not allowed

	nop
	movf	PCL,w					;false read to update PCU,PCH
	rlncf	RECBUFF,w
	addwf	PCL,F					;jump to data translate
	bra		bt0
	bra		bt1
	bra		bt2
	bra		bt3
	bra		bt4
	bra		bt5
	bra		bt6
	bra		bt7
	bra		bt8
	bra		bt9
	bra		bt10
	bra		bt11
	bra		bt12
	bra		bt13
	bra		bt14
	bra		bt15

bt0						;0 = -14dB, no change
	return
bt1						;1 = -12dB
	return
bt2						;2 = -10dB
	return
bt3						;3 = -8dB
	return
bt4						;4 = -6dB
	return
bt5						;5 = -4dB
	return
bt6						;6 = -2dB
	return
bt7						;7 = 0Db, no change (default)
	return
bt8						;0x0E = 2dB
	movlw	0x0e
	movwf	RECBUFF
	return
bt9						;0x0D = 4dB
	movlw	0x0d
	movwf	RECBUFF
	return
bt10
	movlw	0x0c		;0x0C = 6dB
	movwf	RECBUFF
	return
bt11
	movlw	0x0b		;0x0B = 8dB
	movwf	RECBUFF
	return
bt12
	movlw	0x0a		;0x0A = 10dB
	movwf	RECBUFF
	return
bt13
	movlw	0x09		;0x09 = 12dB
	movwf	RECBUFF
	return
bt14
	movlw	0x08		;0x08 = 14dB
	movwf	RECBUFF
	return
bt15
	return

;--------------------------------------------------------------------------------------------------------------
statev
;--------------------------------------------------------------------------------------------------------------
;we have a v, can be vr, vl

	bcf		FLAG1,b_pending
	movlw	d'04'
	cpfseq	current_state		;where was I?
	bra		s2_0				;not here yet!
	bra		s2_1				;okay, I was already here....	
s2_0
	movwf	current_state
	return						;we have v, return wait for next char
s2_1
	movlw	"r"
	cpfseq	RECBUFF
	bra		statevl

;--------------------------------------------------------------------------------------------------------------
statevr
;--------------------------------------------------------------------------------------------------------------
;we have a vr, now look for ?
	bcf		FLAG1,b_pending
	movlw	d'6'
	cpfseq	current_state
	bra		svr_0
	bra		svr_1
svr_0
	movwf	current_state				
	return							;we have vr, now return wait for ?

svr_1
	movlw	"?"
	cpfseq	RECBUFF
	goto	command_error
	movlw	d'8'
	movwf	current_state
	return
;-------------------------------------------------------------------------------------------------------------
statevr?
;-------------------------------------------------------------------------------------------------------------
	bcf		FLAG1,b_pending
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error

	call	String_VERSION
;send whatami
	movlw	00
	cpfseq	whatami					;skip if a 6K4
	bra		boot_0					;if whatami = 1 then 6K7
	call	ima6k4
	bra		boot_1
boot_0
	call	ima6k7
boot_1
	bcf		FLAG3,b_TILDA
	clrf	current_state	
	return

;--------------------------------------------------------------------------------------------------------------
statevl
;--------------------------------------------------------------------------------------------------------------
;we either have a vl or an error

	movlw	"l"
	cpfseq	RECBUFF
	goto	command_error
	movlw	d'12'
	movwf	current_state
	return

statevlx
	bcf		FLAG1,b_pending
	movlw	"?"
	cpfseq	RECBUFF
	bra		statevlx0
	goto	statevl?			;goto request volume
statevlx0						;must be set volume command
	movlw	d'14'
	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
statevlxx
	bcf		FLAG1,b_pending
	movlw	d'16'
	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.
	call	stor_vol

	return
statevlxx_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....

	bsf		FLAG4,b_ch_left		;add 3.0
	call	trans_vol 	
	movwf	current_data
;now send volume left
	movlw	0x03
	movwf	current_subadd
	bsf		FLAG2,b_tdaonly
	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

stor_vol				;stores current channel volume on volume command
	movf	PCL,w					;false read to update PCU,PCH
	rlncf	current_channel,w
	addwf	PCL,F					;jump to corrent channel storage
	nop
	bra		stor_1
	bra		stor_2
	bra		stor_3
	bra		stor_4
	bra		stor_5
	bra		stor_6

stor_1
	movf	vl_val,w
	movwf	current_vl_1
	return
stor_2
	movf	vl_val,w
	movwf	current_vl_2
	return
stor_3
	movf	vl_val,w
	movwf	current_vl_3
	return
stor_4
	movf	vl_val,w
	movwf	current_vl_4
	return
stor_5
	movf	vl_val,w
	movwf	current_vl_5
	return
stor_6
	movf	vl_val,w
	movwf	current_vl_6
	return

get_vol								;retrieves current channel volume

	nop
	movf	PCL,w					;false read to update PCU,PCH
	rlncf	current_channel,w
	addwf	PCL,F					;jump to corrent channel storage
	nop
	bra		get_vol1
	bra		get_vol2
	bra		get_vol3
	bra		get_vol4
	bra		get_vol5
	bra		get_vol6

get_vol1
	movf	vl_1,w
	return
get_vol2
	movf	vl_2,w
	return
get_vol3
	movf	vl_3,w
	return
get_vol4
	movf	vl_4,w
	return
get_vol5
	movf	vl_5,w
	return
get_vol6
	movf	vl_6,w
	return

statevl?
	movlw	d'54'
	movwf	current_state
	return
statevl?_end
	bcf		FLAG1,b_pending
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error
	clrf	current_state
;we have current channel, now we need to retrieve the volume
	call	get_vol		;retrieves current channel volume in w
	movwf	SENDBUFF
	call	tx_dec		;transmit the dec byte
	clrf	current_state
	bcf		FLAG3,b_TILDA
	return	


state3
	bcf		FLAG1,b_pending
	movlw d'18'
	cpfseq	current_state
	bra		state3_0
	bra		state3_1
state3_0
	movwf	current_state			;first time here, we have "r"
	return
state3_1
	movlw	"x"
	cpfseq	RECBUFF
	goto	command_error		
	movlw	d'20'
	movwf	current_state
	return

staterx_end
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error
	RESET
	return

state4

	return
state5
	bcf		FLAG1,b_pending
	bcf		FLAG3,b_TILDA

;TDA1
	movlw	TDA_ADDRESS
	movwf	I2CBUF

	call	START_TDA1				;start condition to TDA1
	call	SEND_TDA1
	call	STOP_TDA1
	btfss	FLAG3,b_ACKERROR		;look for ack_error
	bra		s5_0
	call	String_NO_ACK_TDA1
	bra		s5_1
s5_0
	call	String_ACK_TDA1

;TDA2
s5_1
	movlw	TDA_ADDRESS
	movwf	I2CBUF

	call	START_TDA2				;start condition to TDA2
	call	SEND_TDA2
	call	STOP_TDA2
	btfss	FLAG3,b_ACKERROR		;look for ack_error
	bra		s5_2
	call	String_NO_ACK_TDA2
	bra		s5_3
s5_2
	call	String_ACK_TDA2

;TDA3
s5_3
	movlw	TDA_ADDRESS
	movwf	I2CBUF
	call	START_TDA3				;start condition to TDA3
	call	SEND_TDA3
	call	STOP_TDA3
	btfss	FLAG3,b_ACKERROR		;look for ack_error
	bra		s5_4
	call	String_NO_ACK_TDA3
	bra		s5_5
s5_4
	call	String_ACK_TDA3

;TDA4
s5_5
	movlw	TDA_ADDRESS
	movwf	I2CBUF	
	call	START_TDA4				;start condition to TDA4
	call	SEND_TDA4
	call	STOP_TDA4
	btfss	FLAG3,b_ACKERROR		;look for ack_error
	bra		s5_6
	call	String_NO_ACK_TDA4
	bra		s5_7
s5_6
	call	String_ACK_TDA4

;TDA5
s5_7
	movlw	TDA_ADDRESS
	movwf	I2CBUF
	call	START_TDA5				;start condition to TDA5
	call	SEND_TDA5
	call	STOP_TDA5
	btfss	FLAG3,b_ACKERROR		;look for ack_error
	bra		s5_8
	call	String_NO_ACK_TDA5
	bra		s5_9
s5_8
	call	String_ACK_TDA5

;TDA6
s5_9
	movlw	TDA_ADDRESS
	movwf	I2CBUF
	call	START_TDA6				;start condition to TDA6
	call	SEND_TDA6
	call	STOP_TDA6
	btfss	FLAG3,b_ACKERROR		;look for ack_error
	bra		s5_10
	call	String_NO_ACK_TDA6
	bra		s5_11
s5_10
	call	String_ACK_TDA6
s5_11
	return


state6
	movlw	d'22'
	cpfseq	current_state
	bra		s6_0
	bra		s6_00
;already been here, expecting next char
s6_0
	movwf	current_state	;set to here
	return					;first time through, just set state to state4 and return
							;pending is already cleared in state0
s6_00
	bcf		FLAG1,b_pending
	movlw	"n"
	cpfseq	RECBUFF
	bra		s6_1

	movlw	d'24'
	movwf	current_state
	return
s6_1
	movlw	"f"
	cpfseq	RECBUFF
	goto	command_error
	movlw	d'26'
	movwf	current_state
	return



state_on
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error

	bcf		FLAG1,b_pending
	bcf		FLAG3,b_TILDA
	clrf	current_state

	nop
	movf	PCL,w					;false read to update PCU,PCH
	rlncf	current_channel,w
	addwf	PCL,F					;jump to next state!

	nop								;place holder - cannot be 0
	bra		on1
	bra		on2
	bra		on3
	bra		on4
	bra		on5
	bra		on6

on1	bsf	AMP1
	bsf	CHANNELS,1
	return
on2	bsf	AMP2
	bsf	CHANNELS,2
	return
on3	bsf	AMP3
	bsf	CHANNELS,3
	return
on4	bsf	AMP4
	bsf	CHANNELS,4
	return
on5	bsf	AMP5
	bsf	CHANNELS,5
	return
on6	bsf	AMP6
	bsf	CHANNELS,6
	return		

state_off
	movlw	")"
	cpfseq	RECBUFF
	goto	command_error

	bcf		FLAG1,b_pending
	bcf		FLAG3,b_TILDA
	clrf	current_state
	movf	PCL,w					;false read to update PCU,PCH
	rlncf	current_channel,w
	addwf	PCL,F					;jump to next state!
	nop								;place holder - cannot be 0
	bra		of1
	bra		of2
	bra		of3
	bra		of4
	bra		of5
	bra		of6

of1	bcf	AMP1
	bcf	CHANNELS,1
	movlw	d'14'
	movwf	combyte
	call	talk2
	return

of2	bcf	AMP2
	bcf	CHANNELS,2
	movlw	d'14'
	movwf	combyte
	call	talk2
	return

of3	bcf	AMP3
	bcf	CHANNELS,3
	movlw	d'14'
	movwf	combyte
	call	talk2
	return

of4	bcf	AMP4
	bcf	CHANNELS,4
	movlw	d'14'
	movwf	combyte
	call	talk2
	return

of5	bcf	AMP5
	bcf	CHANNELS,5
	movlw	d'14'
	movwf	combyte
	call	talk2
	return

of6	bcf	AMP6
	bcf	CHANNELS,6
	movlw	d'14'
	movwf	combyte
	call	talk2
	return		

statem
	movlw	d'28'
	cpfseq	current_state
	bra		sm_0
	bra		sm_1
sm_0
	movwf	current_state
	return
sm_1
	bcf		FLAG1,b_pending
	movlw	"u"
	cpfseq	RECBUFF
	goto	command_error
	movlw	d'30'
	movwf	current_state
	return
statem_end
	movlw	")"

⌨️ 快捷键说明

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