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

📄 servomov.asm

📁 主要是8051源代码
💻 ASM
字号:
;  ServoMov - Put Servo's to Specified Positions.
;
;  This Third Servo Program, Sets the "Servo0" and "Servo1" according
;   to the two byte value passed to it.  Servo0 is controlled by an "A"
;   and Servo1 is controlled by an "E".  
;
;  The Servo Code Developed Earlier is used to Output the two Servo PWM.   
;
;  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.16
;
;  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 0)
;  P1.7 is Connected to a Radio Control Servo (Servo 1)
;  P3.0 is Connected to the Position Sensor
;  P3.0 is used to transmit an "Acknowledge" Character (00Dh) back 

;  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    SCON,#%01010000        ;  Set the Serial Port to 8 Bit Mode
  mov    TMOD,#%00100001        ;  Timer0 - Uses Internal Clock
                                ;         - Run in Mode 1
                                ;  Timer1 - Uses Internal Clock
                                ;         - Run in Mode 2
                                ;         - Drive the Serial Port
  mov    TH1,#234               ;  Setup the Timer1 Interval
  mov    TL1,#234
  mov    TCON,#%01010000        ;  Start Both Timers running

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

  mov    Servo0,#83             ;  Setup Both Servos to Intermediate Position
  mov    Servo1,#83             

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

;  Now, Do the Looping Poll for Input

MainLoop:                       ;  Come Back Here After Decrementing P3

  jnb    RI,MainLoop            ;  Wait for a Character to Come in

  mov    R4,SBUF                ;  Save the Character
  clr    RI
  mov    SBUF,#00Dh             ;  Acknowledge the Character Coming In

  mov    R2,#6                  ;  Delay 2 Seconds
DlayLoop:                       ;  Wait for the Next Character (Servo Value)
  jb     RI,HaveChar
  djnz   R0,DlayLoop
  djnz   R1,DlayLoop
  djnz   R2,DlayLoop

HaveChar:                       ;  We Have the Character

  mov    A,SBUF                 ;  Save the Incoming Character
  clr    RI
  mov    SBUF,#00Dh             ;  Acknowledge the Incoming Character

  mov    B,#5                   ;  Get the Range Divided by 5
  div ab
  add    A,#56                  ;  56 is the 1 msec Value

  cjne   R4,#'A',SetElevators   ;  Is this an "A" Coming In?

  mov    Servo0,A               ;  No, Set the Aileron Position

  ajmp   MainLoop               ;  Just Loop Around Forever

SetElevators:                   ;  Set the Elevators Position

  mov    Servo1,A               

  ajmp   MainLoop

⌨️ 快捷键说明

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