📄 prog37.asm
字号:
; PROG37A - Reading an TV IR Remote Control
;
;
; This Application will Read the Incoming I/R Commands.
;
; A Sony TV Remote Control is Used.
;
;
; I/R Data (Repeated Every 45 msec):
;
; -------+ +----+ +----+ +----+
; | | | | | | |
; | | | | | | o o o
; +--------------+ +--------+ +----+
;
; | | | | | |
; | Start Bit | |"0" Bit | |"1" |
; | < 3 msec | | 1 msec | |<1 |
; |High| > 1.5 | |msec|
; |<0.5| msec |
; |msec|
;
; I/R Values:
IR2 EQU 017EFh ; "2" on Remote Control
IR4 EQU 013EFh ; "4" on Remote Control
IR6 EQU 015EFh ; "6" on Remote Control
IR8 EQU 011EFh ; "0" on Remote Control
IRPower EQU 0156Fh ; "Power" Key on Remote Control
;
; Myke Predko
; 98.03.25
;
; Hardware Notes:
; AT89C2051 is used as the Microcontroller
; - Oscillator Speed is 20 MHz
; Wheel PWM Control is at P1.3
; Left Motor Control 1 is at P1.6
; Left Motor Control 2 is at P1.2
; Right Motor Control 1 is at P1.7
; Right Motor Control 2 is at P1.4
; LED Control is at P1.5
; Constant Declarations
; Variable Declarations
Flags EQU 020h ; Current Operation Flags
IRState EQU 0 ; Set When Reading I/R Data
IRComplete EQU 1 ; Set When Finished with I/R Read
IRButton EQU 030h ; Value Read In (2 Bytes)
IRCount EQU 032h ; Number of Bits to Read
; Macros
; Mainline
org 0 ; Execution Starts Here
ajmp MainLine ; Jump Over to the Mainline
org 003h ; Interrupt Pin 0 - Left I/R Receiver
mov IE,#%10000011 ; Just Int 0 For Incoming Data
ajmp IRInt
org 00Bh ; Timer 0
clr IRState ; Don't Have Anything to Do Here
mov IE,#%10000101 ; Just Leave Buttons Ready for Interrupts
reti
org 013h ; Interrupt Pin 1 - Right I/R Receiver
mov IE,#%10000110 ; Just Int 1 For Incoming Data
ajmp IRInt
org 01Bh ; Timer 1
IRInt: ; Handle the Button Interrupt
jb IRState,IRRead ; If IRState Set, Then Executing Interrupt
; Else, Have to Set up for a New Interrupt
setb IRState ; Set the IR State Interrupt
clr IRComplete ; Don't Have a Valid Value
mov IRButton,#0 ; Clear the I/R Button
mov IRButton+1,#0
mov IRCount,#12 ; Going to Read 12 Going Lows
mov TL0,#0 ; Going to Delay 4 msec for End of Start Pulse
mov TH0,#LOW(256 - 26)
clr TCON.5 ; Clear the Tmr0 Overflow Flag
reti ; Return to Mainline
IRRead: ; Now, Read the Value
push ACC ; Save the Accumulator
clr C
mov A,TH0 ; Load the Timer Value and Set According to Time Remaining
subb A,#(256 - 4) ; Have we Waited 8 or 11 Cycles?
mov A,IRButton
rlc A
mov IRButton,A
mov A,IRButton+1 ; Remember it is a 16 Bit Value
rlc A
mov IRButton+1,A
mov TL0,#0 ; Wait Up to 2 msec for the Next Delay
mov TH0,#LOW(256 - 13)
dec IRCount ; Decrement the Bit Count
mov A,IRCount ; Is it equal to Zero?
jz IRDone
pop ACC ; Restore the Accumulator
reti ; Return to Executing
IRDone: ; Have Read the IR Value
setb C ; Put in the Last Set Bit
mov A,IRButton
rlc A
mov IRButton,A
mov A,IRButton+1
rlc A
mov IRButton+1,A
clr IRState ; Have Finished with the Code
setb IRComplete ; Indicate that the Button is Ready
mov TL0,#0 ; Run for 1/10th of a Second
mov TH0,#0
pop ACC
reti ; Return to the Mainline
MainLine: ; Mainline of the Program
clr IRState ; Clear the Flags Variables
clr IRComplete
mov TMOD,#%00000001 ; Timer0 - Uses Internal Clock
; - Run in Mode 1
mov TCON,#%00010101 ; Start Timer0 running
; Make Edge Triggered Interrupts
mov IE,#%10000101 ; Enable Int 0 & 1 Pin Interrupts
Loop: ; Loop Around Here
jnb IRComplete,Loop ; Nothing to Handle
mov IRCount,#16 ; Output the Bits in IRButton
IROutput: ; Loop Here for Each Bit
mov A,IRButton ; Output the Highest Bit
rlc A
mov IRButton,A
mov A,IRButton+1
rlc A
mov IRButton+1,A
mov P1.0,C ; Show the Bit on P1.0
acall ShortDlay ; Delay four Instruction Cycles so that Data can be Seen
setb P1.1 ; Toggle the Clock
clr P1.1
djnz IRCount,IROutput ; Loop 16x
; mov A,IRButton ; Now, Do we Have the Number "2"?
; cjne A,#LOW(IR2),SecondLoop
; mov A,IRButton+1
; cjne A,#HIGH(IR2),SecondLoop
; mov C,P1.5 ; Toggle the LED
; cpl C
; mov P1.5,C
SecondLoop: ; Wait for the Next Value to be Read in
jb IRComplete,SecondLoop
ajmp Loop
ShortDlay:
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -