📄 potreadd.asm
字号:
; PotReadd - Read the Pot Values and Send to the Servos
;
; This Application Reads Resistance Values by Allowing a Capacitor
; Wired to a Pot to Charge and then Measure the Time the Cap takes
; To Discharge.
;
; Two AT89C2051 pins are used for reading each Pot.
;
; The values of each Pot are sent to the Servo Controller at 1200 bps
; using a simple Transmission Protocol.
;
; Myke Predko
; 98.05.16
;
; Hardware Notes:
; 89C2051 Running at 10 MHz
; P1.6 is Connected to the Elevator R/C Charge/Discharge Circuit
; P1.7 is Connected to the Aileron R/C Charge/Discharge Circuit
; P1.0 is Connected to the R/C Voltage which is the Pulse State
; Between the Capacitor and Resistor for the Elevator
; P1.1 is Connected to the R/C Voltage which is the Pulse State
; Between the Capacitor and Resistor for the Aileron
; P3.1 is used to Send Data Serially to the Servo AT89C2051.
; P3.0 is used to Receive Data Serially from the Servo AT89C2051
; Variable Declarations
; R0 - R2: Delay Counter Variables
; R3: Elevator Value
; R4: Aileron value
org 0
mov SCON,#%01010000 ; Serial Port in Mode 1
mov TMOD,#%00100000 ; Put Timer1 in Mode 2
mov TH1,#234
mov TL1,#234
setb TCON.6 ; Start the Timer Running
Mainline: ; Program Mainline
mov P1,#%00111111 ; Allow the Capacitors to Discharge
mov R3,#0 ; Clear the Elevator Counter
mov R4,#0 ; Clear the Aileron Counter
clr RI ; Clear the Serial Data Receive Bit
mov R0,#0FFh ; Let the Cap Discharge
mov R1,#010h ; For 10 msecs
Loop1:
djnz R0,Loop1
djnz R1,Loop1
mov P1,#%01111111 ; Now, Wait for the Elevator Capacitor to Charge
Loop2: ; Loop Until the the Line Becomes High
inc R3 ; Increment the Elevator Position Counter
jnb P1.0,Loop2
mov P1,#%11111111 ; Now, Wait for the Aileron Capacitor to Charge
Loop3: ; Loop Until the the Line Becomes High
inc R4 ; Increment the Aileron Position Counter
jnb P1.1,Loop3
mov A,R3 ; Scale the Elevator Value
clr C
subb A,#4 ; Take 4 Away for the Initial Value
mov R3,A ; Multiply the Elevator Value Read by 2.5
rl A ; Rotate Left By one, Multiply by 2
xch A,R3
clr C
rrc A ; Rotate Right by One, Multiply by 0.5
add A,R3 ; Add 2x and 0.5x Together
mov R3,A
mov A,R4 ; Scale the Aileron Value
clr C
subb A,#4
mov R4,A ; Multiply the Alieron Value Read by 2.5
rl A ; Rotate Left By one, Multiply by 2
xch A,R4
clr C
rrc A ; Rotate Right by One, Multiply by 0.5
add A,R4 ; Add 2x and 0.5x Together
mov R4,A
mov SBUF,#'A' ; Indicate We're Sending the Aileron Value
acall DlayCheck ; Do we Get an Acknowledge?
jnb RI,Mainline ; If "RI" not Set, then No, Start Over
clr RI ; Clear the Received Character Bit
mov SBUF,R4 ; Send the Aileron Value
acall DlayCheck ; Did we Get an Acknowledge?
jnb RI,Mainline
clr RI
mov SBUF,#'E' ; Indicate We're Sending the Elevator Value
acall DlayCheck ; Do we Get an Acknowledge?
jnb RI,Mainline ; If "RI" not Set, then No, Start Over
clr RI ; Clear the Received Character Bit
mov SBUF,R3 ; Send the Elevator Value
acall DlayCheck ; Did we Get an Acknowledge?
jnb RI,Mainline
clr RI
ajmp Mainline
DlayCheck: ; Delay 2 Seconds and Check for "RI" to be
; Set
mov R2,#6
DlayCheckLoop: ; Loop Until Time is Up or "RI" is Set
jb RI,DlayCheckEnd ; If "RI" Set, Return
djnz R0,DlayCheckLoop
djnz R1,DlayCheckLoop
djnz R2,DlayCheckLoop
DlayCheckEnd: ; Finished, Return to the Caller
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -