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

📄 rs232.asm

📁 用CY7C630芯片做USB转串口的汇编原程序,里面有编译生成的hex文件.写入芯片就可使用.最高波特率为24
💻 ASM
📖 第 1 页 / 共 2 页
字号:
          pop     A                         ; Restore the accumulator.
          ret                               ; Return to sender.
  ;
  txWait:
  ;  Wait for the next 128us interrupt.
  	mov	A, 02h		          ; Load 128us ISR Enable value.
  	iowr	Global_Interrupt	; Enable 128us ISR.
  	jmp	txWait		          ; Loop until 128us Interrupt.
  ;
  ;************************************************************************
  ; RX_Data processing:
  ; This routine will read in a byte of data from the 8051 UART.
  ; The receive subroutine is entered whenever the One_mSec_ISR occurs if
  ; rxEnable is set.
  ; The received data byte is stored in the receive buffer.
  ; If stop bit is invalid send a framing error to 8051 and discard data.
  ;************************************************************************
  ;
  rxRoutine:
  ;
  ;  A new 128us interrupt has occurred.
  ;  Check the frame count and send a bit if required.
  	push	A		 	          ; Save the accumulator.
  	mov	A, [rxFrameCount] ; Get rx frame count.
  	cmp	A, rxStart 	      ; Start bit at frame count=01h.
  	jz	getrxStart 	      ; Go get Start bit.
  	cmp	A, rxBit0 	      ; Data bit 0 at frame count=05h.
  	jz	getrxBit 	        ; Go get data bit.
  	cmp	A, rxBit1 	      ; Data bit 1 at frame count=09h.
  	jz	getrxBit 	        ; Go get data bit under test.
  	cmp	A, rxBit2 	      ; Data bit 2 at frame count=0Ch.
  	jz	getrxBit 	        ; Go get data bit.
  	cmp	A, rxBit3 	      ; Data bit 3 at frame count=0Fh.
  	jz	getrxBit 	        ; Go get data bit.
  	cmp	A, rxBit4 	      ; Data bit 4 at frame count=12h.
  	jz	getrxBit 	        ; Go get data bit.
  	cmp	A, rxBit5 	      ; Data bit 5 at frame count=16h.
  	jz	getrxBit 	        ; Go get data bit.
  	cmp	A, rxBit6 	      ; Data bit 6 at frame count=19h.
  	jz	getrxBit 	        ; Go get data bit.
  	cmp	A, rxBit7 	      ; Data bit 7 at frame count=1Ch.
  	jz	getrxBit 	        ; Go get data bit.
  	cmp	A, rxStop	        ; Stop bit at frame count=1Fh.
  	jz	getrxStop	        ; Go get stop bit.
  	pop	A		              ; Restore the accumulator.
  	ret			              ; Return to caller.
  ;
  ;  Read the start bit.
  getrxStart:
  	iord	Port0_Data	    ; Get data.
  	and	A, 80h	          ; Isolate rx data bit.
  	jnz	rxAbort	          ; Bad start bit? Go abort.
  	pop	A		              ; Restore the accumulator.
  	ret			              ; Return to caller.
  ;
  ;  Start bit is invalid.
  rxAbort:
  	mov	A, 00h		        ; Clear the accumulator.
  	mov	[rxBitCount], A	  ; Clear rx bit count.
  	mov	[rxFrameCount], A	; Clear rx frame count.
  ;	mov	[rxEnable],a
  	pop	A			            ; Restore the accumulator.
  	ret				            ; Return to caller.
  ;
  ;  Get the current receive data bit and
  ;  process into the receive register.	
  getrxBit:
  	iord	Port0_Data		; Get data.
  	and	A, 80h		      ; Isolate rx data bit.
  	or	[rxData], A		  ; Add new data bit to register.
  	mov	A, [rxBitCount]	; Get count.
  	cmp	A, lastrxBit	  ; Check for last data bit.
  	jz	rxSave		      ; Exit if last bit.
  	inc	[rxBitCount]	  ; Bump the receive bit count.
          mov     A,[rxData]               ; Get new data value.
  	asr	A			          ; Shift data down register.
          and     A,7Fh                ; Clear data bit 7.
  	mov	[rxData], A		  ; Store adjusted data.
  	pop	A			          ; Restore the accumulator.
  	ret				          ; Return to caller.
  ;
  ;  Time to get the stop bit and check for end of string.	
  getrxStop:
          mov     A, 00h                ; Clear the accumulator.
          mov     [rxEnable], A         ; Clear rx bit count.
          mov     [rxBitCount], A       ; Clear rx bit count.
          mov     [rxFrameCount], A     ; Clear rx frame count.
          pop     A                           ; Restore the accumulator.
  	ret				            ; Return to caller.
  
  ;  Check that the stop bit is real.
  ;checkFrame:
  ;	iord	Port0_Data		  ; Get data.
  ;	and	A, 80h		        ; Isolate rx data bit.
  ;	jz	sendFrameError	  ; Framing error detected.
  ;
  ;  New character is in register, process it.
  rxSave:
  ;
  ;  Strip out any ASCII Space characters.
  
          mov     A, Asc_Space                ; Get Value of ASCII Space.
  	cmp	A, [rxData]		    ; Check for end of data.
  	jz	Skip_Char		      ; Get next byte.
  ;
  ;  Strip out any ASCII Line Feed characters.
          mov     A, Ln_Fd                    ; Get Value of ASCII Line Feed.
  	cmp	A, [rxData]		    ; Check for end of data.
          jz      Skip_Char                   ; Get next byte.
  ;
  ;  Save the good ASCII characters in the receive buffer.
  	mov	A, [rxData]		    ; Get the good byte of data.
  	mov	X, [rxBufPtr]	    ; Point to the next buffer entry.
  	mov	[X + rxBuf], A	  ; Save data byte in the receive buffer.
  	inc	[rxBufPtr]		    ; Increment the receive buffer pointer.
  ;
  ;  Character is on cull list, so skip it.
  Skip_Char:
  ;  Return for the next character;
  	inc	[rxBitCount]	; Bump the bit count.
  	pop	A			        ; Restore the accumulator.
  	ret				        ; Return to caller.
  ;
  ;  Receive frame is done.
  rxEnd:
  	mov	A, 00h		        ; Clear the accumulator.
  	mov	[rxBitCount], A	  ; Clear rx bit count.
  	mov	[rxFrameCount], A	; Clear rx frame count.
  	pop	A			            ; Restore the accumulator.
  	ret				            ; Return to caller.
  ;
  
  ;************************************************************************
  ; This is the routine that is called to enable the receive routine.
  ;************************************************************************
  ;
  ;  Set up to receive the return character string.
  getSerial:
  	mov	A, 80h		        ; Enable the Port 0 Bit 7
  	iowr	Port0_Interrupt	; GPIO interrupt.
  ;
  Start_receive:
  ;  Enable GPIO interrupts.
  	mov	A, GPIO_intMask	    ; Get the GPIO interrupt enable mask.
  	iowr	Global_Interrupt	; Enable the Port 0 Bit 7 GPIO interrupt.
  ;
  WaitForStart:
  ;  Wait for the receive GPIO interrupt.
  ;	MOV	A,01
  ;	MOV	[rxEnable],A
  	mov	A, [rxEnable]	; Get the receive enable flag.
  	cmp	A, 00h		    ; Did we get an interrupt?
  	jz 	WaitForStart	; Hang around if we didn't.
  ;
  Data_receive:
  ;  Got the start bit. Enable the 128us interrupt and wait.
  ;	iowr	Watchdog		      ; Clear watchdog timer
  	mov	A, 128us_intMask	  ; Set up the 128 us enable.
  	iowr	Global_Interrupt	; Enable it.
  	mov	A, [rxEnable]	      ; Get the enable flag.
  	cmp	A, 00h		          ; Are we still enabled?
  	jnz 	Data_receive	    ; Hang around for the interrupt.
  ;
  Xfer_Done:
  	ret				;
  ;
  ;************************************************************************
  ; This is the routine that is called to flush the receive buffer.
  ;************************************************************************
  ;
  Clear_rxBuf:
  ;  Clear the receive buffer before sending the next command.
  	push	A			      ; Save the accumulator.
  	push	X			      ; Save the index register.
  	mov	A, 00h		    ; Clear the accumulator.
  	mov	[rxBufPtr],	A	; Clear the receive buffer pointer.
  ;
  Clear_rxBuf_Next:
  ;  Loop and clear all 16 bytes of the receive buffer.
  	mov	A, [rxBufPtr]	    ; Load the current receive buffer pointer.
  	cmp	A, 10h		        ; Have we done 16?
  	jz	Clear_rxBuf_Done	; Yes, we are done.
  	mov	A, 00h		        ; Clear the accumulator.
  	mov	X, [rxBufPtr]	    ; Load the index register.
  	mov	[X + rxBuf], A	  ; Clear the current location.
  	inc	[rxBufPtr]		    ; Point to the next byte.
  	jmp	Clear_rxBuf_Next	; Do it again.
  ;
  Clear_rxBuf_Done:
  	pop	X			; Restore the index register.
  	pop	A			; Restore the accumulator.
  	ret				; Return to sender.
  ;
  ;************************************************************************
  ; This is the routine that is called to wait after receiving the latest
  ; character string.
  ;************************************************************************
  ;
  delay1:
  	push	A			                ; Save the accumulator.
  	mov	A, FFh		              ; Set loop variable.
  	mov	[outerDelayOneCount], A ; Store loop variable.
  ;
  outer_delay1_loop:
          mov     A, a0h                        ; Set loop variable for good sync.
  	mov	[innerDelayOneCount], A ; Load the loop count.
          mov       A, 00h                    ; Clear the accumulator.
  ;
  inner_delay1_loop:
  	iowr	Watchdog		          ; Clear watchdog timer
  	dec	[innerDelayOneCount]	  ; Decrement the inner loop counter.
  	cmp	A, [innerDelayOneCount]	; Is it empty?
  	jnz	inner_delay1_loop	      ; Not, go do it again.
  ;
  	dec	[outerDelayOneCount]    ; Decrement the outer loop counter.
  	cmp	A, [outerDelayOneCount] ; Is it empty?
  	jnz	outer_delay1_loop	      ; No, go do it again.
  ;
  	pop	A			; Restore the accumulator.
  	ret				; Return to caller.
  ;
  ;************************************************************************
  ; This is the routine that is called to wait between commands.
  ;************************************************************************
  ;                     
  delay:
  	push  A                   ; Save the accumulator.
          mov  A, ffh               ; Set loop variable
  	mov  [outerDelayCount], A ; Store loop variable
  
  outer_delay_loop:
          mov  A, a0h     ; Set loop variable for good sync   
  	mov  [innerDelayCount], A ;
    mov  A, 00h	              ;
  ;
  inner_delay_loop:
          nop
          nop
          nop
          nop
          nop
  	nop	;
  	nop	;
  	nop	;
  	nop	;
  	nop	;
  	nop	;
  	nop	;
  	nop	;
  	nop	;
  	nop	;
          nop     ;
  	iowr  Watchdog		          ; Clear watchdog timer
  	dec   [innerDelayCount]	    ; Decrement the inner count.
  	cmp   A, [innerDelayCount]  ; Time up?
  	jnz   inner_delay_loop      ; Yes, go to the outer loop.
  ;
  	dec  [outerDelayCount]      ; Decrement the outer count.
  	cmp  A, [outerDelayCount]   ; Time up?
  	jnz  outer_delay_loop       ; No, go through the loops again.
  	pop  A                      ; Restore the accumulator.
  	ret				                  ; Return to caller.

⌨️ 快捷键说明

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