;  лллллллм     млллллм            лллллллл 
;  лл    плл   ллп    пл           лл 
;  лл    млл   лл                  лл 
;  лллллллл    лл                  лллллллм 
;  лл   лл     лл                        плл 
;  лл    лл    ллм    мл           ллм   млл 
;  лл     лл    плллллп             плллллп 
; 
; 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 

