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

📄 prog41.asm

📁 主要是8051源代码
💻 ASM
字号:
;  PROG41 - Start doing RS-232 Communications with the 8051 in the 51Bot.
;
;  This Application will Read and Send RS-232 Commands from the AT89C2051
;   in the 51Bot.  Requirements for this application include, setting up Timer 1
;   for use as a PWM Interrupt Source as well as the Timer for the RS-232 Serial
;   data transmission.  
;
;  Timer 1 Interrupt Rate: 75.76 KHz (for a 18.94 KHz PWM Frequency) 
;
;  Serial Interface Speed: 2400 bps (Actually) 
;
;  Myke Predko
;  98.04.19
;
;  Hardware Notes:
;  AT89C2051 is used as the Microcontroller
;   - Oscillator Speed is 20 MHz
;  Serial Output is on P3.1
;  Serial Input is on P3.0

;  Constant Declarations
TimerReload EQU 0EAh            ;  Value to Reload the Timer With

;  Variable Declarations
LastChar    EQU 028h            ;  Last Character Sent to The Program
Dlay1       EQU LastChar+1      ;  24 Bit Value to Delay 1 Second Between TX's
Dlay2       EQU LastChar+2
Dlay3       EQU LastChar+3


;  Macros


;  Mainline
 org 0                          ;  Execution Starts Here

  ajmp    MainLine              ;  Jump Over to the Mainline

 org 01Bh                       ;  Timer 1 Interrupt Vector
 

Mainline:                       ;  Mainline Code, Setup Timer1 and Transmit
                                ;   "A" Once Every Second or Last Character
                                ;   Received.

  mov     SCON,#%01010000       ;  Run Serial Port in 8 Bit Mode
  mov     TMOD,#%00100001       ;  Run the Timers, Tmr1 in 8 Bit Reload Mode
  mov     TH1,#TimerReload      ;  Enable the Timer
  mov     TL1,#TimerReload
  orl     TCON,#040h            ;  Enable Tmr1 to Run
  anl     PCON,#07Fh            ;  Make Sure SMOD is Reset

  mov     LastChar,#'A'         ;  Setup the Last Character to Transmit


Loop:                           ;  Loop Here to Transmit Each Character

  acall   Dlay                  ;  Wait one Second

  clr     TI                    ;  Turn off the Transmit Completed Flag
  mov     A,LastChar
  mov     SBUF,A

  jnb     RI,Loop               ;  Was Anything Received?  

  clr     RI                    ;  Yes, Clear RI

  mov     A,SBUF                ;  Save the Character Received
  mov     LastChar,A
  
  ajmp    Loop                  ;  Wait to Transmit the Next Character


Dlay:                           ;  Delay 1 Second

  mov     Dlay1,#0              ;  Initialize Delay Values
  mov     Dlay2,#0
  mov     Dlay3,#00Ch

DlayLoop:                       ;  Loop Here for 1 Second
  djnz    Dlay1,DlayLoop
  djnz    Dlay2,DlayLoop
  djnz    Dlay3,DlayLoop

  ret                           ;  Return to the Caller

⌨️ 快捷键说明

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