This section describes how to interface an Infrared Receiver (TSOP 1738) to the microcontroller AT89S51/52
and to control 8 LED's through a RC5 Remote control.
The circuit explains how to connect an Infrared Sensor to the Microcontroller, the program to control 8 devices through a standard RC5 Remote control.
Program
Code (Text):
INCLUDE reg_51.pdf INPUT EQU P3.2 ; Port3,Bit2 is used as input. The demodulated signal ; with active low level is connected to this pin RB0 EQU 000H ; Select Register Bank 0 RB1 EQU 008H ; Select Register Bank 1 ...poke to PSW to use DSEG ; This is internal data memory ORG 20H ; Bit adressable memory FLAGS: DS 1 CONTROL BIT FLAGS.0 ; toggles with every new keystroke NEW BIT FLAGS.1 ; Bit set when a new command has been received COMMAND: DS 1 ; Received command byte SUBAD: DS 1 ; Device subaddress TOGGLE: DS 1 ;Toggle every bit ANS: DS 1 ; ADDR: DS 1 STACK: DS 1 ; Stack begins here CSEG ; Code begins here ;---------==========----------==========---------=========--------- ; PROCESSOR INTERRUPT AND RESET VECTORS ;---------==========----------==========---------=========--------- ORG 00H ; Reset JMP MAIN ORG 0003H ; External Interrupt0 JMP RECEIVE ;---------==========----------==========---------=========--------- ; ---------==========----------==========---------=========--------- ; Interrupt 0 routine ; ---------==========----------==========---------=========--------- RECEIVE: CPL P2.2 MOV 2,#235 ; Time Loop (3/4 bit time) DJNZ 2,$ ; Waste Time to sync second bit MOV 2,#235 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit Mov 2,#134 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit clr a mov r6,#07h pol1: mov c,Input rlc a Mov 2,#235 ; Waste time for next BIT Djnz 2,$ Mov 2,#235 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit Mov 2,#235 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit Mov 2,#105 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit djnz r6,pol1 MOV SUBAD,A mov r6,#06h pol2: mov c,Input rlc a Mov 2,#235 ; Waste time for next BIT Djnz 2,$ Mov 2,#235 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit Mov 2,#235 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit Mov 2,#105 ; Time Loop (3/4 bit time) Djnz 2,$ ; Waste Time to sync second bit djnz r6,pol2 Mov COMMAND,A ; Save Command at IRData memory MOV A,SUBAD MOV ADDR,A ANL A,#0FH MOV SUBAD,A CJNE A,#03H,ZXC1 MOV A,COMMAND CPL A MOV COMMAND,A AJMP ASZ ZXC1: MOV A,SUBAD CJNE A,#00H,ANSS AJMP ASZ ASZ: MOV A,ADDR ANL A,#20H MOV TOGGLE,A CJNE A,ANS,ANSS AJMP WAR ANSS: JMP ANS1 WAR: MOV A,COMMAND CJNE A,#01H,DSP1 CPL P0.0 DSP1: CJNE A,#02H,DSP2 CPL P0.1 DSP2: CJNE A,#03H,DSP3 CPL P0.2 DSP3: CJNE A,#04H,DSP4 CPL P0.3 DSP4: CJNE A,#05H,DSP5 CPL P0.4 DSP5: CJNE A,#06H,DSP6 CPL P0.5 DSP6: CJNE A,#07H,DSP7 CPL P0.6 DSP7: CJNE A,#08H,DSP8 CPL P0.7 DSP8: CJNE A,#0CH,DSP9 MOV P0,#0FFH DSP9: MOV ANS,TOGGLE MOV A,ANS CPL ACC.5 MOV ANS,A SETB NEW ; Set flag to indicate the new command ;################################################################ ANS1: RETI ; ---------==========----------==========---------=========--------- ; Main routine. Program execution starts here. ; ---------==========----------==========---------=========--------- MAIN: MOV SP,#60H SETB EX0 ; Enable external Interrupt0 CLR IT0 ; triggered by a high to low transition SETB EA; /* Enable global interrupt */ MOV ANS,#00H ;clear temp toggle bit CLR NEW LOO: JNB NEW,LOO CLR NEW AJMP LOO END
Infrared Receiver Interfacing 1.0
Interfacing Infrared Receiver (TSOP 1738) with 8051 microcontroller