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

📄 microp2dsp.bk3

📁 This program allows reading or writing values to and from the DSP through hyperterminal serial por
💻 BK3
字号:

;FILE: microp2dsp.ASM
;
; This program allows reading or writing values to and from the DSP
; through hyperterminal serial port interface.
;
; command -- function description
; dr.... -- data memory read, eg dr22aa, reading data mem 0x22aa
; dw.... xxxx -- data memory write, eg dw22aa 12bb, writing data mem addr=0x22aa value = 0x12bb
; pr.... -- prog memory read, eg pr22aa, reading prog mem 0x22aa
; pw.... xxxx -- prog memory write, eg pw22aa 12bbcc, writing prog mem addr=0x22aa value =0x12bbcc
;
; register used:
; R0,1,2,3,4,5 in bank 0
; R0,1,2,3,4,5	in bank 1, 0xe,f,a,b,c
; A
;
; by Francis Tiong
; 11th July 2005
;

;	PCON EQU 87H

	ORG 00H
	JMP MAIN

	ORG 23H
	RET

	ORG 40H

MAIN:   CLR C					;zero ALU carry flag
	
								;8E=address of AUXR
	MOV 8EH, #03H				;set EXTRAM and AO to one
								;AO one will disable ALE	

	MOV P1, #02					;p1.0 = cs = LOW, p1.1=rst = HIGH

; setting timer and serial port
	MOV SCON,#50H             	;SET SERIAL PORT FOR MODE 1 OPERATION
	MOV PCON,#80H		  		;80h SET DOUBLE BAUD RATE BIT to 38.4k
	MOV TMOD,#20H           	;SET TIMER 1 TO AUTO RELOAD
    MOV TH1,#0FDH           	;LOAD RELOAD VALUE FOR 19.2k BAUD AT 16MHZ
    MOV TCON,#40H           	;START TIMER 1
    CLR TI
	MOV SBUF,#62H            	;TRANSMIT b=62 HEX OUT THE TXD LINE

	MOV A, #20H		 			;transmit space
	CALL TRANS_BYTE

; begin 
label:	nop

	CALL RECEI_BYTE

;test
	MOV A, #62H		 			;transmit space
	CALL TRANS_BYTE
	SJMP label
;test

; check for commands, mem flag
	MOV     R2, #0				; R2 = flag for dm=0x40 or pm dm=0
	CJNE	A,#64H,check_p		; d = 0x64

; command 'd' received
	MOV 	R2, #40H
	SJMP	GOT_MEM_FLAG
		
check_p: CJNE	A,#70H,label	; p = 0x70
	
GOT_MEM_FLAG:	CALL TRANS_BYTE


; check for commands, read/write flag	
	CALL RECEI_BYTE

	MOV     R4, #0		; R4 = flag for read=0 or write =1
	CJNE	A,#77H,check_r		; w = 0x77

	; command 'd' received
	MOV 	R4, #1H
	SJMP	GOT_RW_FLAG
		
check_r:	CJNE	A,#72H,label		; R = 0x72
	
GOT_RW_FLAG:	CALL TRANS_BYTE


; get high byte of address , send in addr 04
	CALL GET_BCD			; getting a BCD valued byte in A

	ORL	A, R2			; mem flag set in
					; high byte ready

	MOV	R0, #04H	; R0= external address
	MOVX	@R0, A

; get low byte of address , send in addr 05
	CALL GET_BCD			; getting a BCD valued byte in A

	MOV	R0, #05H	; R0= external address
	MOVX	@R0, A

; send RW request in addr 02

	MOV	A, R4
	MOV	R0, #02H	; R0= external address
	MOVX	@R0, A

; check R or W , if W then fetch 16-bit data word

	DJNZ	R4, DO_READ

;write command process
PROCESS_WRITE_CMD:	CALL RECEI_BYTE				; expect one space between address and data
	CJNE	A,#20H,PROCESS_WRITE_CMD	; space = 0x20

	CALL TRANS_BYTE

	MOV	R0, #06H	; R0= external address, send to addr 6

	; get high byte of data
	CALL GET_BCD			; getting a BCD valued byte in A
	MOV	0CH, A			; high byte

	; get low byte of data
	CALL GET_BCD			; getting a BCD valued byte in A
	MOV	0BH, A			; 

	;if PM write then there is one more
	CJNE	R2,#0H,WRITE_CMD_DM	; if R2!=0 then DM

	CALL GET_BCD			; getting a BCD valued byte in A
	MOV	0AH, A			; lowest byte

	
; sending data out, high order byte first
WRITE_CMD_DM:	MOV	A, 0CH
	MOVX	@R0, A

	MOV	A, 0BH
	MOVX	@R0, A
	
	CJNE	R2,#0H,label	; if R2!=0 then DM

	MOV	A, 0AH
	MOVX	@R0, A

        JMP label                  ;DO IT ALL OVER AGAIN	


