📄 servcent.asm
字号:
; ServCent - Centre an R/C Servo
;
; This is the first program for the Model Airplane Application
; Demonstration. This Program outputs a 1.5 msec Pulse once every
; 20 msecs to Centre the Servo. The Interrupt Routine outputs a signal
; For two Servos.
;
; 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 the Servos to 1.5 msec Delays
mov Servo1,#83
mov IE,#%10000010 ; Enable the Timer 0 Interrupt
; Now, Do the Looping Output
MainLoop: ; Come Back Here After Decrementing P3
ajmp MainLoop ; Just Loop Around Forever
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -