Tutorial Microcontroller 8051
 
 
 
 
 
   

PREVIOUS

SAFETY

If you want to include some safety (recommended), check bits #7 and #6 for ZEROS, if it is a Philips TV remote.   You can also not use the 4.752ms delay, instead, wait only 3/4 of a bit time, and then start to read from the bit #2.  You will suppose the first one was a "1" and the second should be a "1" too, if not, discard  them, wait 60ms and activate reception again, you should sync correctly at the beginning of the next train of pulses.  But even this way, you could read wrongly a "1" bit followed by another if the reading start anywhere in the middle of the train. 

To make sure your controller is never starting to read the train in the middle, you can discard the first reading always after a long silence (half second or more), so you will make sure that the second reading will be in sync.  To do that, after idling for more than half second, enter in a special sync routine and upon sensing the first LOW level bit (can be the real first or not), wait 60ms and jump to the real receive routine and start to monitor the Receiver output again.  It means that the first train will be used just to make your receive routine to engage in a correct timing to read the second train of pulses. 

Remember that there is a delay of 105ms between pulse trains, so doesn't matter which LOW bit you sensed, waiting 60ms will put your reception routine in the middle of the silence between pulse trains, allowing it to sync  at the first bit of the next train of pulses.
 

AT89C2051  IR  RECEIVER

The following circuit and code were used in one of our equipment, using a remote control for mechanical positioning.  The At89C2051 were selected by fast coding and low cost.  Today probably I would use an small Tinny AVR unit. The software listing below was stripped from other non essential coding, necessary to our machine, but not necessary here.


8051  ASSEMBLY  CODE

;  лллллллм     млллллм            лллллллл
;  лл    плл   ллп    пл           лл
;  лл    млл   лл                  лл
;  лллллллл    лл                  лллллллм
;  лл   лл     лл                        плл
;  лл    лл    ллм    мл           ллм   млл
;  лл     лл    плллллп             плллллп
;
; SOFTWARE FOR AT89C2051 TO DECODE PHILIPS REMOTE CONTROL
; RC-5 CODIFICATION - INFRA-RED RECEIVER LT1029-ND DIGIKEY
; CLIPPED PARTS FROM THE ORIGINAL SOURCE TEXT:
;   A) TRANSMITTER
;   B) SELECTION FOR PHILIPS / FC1 - (WORKING PHILIPS)
; AT89C2051 RUNNING AT 2MhZ <== IMPORTANT
; WAGNER LIPNHARSKI - NOVEMBER 1999 - WAGNER@USTR.NET
; UST RESEARCH INC. - ORLANDO, FL - WWW.USTR.NET
;
$MOD51
$NOPAGING
$LIST
;
; PIN 11 (P37) : 0 = RECEIVER CIRCUIT
;              : 1 = TRANSMITTER CIRCUIT
;
; PIN  2 (P30) : 1 = RECEIVER DECODES PHILIPS REMOTE
;              : 0 = RECEIVER DECODES FC1 REMOTE
;
; PIN 12 (P10) : PULLED UP = FC1 CODE TRANSMITTER
;              : GROUND    = PHILIPS CODE TRANSMITTER
;
; RECEIVER CONFIGURATION:
; -----------------------
; PIN 7 (P33) INPUT SIGNAL FROM IR RECEIVER
; PINS 12-19 DECODER OUTPUT (DRIVE TO GROUND)
; PIN 11 TO GROUND.
; CLOCK CERAMIC RESSONATOR 2MhZ
; RESET CAP 1uF TO +VCC
; PIN 9 (P35) CAN BE USED TO LITE A LED WHEN RECEIVING VALID IR
; PIN 8 (P34) SCOPE GATE TIME (SOFTWARE TIMMING ADJUSTMENT)
;
; ---___---___------______---___---___--- PIN 7 P33 IRDATA
; _|_____|_____|_____|_____|_____|_____|_ PIN 8 P34 SCOPE READ GATE TIME
;
; --__  1 BIT
;             RX DATA
; __--  0 BIT
;

; TRANSMITTER CONFIGURATION:
; --------------------------
; PINS 2,3,6,7,8,9 & 11 TIED TOGETHER TO DRIVE IR LED
; PINS 16-19 KEYBOARD MATRIX DRIVE (4 PINS)
; PINS 14 & 15 KEYBOARD MATRIX RETURN WITH PULL UP
; CRYSTAL 6MHZ
; RESET CONTROLLED BY FET BS110, DIODES FROM KEYBOARD.
; PIN 12 GOES TO GROUND WHEN IN POWER OFF

             ;------------------
             ; Receiver
             ;------------------
Led          BIT   0B5h   ; P3.5
IrInput      BIT   0B3h   ; P3.3
Scope        BIT   0B4h   ; P3.4
RxTx         BIT   0B7h   ; P3.7 ; Grounded if Receiver/High if TX
             ;------------------
             ; Transmitter
             ;------------------
TXLED        EQU   P3     ; FF = Off, 00 = On
KO1          Bit   097h   ; P1.7 Keyboard Output
KO2          Bit   096h   ; P1.6
KO3          Bit   095h   ; P1.5
KO4          Bit   094h   ; P1.4
KI1          Bit   093h   ; P1.3 Keyboard Input
KI2          Bit   092h   ; P1.2

IRDATA      DATA   010H   ; Memory to store IR code received

;======================================;
;
; P H I L I P S     R E M O T E
; CODE "10" AT AV6 UNIVERSAL PROGRAMMABLE REMOTE CONTROL
;
;======================================;
ORG 00H
MAIN:        Mov  SP,#SPVALUE          ;

PH0:         Mov  P1,#0FFh             ; Reset Decoder Output High
             Setb LED                  ; Turn off IR Indicator
             ;                         ;
PH1:         Mov  4,#022               ; 2MHz
             Mov  5,#000h              ; 2MHz Time loop
PH2:         Jnb  IrInput,PH3          ; Wait for Incomming IR (first low)
             Djnz 5,PH2                ; This time loop is to keep the last
             Djnz 4,PH2                ; ..pressed key available at P1 for few
             Jmp  PH0                  ; ..time in case you press it again
                                       ; ..and avoid glitches at P1.
             ;-------------------------;
PH3:         Clr  A                    ; IR Receiver First Low level.
             Clr  Led                  ; Lite IR Indicator
             ;                         ;
             Mov  2,#110               ; Time Loop (3/4 bit time)
             Djnz 2,$                  ; Waste Time to sync second bit
             ;                         ; 2MHz = 1.296ms
             Mov  B,#7                 ;
PH4:         Setb Scope                ; Scope Gate Indicator Pulse UP
             Mov  C,IrInput            ; Shift IR state to Carry bit
             Clr  Scope                ; Scope Gate Indicator Pulse Down
             Rlc  A                    ; Insert LEFT Carry Bit into A Reg
             ;                         ;
             Mov  2,#145               ; Waste time for next BIT
             Djnz 2,$                  ; 2MHz clock, 1.728ms
             ;                         ;
             Djnz B,PH4                ; Rotate 7 bits into A
             ;                         ; AGC#2, CHKbit, ADDRESS field (5 bits)
             ;-------------------------;
             Anl  A,#0F7h              ; Cut off CHECK Bit (Flipping bit)
             Cjne A,#40h,PH5           ; 10h means second AGC UP & Address 00
             ;                         ; Not 10h?, wrong sync, go again (PH5)
             ;-------------------------;
             Mov  B,#6                 ; Will Get the COMMAND field
PH4A:        Setb Scope                ; Scope Gate Indicator Pulse UP
             Mov  C,IrInput            ; Shift IR state into Carry bit
             Clr  Scope                ; Scope Gate Indicator Pulse Down
             Rlc  A                    ; Insert LEFT carry bit into A Reg
             ;                         ;
             Mov  2,#145               ; Waste time for next BIT
             Djnz 2,$                  ; 2MHZ clock = 1.728ms
             ;                         ;
             Djnz B,PH4A               ; Rotate 8 bits into A (Command)
             ;                         ; Here A holds Command bits
             ;-------------------------;
             Mov  IRData,A             ; Save Command at IRData memory
             Cjne A,#25h,$+3           ; Is Command >=25h
             Jnc  PH5                  ; Yes? Wrong everything, go again PH5
             ;                         ;
             Call PH6                  ; Go get Conversion at Table
             Cjne A,#0FFh,PH4B         ; If conversion <> FF, is valid.
             Jmp  PH5                  ; ..Not Expected Command. go again PH5
             ;                         ;
