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

📄 prog29b.asm

📁 主要是8051源代码
💻 ASM
字号:
;  PROG29B - Working through the Emulator  
;
;  Start with the Serial Interface.
;
;
;  PROG29B - Start with the Command Line Interface.  Upon Return, R0 Points to the
;   First Parameter and R1 Points to the Second.  If there is a Third, Error
;
;   Input String Buffer is 10 Long Starting at 080h.
;
;   Commands are:
;    H        - Help, Display this List
;    R        - Reset
;    D        - Download a New Application
;    E [Addr] - Start Running at the Optional Address
;    S [Addr] - Single Step from the Optional Address
;             - If just a Carriage Return Received then Single Step 
;    U [Addr] - Unassemble at the PC or Optional Address
;    E Addr   - Modify the Control Store at the Address
;    G Addr   - Read from the Scratchpad RAM/SFR Address
;    W Addr   - Write to the Scratchpad RAM/SFR Address
;    R        - Display the Scratchpad RAM Registers
;    B Addr   - Toggle Set Breakpoint at the Specified Address
;    L        - List the Breakpoints
;  
;  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
;define SerOut=P1.0              ;  Serial Output Bit
;define SerIn=P1.6               ;  Serial Input Bit

CR     EQU 00Dh                 ;  ASCII Carriage Return
LF     EQU 00Ah                 ;  ASCII Line Feed
BS     EQU 008h                 ;  ASCII BackSpace

;  Variable Declarations
Buffer EQU 080h                 ;  Input/Breakpoint Buffer Area
                                ;   - 80 Characters Long


;  Macros


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

  acall   DisplayHelp1          ;  As the First Thing, Display Help
  acall   DisplayHelp2
  acall   DisplayHelp3

Loop:

  acall   GetChar               ;  Wait for a Character to be Sent

  acall   SendChar              ;  Send Back the Received Character

  ajmp    Loop  


;  Subroutines
DisplayHelp1:                   ;  Display the "Help" Menu

  mov     R0,#(HelpTable1 - GetHelp1)

DisplayHelp_Loop1:              ;  Loop Here to Display Every Character
  mov     A,R0                  ;   Get the Next Character to Display
  movc A,@A+PC
GetHelp1:

  jz      DisplayHelp_End1      ;  '\0' is the End Character

  acall   SendChar              ;  Send the Character to the Console

  inc     R0                    ;  Point to the Next Character to Display

  ajmp    DisplayHelp_Loop1     ;  Loop Around to Display the Next Character
  
DisplayHelp_End1:

  ret

HelpTable1:                     ;  Messages to be Displayed
  db      CR,LF                 ;  Start a New Line
  db      'H        - Help, Display this List',CR,LF
  db      'R        - Reset',CR,LF
  db      'D        - Download a New Application',CR,LF
  db      'E [Addr] - Execute at the Optional Address',CR,LF
  db      'S [Addr] - Single Step from the Optional Address',CR,LF,0
DisplayHelp2:                   ;  Display the "Help" Menu

  mov     R0,#(HelpTable2 - GetHelp2)

DisplayHelp_Loop2:              ;  Loop Here to Display Every Character
  mov     A,R0                  ;   Get the Next Character to Display
  movc A,@A+PC
GetHelp2:

  jz      DisplayHelp_End2      ;  '\0' is the End Character

  acall   SendChar              ;  Send the Character to the Console

  inc     R0                    ;  Point to the Next Character to Display

  ajmp    DisplayHelp_Loop2     ;  Loop Around to Display the Next Character
  
DisplayHelp_End2:

  ret

HelpTable2:                     ;  Messages to be Displayed
  db      '         - If just a Carriage Return Received then Single Step',CR,LF
  db      'U [Addr] - Unassemble at the PC or Optional Address',CR,LF
  db      'E Addr   - Modify the Control Store at the Address',CR,LF
  db      'G Addr   - Read from the Scratchpad RAM/SFR Address',CR,LF,0
DisplayHelp3:

  mov     R0,#(HelpTable2 - GetHelp2)

DisplayHelp_Loop3:              ;  Loop Here to Display Every Character
  mov     A,R0                  ;   Get the Next Character to Display
  movc A,@A+PC
GetHelp3:

  jz      DisplayHelp_End3      ;  '\0' is the End Character

  acall   SendChar              ;  Send the Character to the Console

  inc     R0                    ;  Point to the Next Character to Display

  ajmp    DisplayHelp_Loop3     ;  Loop Around to Display the Next Character
  
DisplayHelp_End3:

  ret

HelpTable3:                     ;  Messages to be Displayed
  db      'W Addr   - Write to the Scratchpad RAM/SFR Address',CR,LF
  db      'R        - Display the Scratchpad RAM Registers',CR,LF
  db      'B Addr   - Toggle Set Breakpoint at the Specified Address',CR,LF
  db      'L        - List the Breakpoints',CR,LF,0
  GetChar:                        ;  Wait for a Character and Return it in Accumulator

  mov  R6,#9	                ;  Want to Read 9 Bits

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

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

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

GCLoop:			        ;  Now, Read 9 Bits

  mov  C,SerIn	                ;  Read the Input Bit
  rrc  A

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

  djnz R6,GCLoop

  ret


SendChar:                       ;  Send the Serial Character
  mov	 R6,#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	 R7,#170	        ;  Delay to 104 usecs (520 Cycles) per loop
SCLoop1:
  djnz	 R7,SCLoop1
  nop

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

  djnz	 R6,SCLoop

  ret

⌨️ 快捷键说明

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