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

📄 prog29a.asm

📁 主要是8051源代码
💻 ASM
字号:
;  PROG29A - Working through the Emulator  
;
;  Start with the Serial Interface.
;
;  PROG29A - Develop Serial Interface - Bounce Back Characters from the Host
;   Terminal.  
;
;  The Serial Interface consists of a Command and a Parameter Followed by a
;   Carriage Return, We Have to Interpret this as well as:
;
;   1.  Ignore Following "Line Feed" - Wait 10 msecs after CR.
;   
;   2.  Handle BackSpacing
;
;  Myke Predko
;  98.06.25
;
;  Hardware Notes:
;  DS87C520 is used as the Microcontroller
;   - Oscillator Speed is 20 MHz
;  P2.7 is Console Serial Output
;  P2.6 is Console Serial Input

;  Constant Declarations
define SerOut=P2.7              ;  Serial Output Bit
define SerIn=P2.6               ;  Serial Input Bit

;  Variable Declarations


;  Macros


;  Mainline
 org 0                          ;  Execution Starts Here
MainLine:                       ;  Mainline of the Program

  acall   GetChar               ;  Wait for a Character to be Sent

  acall   SendChar              ;  Send Back the Received Character

  ajmp    Mainline              ;  


;  Subroutines
GetChar:                        ;  Wait for a Character and Return it in Accumulator

  mov  R0,#9	                ;  Want to Read 9 Bits

GCLoop1:			;  Wait for a Start Bit
  jb   SerIn,GCLoop1

  mov  R1,#83		        ;  Delay 1/2 Bit
GCLoop2:
  djnz R1,GCLoop2

  jb   SerIn,GCLoop1	        ;  If "Glitch", keep Waiting

GCLoop:			        ;  Now, Read 9 Bits

  mov  C,SerIn	                ;  Read the Input Bit
  rrc  A

  cpl  P2.0                     ;  Toggle Another Bit

  mov  R1,#170  	        ;  Delay Loop for 104 usecs per bit
GCLoop3:
  djnz R1,GCLoop3
;  nop
;  nop

  djnz R0,GCLoop

  ret


SendChar:                       ;  Send the Serial Character
  mov	 R0,#10		        ;  We're Actually Sending 10 Bits

  clr	 C	       	        ;  First Bit is a "0"

SCLoop:			        ;  Loop Here for Each Bit

  mov	 SerOut,C               ;  Output the Bit in the Carry Flag

  mov	 R1,#170	        ;  Delay to 104 usecs (520 Cycles) per loop
SCLoop1:
  djnz	 R1,SCLoop1
  nop

  setb	 C		        ;  Shift the Next Bit to Carry
  rrc 	 A		        ;   And Load in a "1" for Stop Bit

  djnz	 R0,SCLoop

  ret

⌨️ 快捷键说明

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