; ; A sample program for using the IR Link as a Remote Control. ; by Sami Khawam (sKhawam@bigfoot.com) ; http://unet.univie.ac.at/~a9501901 ; ; This programm control the programm and the volume of a PHILIPS TV. ; ; The program could be optimized, but I haven't made it here. Tables ; might be used for codes storing, and a compression might also be used. ; ; The PutByte was taken (and modified) from a disassembly of the ROM. ; ; #include usgard.h .org 0 .db "IR Remote Control for PHILIPS",0 call CLEARLCD Start: LD A, $C0 ; Set W1 and R1 OUT (7),A ; call CLEARLCD ld hl, &Text ld de,$0003 ld ($800C),de call D_ZT_STR ld de,$0004 ld ($800C),de call D_ZT_STR ProgLoop: call GET_KEY cp 0 jr z, ProgLoop cp K_EXIT ret z cp K_DOWN jr z, VolMinus cp K_UP jr z, VolPlus cp K_RIGHT jr z, ProgPlus cp K_LEFT jr z, ProgMinus cp K_F1 jr z, RecordRemote cp K_F2 jr z, RecPlay jr ProgLoop VolMinus ld hl, &CK_DOWN jr SendData VolPlus ld hl, &CK_UP jr SendData ProgPlus ld hl, &CK_RIGHT jr SendData ProgMinus ld hl, &CK_LEFT jr SendData RecPlay ld hl, &CK_RECORDED SendData: ld a, (hl) ; Number of bytes ld b, a ; We load it into b for djnz call &PutByte ; Send the Byte inc hl ld a, (hl) ; The Duration of a Bit call &PutByte ; Send the Byte inc hl ld a, (hl) ; The First delay call &PutByte ; Send the Byte inc hl ld a, (hl) ; The Second delay call &PutByte ; Send the Byte NextByte: inc hl ld a, (hl) call &PutByte ; Now we send all bytes. djnz NextByte jr Start RecordRemote call CLEARLCD ld a, $54 call &PutByte ld hl, &REC_HEADER ld b, 3 RNextByte: ld a, (hl) call &PutByte ; Now we send all bytes. inc hl djnz RNextByte ld hl, &REC_DATA ld b, 20 GNextByte: call &GetByte ld (hl), a inc hl djnz GNextByte jp &Start GetByte: push bc LD DE, $FFFF ; For time-out. ld c,0 ; byte receive ld b,8 ; counter GB_Wait_For_Change: in a,(7) and 3 jr z, GB_End cp 3 jr nz, GB_Next_Bit call &TimeOut jr GB_Wait_For_Change GB_Next_Bit: sub 2 jr nc, GB_GetZero GB_GetOne: ld a, $D4 out (7), a rr c jr GB_Wait_for_W1_and_R1 GB_GetZero: ld a,$E8 out (7),a rr c GB_Wait_for_W1_and_R1: LD DE, $FFFF ; For time-out GB_Cont: call &TimeOut in a, (7) and 3 jr z, GB_Cont ld a, $c0 out (7), a djnz GB_Wait_For_Change ld a,c GB_End pop bc ret TimeOut DEC DE LD A,D OR E ret NZ pop bc pop hl xor a ret PutByte: push bc LD C,A LD B,8 ; 8 Bits PB_Next_Bit: ld d, B ; Only to see if it is working. ld e, $01 ; ld ($800C),de ; ld A, B ; call TX_CHARPUT ; LD A, $C0 ; Set W1 and R1 OUT (7),A Cont: RR C JR NC, PB_SendZero PB_SendOne: LD A, $E8 JR PB_Output_val PB_SendZero: LD A, $D4 PB_Output_val: OUT (7),A LD DE, $FFFF ; For time-out PB_Wait_for_W0_and_R0: IN A,(7) AND 3 JR Z, PB_Continue IN A,(7) AND 3 JR Z, PB_Continue DEC DE LD A,D OR E JR NZ, PB_Wait_for_W0_and_R0 JR PB_End ; If error return. PB_Continue: LD A, $C0 ; Set W1 and R1 OUT (7),A LD DE, $FFFF ; Reload time-out PB_Wait_for_W1_and_R1: DEC DE LD A,D OR E JR Z, PB_End IN A,(7) AND 3 CP 3 JR NZ, PB_Wait_for_W1_and_R1 DJNZ PB_Next_Bit PB_End: POP BC RET CK_DOWN: ; Vol - .db 4, 32, $0E, $12, .db %01010110, %10101010, %10011010, %10010000 ; | | | | | ; ^ ^ ^ ^ ^ ; Bits: Sync Ctrl Group=0 Command=17 Unused ; ; One some new RC5 devices, the Command byte might be 7-bit long. CK_UP: ; Vol + .db 4, 32, $0E, $12, .db %01010110, %10101010, %10011010, %10100000 ; | | | | | ; ^ ^ ^ ^ ^ ; Bits: Sync Ctrl Group=0 Command=16 Unused ; CK_LEFT: ; Prog - .db 4, 32, $0E, $12 .db %01010110, %10101010, %01101010, %10010000 ; | | | | | ; ^ ^ ^ ^ ^ ; Bits: Sync Ctrl Group=0 Command=33 Unused ; CK_RIGHT: ; Prog + .db 18, 13, $0C, $10 .db %11111111, %11000010, %10001010, %10101010 ; 0 1 0 0 0 0 0 0 .db %10101010, %10101010, %00101010, %10101010, ; 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 .db %10101000, %10101010, %10101010, %10101010, ; 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 .db %10010100, %0100010, %10101010, %00101000, ; 1 0 1 1 0 0 0 0 1 0 1 .db %10010100, %0100010 ; 1 0 1 1 0 CK_RECORDED: .db 20 REC_HEADER: .db 13, $0C, $10 REC_DATA: .dw 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 Text: .db "Up/Down:Vol", 0 .db "Left/Right:Prog", 0 .end