From: garyf@puente.jpl.nasa.gov (Gary Friedman) Newsgroups: comp.sys.hp48 Subject: Infrared Remote Control Learn/Transmit Source Code for the HP48 Summary: Direct from the Corvallis conference proceedings Keywords: IR, remote, learning, infrared, world is drooling over this... Date: 9 Aug 91 18:26:27 GMT Distribution: comp.sys.handhelds, comp.sys.hp48 Organization: Jet Propulsion Laboratory, Advanced Engineering Group Nntp-Posting-Host: puente Okay, okay! Here is the article on the IR Remote control for the 48!!!! Remember, this was literally the first cut, and there is gobs of room for improvment and polishing! Enjoy! -Gary Friedman ------------------------------------------------------------------ IR Sampling of TV Remotes by Dave Marsh (Typed in by Gary Friedman) Many users have experimented with the HP 48 to make it capable of being a TV remote control unit. With its built-in IR capability numerous schemes have been tried to give the HP 48 additional power. Previously these schemes involved knowing the digital codes used to modulate the 40 KHz IR signal commonly used. With the recent release by HP of their Software Development Tools it is possible to write assembly programs for the HP 48. Faster speed and greater control of the calculator are gained using this approach. A method that occurred to me during lunch one day - I do development work on the HP 48 as part of my job - is implemented in the two programs on the following pages. The basic idea is to sample the incoming IR as fast as possible to digitize the signal and record it. This takes lots of memory, but it actually works. Using this method of "learning" the codes instead of knowing them allows the HP 48 to be used by any IR device. The inverse is used with the second program using the stored sampled signal (stored as a text string) to control the transmitter. This approach is still in the experimental stages and there is much work to be done. Applications include controlling systems such as the BSR system that has in IR controller - at least they used to offer an IR controller. Your HP 48 could, with off-the-shelf components and a simple program, control the lights and appliances of your home or factory. The sampling rate is estimated at about 60 kilohertz, still short of the desired twice the carrier frequency. Still it works quite well. I have written preliminary programs that convert the digitized signal into a graphics object that may be displayed or printed. This aids the decoding of the signal if that is of interest. Once the optimum signal is determined it may be stored in a more memory-efficient form. A complete set of commands for any IR controller could be made available to any user. This aspect of the programming ahs yet to be done. Copies of the program will be available at the conference and time does not allow a complete description of the program here. The listings are commented and there is always room for improvement. One problem is the memory usage of using one nibble where only one bit is needed. Perhaps other programmers will find additional techniques to make the program faster. Dave Marsh 18335 Jakes Way #103 Canyon Country, CA 91351 (818) 362-6822 x3007 (W) [Poster's note: I will try to post an ASC-> version of the binary this weekend. -GF] ----------------------------------------------------------------- * LOOK * A PROGRAM TO SAMPLE I.R. REMOTE CONTROL SIGNALS * * 1: STRING -> 1: STRING * * (C) 1991 DAVE MARSH - THIS PROGRAM MAY BE DISTRIBUTED ONLY IF * IT'S FREE OF CHARGE * * (Insert your favorite disclaimers here) * ASSEMBLE NIBASC \HPHP48-F\ RPL :: CK1NOLASTWD ( CHECK FOR 1 ARG ) CK&DISPATCH1 ( CHECK ARG IS STRING ) THREE :: TOTEMPOB CODE GOSBVL #01115 DisableIntr (FOR SMOOTH INPUT) INTOFF A=DAT1 A SET A TO POINT AT BEGINNING OF STRING GOSBVL #0679B SAVE REGISTERS (SAVEPTR) D1=HEX #0011A 11Ah IS ADDRESS OF I.R. INPUT P= 0 C=0 P DAT1=C P SET 'TRIGGERED' BIT TO 0 D0=A D0=D0+ 5 D0 POINTS TO LENGTH FIELD OF STRING C=DAT0 A C=C-CON A, 5 SUBTRACT 5 FROM LENGTH IN ORDER TO GET DATA LENGTH ONLY D0=D0+ 5 D0 POINTS TO DATA AREA OF STRING A=A+CON A, 10 SET A = D0 C=C+A A SET C= ADDRESS OF END OF STRING B=A A LOOP1 A=DAT1 P LOOP UNTIL TRIGGER BIT IS 1 (I.R. SIGNAL REC'D) ?ABIT=0 0 GOYES LOOP1 LOOP2 A=DAT1 P GET I.R. DATA AND STORE AS NIBBLE OF STRING DAT0=A P D0=D0+ 1 B=B+1 A ?B#C A LOOP UNTIL D0=END OF STRING (STORAGE AREA) GOYES LOOP2 GOSBVL #010E5 AllowIntr ( re-enable interrupts ) GOVLNG #05143 RESTORE REGISTERS (GETPTRLOOP) ENDCODE ; ; ------------------------------------------------------------------ * XMITREM * A PROGRAM TO EMULATE AN I.R. REMOTE CONTROL TRANSMISSION * REQUIRES OUTPUT OF 'LOOK' PROGRAM AS INPUT * * * 1: STRING -> EMPTY STACK * * * (C) 1991 DAVE MARSH- THIS PROGRAM MAY BE DISTRIBUTED ONLY IF * IT'S FREE OF CHARGE * * ASSEMBLE NIBASC \HPHP48-F\ RPL :: CK1NOLASTWD CK&DISPATCH1 ( CHECK FOR 1 ARG- STRING ) THREE :: TOTEMPOB ( MAKE NEW COPY OF STRING IN TEMPORARY MEMORY ) CODE GOSBVL #01115 DisableIntr (FOR SMOOTH TRANSMISSION) INTOFF A=DAT1 A A POINTS TO INPUT STRING (OUTPUT FROM LOOK) D1=D1+ 5 D=D+1 A GOSBVL #0679B SAVEPTR P= 0 C=0 P D1=HEX #0011A 11Ah IS ADDRESS OF I.R. INPUT & CONTROL DAT1=C P SET IR CONTROL BITS TO 0 D0=A D0=D0+ 5 D0 POINTS TO LENGTH FIELD OF STRING D1=HEX #0011C 11Ch IS ADDRESS OF I.R. LED CONTROL (BIT 3) DAT1=C P MAKE SURE LED IS OFF C=DAT0 A C=C-CON A, 5 C IS LENGTH OF DATA STRING ONLY D0=D0+ 5 D0 POINTS TO DATA FIELD OF STRING A=A+CON A, 10 SET A = D0 C=C+A A SET C= ADDRESS OF END OF STRING B=A A R1=A LOOP2 A=DAT0 P A=A-1 P SUBTRACT 1 FROM NIBBLE (FORMS BIT 3 ON OR NOTHING) DAT0=A P AND PUT BACK D0=D0+ 1 INCREMENT NEXT NIBBLE B=B+1 A ?B#C A LOOP UNTIL END OF STRING GOYES LOOP2 A=R1 B=A A D0=A A LOOP3 A=DAT0 P DAT1=A P SEND DATA TO LED (OFF OR ON) D0=D0+ 1 INCREMENT TO NEXT NIBBLE B=B+1 A ?B#C A LOOP UNTIL END OF STRING GOYES LOOP3 A=0 P MAKE SURE LED IS OFF DAT1=A P GOSBVL #010E5 RESTORE INTERRUPTS GOVLNG #05143 GETPTRLOOP ENDCODE ; -- ---------------------------------------------------------------- Gary Friedman Jet Propulsion Laboratory - NASA 4800 Oak Grove Drive, Pasadena, CA. 91109 (818) 354-1447 garyf@puente.JPL.NASA.GOV || {cit-vax,elroy,psivax}!devvax!garyf