PH4B:        Mov  P1,A                 ; Valid Command is post at P1 Port
             Jmp  PH1                  ; Job done, go wait next pulse train.
             ;                         ;
             ;-------------------------;
PH5:         Mov  3,#8                 ; 2MHz
             Mov  2,#112               ; Wait 15 bit time
PH5A:        Djnz 2,$                  ; Wasting time to sync ok next train
             Djnz 3,PH5A               ;
             Jmp  PH0                  ; Go back and wait for next train.
             ;-------------------------;
PH6:         Inc  A                    ; Table conversion, Inc skip RET
             Movc A,@A+PC              ; Point to TABLE + Value at A (1-255)
             Ret                       ;
             ;-------------------------;
             ;  The following table bit values at the first column, means
             ;  the translation from remote control key to the value to be
             ;  be post at P1.  The program ignores values of "FF".
             ;  Change those bits according to your needs.
             ;
             ;  Bit #7 is "0" when a valid key is pressed, otherwise is "1"
             ;  It can be used to recognize values as key "zero" pressed,
             ;  when all bits UP means command ZERO.
             ;
             ;  This TV remote uses only Address = "00"
             ;
             ;    PHILIPS TV REMOTE CONTROL DECODING
             ;
             ;    VALUE TO P1   REMOTE KEY   COMMAND CODE FIELD (HEX)
             ;    -----------   ----------   ------------------------
TABLE:       DB   01111111b    ; 0         ; 0
             DB   01111110b    ; 1         ; 1
             DB   01111101b    ; 2         ; 2
             DB   01111100b    ; 3         ; 3
             DB   01111011b    ; 4         ; 4
             DB   01111010b    ; 5         ; 5
             DB   01111001b    ; 6         ; 6
             DB   01111000b    ; 7         ; 7
             DB   01110111b    ; 8         ; 8
             DB   01110110b    ; 9         ; 9
             DB   11111111b    ;           ; A
             DB   11111111b    ;           ; B
             DB   01110011b    ; ON/OFF    ; C
             DB   01110010b    ; MUTE      ; D
             DB   01110001b    ; PP        ; E
             DB   01110000b    ; OSD       ; F
             DB   01101111b    ; Volume+   ; 10
             DB   01101110b    ; Volume-   ; 11
             DB   01101101b    ; Bright+   ; 12
             DB   01101100b    ; Bright-   ; 13
             DB   01101011b    ; Color+    ; 14
             DB   01111010b    ; Color-    ; 15
             DB   11111111b    ;           ; 16
             DB   11111111b    ;           ; 17
             DB   11111111b    ;           ; 18
             DB   11111111b    ;           ; 19
             DB   11111111b    ;           ; 1A
             DB   11111111b    ;           ; 1B
             DB   01100011b    ; Contrast+ ; 1C
             DB   01100010b    ; Contrast- ; 1D
             DB   11111111b    ;           ; 1E
             DB   11111111b    ;           ; 1F
             DB   01011111b    ; Program+  ; 20
             DB   01011110b    ; Program-  ; 21
             DB   11111111b    ;           ; 22
             DB   11111111b    ;           ; 23
             DB   01011011b    ; Timer     ; 24
             DB   01010111b    ; Special 1 ; 25
             DB   01000001b    ; Special 2 ; 26
             DB   01000111b    ; Special 3 ; 27
             DB   01001110b    ; Special 4 ; 28
             DB   01000101b    ; Special 5 ; 29
             DB   01010010b    ; Special 6 ; 2A
END
Best Link

 

PREVIOUS

 

Lesson 1:
T o o l
1.1. Programmer
1.2.
Edsim 51
1.3. MIDE-51
1.4. ATMEL ISP

Lesson 2:
Input Output
2.1.LED
2.2.Swicht
2.3.7 Segmen
2.4.LCD Character
2.5.ADC
2.6.DAC
2.7.Motor Stepper
2.8.Keypad

Lesson 3:

Timer Counter

3.1.Basic
3.2.Mode 0
3.3.Mode 1
3.4.Mode 2
3.5.Mode 3

Lesson 4:

Serial Comm.

4.1.Basic
4.2.LED
4.3.Rotate LED
4.2 ADC
4.3.LCD

Lesson 5:
Interuption

5.1.Basic
5.2.Timer
5.2.External