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

📄 rangechk.asm

📁 主要是8051源代码
💻 ASM
字号:
;  RangeChk - Check the Operating Range of an R/C Servo on the Model 
;
;  This Second Program, Moves "Servo1" to First one Extreme, Delays for
;   A Second or So and then Moves to the Other Extreme.  The Interrupt
;   routine from "ServCent" is used.  
;
;  Each Timer Interrupt Loop Takes 18 usecs.  Therefore, at the 1 msec 
;   Extreme, a value of 56 is used.  For the Other Extreme, 2 msec, a value
;   of 111 is used.  For the Middle Position, a value of 83 is used.
;
;  Myke Predko
;  98.05.03
;
;  Hardware Notes:
;  89C2051 Running at 10 MHz
;  The 80C520's Timer 0 Running in Mode 0
;  P1.6 is Connected to a Radio Control Servo (Servo 1)
;  P1.7 is Connected to a Radio Control Servo (Servo 2)

;  Variable Declarations
Servo0 EQU 010h                 ;  Position of the Aileron Servo (at P1.6)
Servo1 EQU 011h                 ;  Position of the Elevator Servo (at P1.7)  

 org 0
  ajmp   Mainline

 org 0Bh                        ;  Timer0 (Real Time) Interrupt

  mov   TH0,#191                ;  Reload the Timer Interrupt
  mov   TL0,#00                 ;  To Interrupt Again in 20 msecs

  push  ACC                     ;  Save the Accumulator
  push  PSW                     ;  Save the Status Register

  mov   A,#0C0h                 ;  Turn ON the Servo's Pulses
  orl   A,P1
  mov   P1,A

  mov   B,#0                    ;  Use "B" as the Loop Counter

IntLoop:                        ;  Loop Around Until Both Servos Counts are met

  mov   A,B                     ;  Get the Current Count Value
  clr   C
  subb  A,Servo0                ;  Is Count Past the Current Position?
  mov   P1.6,C                  ;  Save the Carry as the Aileron Output

  mov   A,B
  clr   C
  subb  A,Servo1
  mov   P1.7,C                  ;  Save the Carry as the Elevator Output

  inc   B                       ;  Increment the Counter

  orl   C,P1.6                  ;  Are Both Control Bits Low?

  jc    IntLoop                 ;  Loop Back, If Either Bit Set

  pop    PSW                    ;  Restore the Registers Pushed onto the Stack
  pop    ACC

  reti


Mainline:                       ;  Program Mainline

  mov    P1,#03Fh               ;  Turn Off the Pulses to the Elevators and Ailerons

  mov    TMOD,#%00000001        ;  Timer0 - Uses Internal Clock
                                ;         - Run in Mode 1
  mov    TCON,#%00010000        ;  Start Timer0 running

  mov    TH0,#191               ;  Setup the 20 msec Delay to the Timer Interrupt
  mov    TL0,#00

  mov    Servo0,#83             ;  Setup Servo0 to 1.5 msec Delays
  mov    Servo1,#56             ;  Start With Servo1 at One Extreme  

  mov    IE,#%10000010          ;  Enable the Timer 0 Interrupt

;  Now, Do the Looping Output

MainLoop:                       ;  Come Back Here After Decrementing P3

  acall  Dlay                   ;  Delay 1 Second With Servo in Current Pos'n

  mov    Servo1,#111            ;  Servo1 At the Full Extreme

  acall  Dlay

  mov    Servo1,#56             ;  Servo1 at the Other Extreme

  ajmp   MainLoop               ;  Just Loop Around Forever


Dlay:                           ;  Delay 1 Second, Use the 

  mov    R2,#6

DlayLoop:

  djnz   R0,DlayLoop            ;  Use the Values Already in the Registers

  djnz   R1,DlayLoop

  djnz   R2,DlayLoop

  ret

⌨️ 快捷键说明

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