;READ command process		
DO_READ:	MOV	A, #20H		;sending a space
	CALL 	TRANS_BYTE

	; get two nibbles
	MOV	R0, #06H	;get one byte from DSP
	MOVX	A, @R0

	MOV	R5,A		;R5= raw 2x 4 bits received

	; do nibble 0
	CALL	BCD_ASCII	;input in A, return in A


	MOV	0EH, A		;using location 13,12,11,10,9,8 to store result

	MOV	A, R5
	SWAP 	A

	; do nibble 1
	CALL	BCD_ASCII	;input in A, return in A

	MOV	0FH, A		;using location 13,12,11,10,9,8 to store result

	; get two nibbles
	MOV	R0, #06H	;get one byte from DSP
	MOVX	A, @R0

	MOV	R5,A		;R5= raw 2x 4 bits received

	; do nibble 2
	CALL	BCD_ASCII	;input in A, return in A
	
	MOV	0AH, A		;using location 13,12,11,10,9,8 to store result

	MOV	A, R5
	SWAP 	A

	; do nibble 3
	CALL	BCD_ASCII	;input in A, return in A
	
	MOV	0BH, A		;using location 13,12,11,10,9,8 to store result


	;check to see if PM word, if so then read two more nibbles
	CJNE	R2, #0, READ_DONE

	; get two nibbles
	MOV	R0, #06H	;get one byte from DSP
	MOVX	A, @R0

	MOV	R5,A		;R5= raw 2x 4 bits received

	; do nibble 4
	CALL	BCD_ASCII	;input in A, return in A
	
	MOV	0CH, A		;using location 13,12,11,10,9,8 to store result

	MOV	A, R5
	SWAP 	A

	; do nibble 5
	CALL	BCD_ASCII	;input in A, return in A
	
	MOV	0DH, A		;using location 13,12,11,10,9,8 to store result

	;done getting ASCII values, now send to screen
READ_DONE:	MOV	A, 0FH
	CALL 	TRANS_BYTE

	MOV	A, 0EH
	CALL 	TRANS_BYTE

	MOV	A, 0BH
	CALL 	TRANS_BYTE

	MOV	A, 0AH
	CALL 	TRANS_BYTE

	;check to see if PM word, if so then read two more nibbles
	CJNE	R2, #0, end_rd_done

	MOV	A, 0DH
	CALL 	TRANS_BYTE

	MOV	A, 0CH
	CALL 	TRANS_BYTE

end_rd_done:	nop
        JMP label                  ;DO IT ALL OVER AGAIN


; receive byte
; return value in A
RECEI_BYTE:        JNB     RI,$            ;Wait until character received.
        MOV     A,SBUF          ;Read input character.
	CLR	RI		;Clear reception flag.
	RET

;transmit byte
; transmit value in A
TRANS_BYTE:        JNB TI,$                  ;WAIT UNTIL TRANSMISSION COMPLETED
        CLR TI                    ;READY TO TRANSMIT ANOTHER
	MOV SBUF,A
	RET

;Converting ASCII value to BCD value
;Input A, Output A
ASCII_BCD:	MOV	R1,A		;R1= raw received byte
	SUBB 	A, #57H		;subtract to check whether it is numbers or letters
				;subtract to get back value from ASCII format
	MOV	20H,A		;20= temp testing location

	JNB	20H.7,RECEIVE_LTR	; check sign bit of R2

	MOV	A, R1		
	SUBB 	A, #2FH		;subtract to get back value from ASCII format

RECEIVE_LTR:	NOP
	RET

; Returning one byte address or data in BCD form in A
GET_BCD:	CALL RECEI_BYTE		;getting first nibble of BCD value
	CALL TRANS_BYTE

	CALL ASCII_BCD		; input A return A

	SWAP	A		;high nibble now in place
	MOV	R3,A		;R3= holding output byte
	
	CALL RECEI_BYTE		;getting second nibble of BCD value
	CALL TRANS_BYTE

	CALL ASCII_BCD		; input A return A

	ORL	A, R3		;put low nibble together with high nibble

;	MOV	P0, A		; output to port 0

	RET

; Convert BCD nibble in A to ASCII value
; Input value in A, return values in A
BCD_ASCII:	ANL	A, #0FH		;do low nibble 

	MOV	R1, A		;R1= current processing nibble
	SUBB 	A, #0AH		;subtract to check whether it is numbers or letters
				
	MOV	20H,A		;20= temp testing location
	MOV	A, R1		
	ADD 	A, #30H		;ADD to get ASCII format

	JB	20H.7,GOT_NUMBERS_DONE	; check sign bit, if neg then is number

	;got letters
	ADD 	A, #27H		;57H-30H=27H, ADD to get ASCII format	

GOT_NUMBERS_DONE:	NOP		

	RET

        END

⌨️ 快捷键说明

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