
History
    98/07/24 First version
    98/08/12  Added "4. TV Remote Controller Waveforms" and "5. Machine Language Programs".
              Also added "1-1. Machines not Compatible". However, we do not disclose this version. 
    98/08/28 Improved 8/08/12 version to make easier what were difficult to understand. 
    99/10/04 Changed CPU clock from 1.8MHz to 3.6MHz.

Title    Remote Control with onHand/Ruputer

Table of Contents
1.Creating light emitting waveforms remote control with software programs
 1-1. Machines not compatible
2.Setting ports and emitting/receiving light
 2-1. Preparation for start of communications
 2-2. Termination of communications
3.Method of setting prescaler and timer
 3-1. Functions of a prescaler and timer
 3-2. Register of a prescaler and timer
 3-3. Method of setting a prescaler and timer
4.TV remote control waveforms
 4-1. Header unit
 4-2. Fixed data unit
 4-3. Button data unit
 4-4. Repetition
5.Machine language programs
 5-1. Data structure
 5-2. Descriptions on program operations

1.Creating light emitting waveforms remote control with software programs
      Light emitting waveforms of remote control varies depending on a manufacturer.  Unlike RS23C, SIR and ASK, no infrared rays can be emitted using a serial interface (UART) circuit built-in in CPU. 
      In addition, remote control is not equipped with convenient BIOS or library such as bi_comopen, bi_comclose of com port.  Moreover, onHand/Ruputer is only provided with a circuit to create carrier of a light emitting waveform of a remote control.      
     Therefore, you have to create a light emitting waveform with a software program by taking fullest advantage of a machine language, after having acquired a certain level of knowledge on circuit configuration.  For instance, you should count time to emit infrared rays and stop it with a soft timer. 
     Nevertheless, if you refer to a sample program, we are sure you will be able to create a remote control program relatively with ease.   

 1-1. Machines not compatible
    Subroutines we've created this time are compatible with main TV models commercially available in Japan.  However, they are not with some models (See the list below).  Note, in addition, the subroutines are not compatible with remote control other than TV (i.e., video, radio cassette recorder, and air conditioner).
    We will be able to cover many of these remote controls not included this time, with semi-learning remote control that we plan to create next time.  Unfortunately, although we cannot say now when we will be able to release the semi-learning remote control in a what kind of form, we are committed to do so.  Please give us some time.     
    (TV models not compatible)
        Some models of Sony:        rtype_sony_2
        Some models of Matsushita:  rtype_national_3
        All models of Sharp:
        Some models of Funai:       rtype_national_2
        Some models of NEC:         rtype_nec_3
        
        (Numbers (***_2, etc.) attached to models of each company do not have any special meaning.)

2.Setting ports and emitting/receiving light
2-1. Preparation for start of communications
      To start remote control communications, set various ports with the following procedures.  In addition, for contents of various ports, note the following two points. 
    
        1) "IOaddress.txt" of onHand/Ruputer Development Kit
        2) "MN1020219 LSI User's Manual"
    
        LSI User's Manual is planned to open in Matsushita's home page. 
        
        http://www.mec.panasonic.co.jp/sc/division/e-micom/manual_d/mn102l00/102l_lsi.html
        
    
    (1)Set a communications method.
          Output data 0x07 of 1 byte to address 0x000070 and set a communications method to "Learning Remote Control II".  If you only wish to emit light (i.e., you do not plan to receive light), you may output data 0x04 and set a communications method to "Learning Remote Control".  If you wish to receive light, set to "Learning Remote Control II". 
    
    (2)Set either Emit Light or Receive Light. 
          In case of the former,
            (1) Set SRADY output terminal of CPU to 0 (Low level). 
              Then, the REMCM terminal of a gate array becomes an input terminal. 
                Set bit 6 of address 0x00ffc3 to 0.
                movbu   (0xffc3),Dn     # Port 3 output register of 0xffc3=CPU
                and     ~0x40,Dn        # Set bit 6 to 0(~ is negative, complement of 1.)
                movb    Dn,(0xffc3)     #
            (2) Set REMCN terminal of CPU as output terminal. 
                Set bit 5 of address 0x00ffe4 to 1. 
                movbu   (0xffe4),Dn     # Port 4 I/O control register of 0xffe4=CPU.
                or      0x20,Dn         # Set bit 5 to 1.
                movb    Dn,(0xffe4)     #
            (3) Set POWCT2 output terminal of CPU to O(Low level). 
              Then, the power of the infrared ray receiving element is turned off. 
                Set bit 1 of address 0x00ffc5 to 0. 
                movbu   (0xffc5),Dn     # Port 5 output register of 0xffc5=CPU. 
                and     ~0x02,Dn        # Set bit 1 to 0.(~ is negative, complement of 1.)
                movb    Dn,(0xffc5)     #
          In case of the latter,
            (1) Set SRADY output terminal of CPU to 1 (High level). 
              Then, REMCM terminal of a gate array becomes an output terminal.
                Set bit 6 of address 0x00ffc3 to 1. 
                movbu   (0xffc3),Dn     # Port 3 output register of 0xffc3=CPU.
                or      0x40,Dn         # Set bit 6 to 1.
                movb    Dn,(0xffc3)     #
            (2) Set REMCN terminal of CPU as an internal terminal. 
                Set bit 5 of address 0x00ffe4 to 0.
                movbu   (0xffe4),Dn     # Port 4 I/O control register of 0xffe4=CPU.
                and     ~0x20,Dn        # Set bit 5 to 0(~ is negative, complement of 1.)
                movb    Dn,(0xffe4)     #
            (3) Set POWCT2 output terminal of CPU to 1(High level).
              Then, the power of the infrared ray receiving element is turned on. 
                Set bit 1 of address 0x00ffc5 to 1.
                movbu   (0xffc5),Dn     # Port 5 output register 0xffc5=CPU.
                or      0x02,Dn         # Set bit 1 to 1.
                movb    Dn,(0xffc5)     #
    
    (3)If you emit light, set frequency of light emitting carrier. 
          A carrier can be created with a prescaler and timer circuit incorporated in CPU.  Here we omit explanations on how to set a prescaler and timer since they are so complicated.  To set them easily, refer to an example of a sample program. 
            File Name:COMREM.S
            Subroutine Name:_rem_set,tmps_set
        If you use "tmps_set" sub-routine writtein in a machine language, you can easily set frequency of carrier. 
          For detailed method of setting a prescaler and timer circuit, refer to "3.Method of setting prescaler and timer". 
    
    (4)If you plan to receive light, set filter frequency of carrier. 
          A carrier filer converts received waveform with carrier of 38KHz, etc., into a waveform that can be easily emitted and stopped by software, as illustrated below.        
        fig.2-1(with carrier)
         +-+ +-+  +-+ +-+ +-+                    +-+ +-+ +-+ +-+ +-+              
         | | | |    | | | | |                    | | | |   | | | | |              
        +  +-+ +-// +-+ +-+ +---------//---------+ +-+ +-//+-+ +-+ +----//---
                        |-+-|                    |-+-| 
                          +--- 38KHz               +--- 38KHz
        
        fig.2-2(after filtering)
        +-------//----------+                    +------//---------+              
        |                   |                    |                 |              
        +                   +--------//----------+                 +----//---
        
          If carrier is 38KHz, output data 0x06 of 1 byte to address 0x000072, and set filter frequency to 15.3-30.7KHz, which shows frequency of carrier.  In essence, we should set 30.7-61.4KHz when frequency = 38KHz.  However, when duty of carrier is not 50%, setting of frequency of carrier one rank lower would seem stabilize the circuit.

2-2. Termination of communications
      To terminate remote control communications, set various ports with the following procedures: 
    (1) If you received light, stop the filter circuit of carrier.
          Output data 0x00 of 1 byte to address 0x000072, and stop the filter circuit. 
    
    (2) If you emitted light, stop the circuit of emitting carrier.
          Stop a prescaler and timer circuit incorporated in CPU.
            (1) Stop prescaler 1. 
                Output data 0x00 of 1 byte to address 0x00ff2b.
            (2) Stop timer 3.
                Set bit 6 of address 0x00fe23 to 0. 
    
    (3)Set Emit Light. 
          Set same as Emit Light. 
            (1) Set SRADY output terminal of CPU to 0 (Low level). 
              Then, REMCM terminal of a gate array becomes an input terminal. 
                Set bit 6 of address 0x00ffc3 to 0. 
            (2) Set REMCN terminal of CPU as an output terminal.
                Set bit 5 of address 0x00ffe4 to 1. 
            (3) Set POWCT2 output terminal of CPU to 0 (Low level). 
              Then, the power of infrared light receiving element is turned off. 
                Set bit 1 of address 0x00ffc5 to 0. 
    
    (4)Set a communications method to "None". 
          Output data 0x00 of 1 byte to address 0x000070 and set a communications method to "None". 

3.Method of setting prescaler and timer 
  3-1. Functions of a prescaler and timer
      The CPU of onHand/Ruputer is provided with two built-in prescalers of 8 bits and four timers of 8 bits.  Carrier of remote control is created by using prescaler 1 and timer 3.  OS of onHand/Ruputer makes cascade connection of prescaler 1 and timer 3 when it is started up.  A demultiply ratio of prescaler 1 is 1 to 256.  That of timer 3 is also 1 to 256.  Thus, that resulting from cascade connection shall be as follows:
    
        Demultiply ratio  =  P x T (P = 1 - 256, T = 1 - 256)
    
    
    
        fig.3-1
                +-----------------------+   +-----------------------+   +------------------+
       SYSCLK ->|Prescaler              |-->|Timer                  |-->|1/2 Circuit       |--> Carrier
     (920KHz)   |Demultiply ratio=1-256 |   |Demultiply ratio=1-256 |   |Demultiply ratio=2|
    (1840KHz)   +-----------------------+   +-----------------------+   +------------------+ 
    
    Note:SYSCLK has two types of 920KHz and 840KHz. SYSCLK of onHand/Ruputer that shows 19200 bps when connected to Docking Station is 920KHz. SYSCLK of onHand/Ruputer that shows 38400bps is 1840KHz. 
    
      It seems that carrier of remote control is mostly 38KHz in Japan.  You can make carrier 38KHz, by calculating with the following expression and setting the demultiply ratio to either 12 or 24. 
    
        Demultiply ratio = 460KHz / 38KHz =: 12.1 (SYSCLK=920KHz)
        Demultiply ratio = 920KHz / 38KHz =: 24.2 (SYSCLK=1840KHz)
    
      There seems to be remote controls using 32KHz, 36KHz, or 40 KHz other than 38KHz. For instance, in case of 40KHz,
    
        Demultiply ratio = 460KHz / 40KHz =: 11.5 (SYSCLK=920KHz)
        Demultiply ratio = 920KHz / 40KHz =: 23.0 (SYSCLK=1840KHz)
    
    When SYSCLK=920KHz, you must wonder whichever demultiply ratio you should choose, 11 or 12. In such a case, create both and use the one with a longer communications distance. 

 3-2. Register of a prescaler and timer 
      Here we describe how to set a prescaler and timer of MN1020219.  For details, refer to LSI User's Manuarl of MN1020219.  The LSI User's Manual is planned to open in the following home page of Matsushita.    
    http://www.mec.panasonic.co.jp/sc/division/e-micom/manual_d/mn102l00/102l_lsi.html
    
    (1)Register of Prescaler 1
      A prescaler is a binary down counter of 8 bits and demultiplies 1 to 256?. It demultiplies at a set value +1.  The prescaler has the following 3 registers:    
    * Mode Register (PS1MD)
        This controls operation of the prescaler. [] of 0/1 is an initial value of onHand/Ruputer.
    Address = 0xfe2b
      Bit   symbol      R/W function                                0               1
      0-5   -   -       No function                                 -               -
      6     PS1LD       Read a value of R/W base register 
                        into a binary counter.                      [No function]   Read
      7     PS1EN       Control of operation of R/W prescaler       [Stop]          Operation

    * Binary counter(PS1BC)
        This is a binary counter of the prescaler.  It can read out a count value. It cannot write. 
    Address = 0xfe0b
      Bit   symbol      R/W function                            0               1
      0-7   PS1BC       R   binary count value                  -               -

    * Base register(PS1BR)
        This sets a demultiply ratio. It demultiplies at a set value +1.
    Address = 0xfe1b
      Bit   symbol      R/W function                            0               1
      0-7   PS1BR       R/W demultiply ratio(Count interval)    -               -

    (2)Register of timer 3
      Timer is a binary down counter of 8 bits and demultiplies 1-256?.  It demultiplies at a set value +1.  The timer has the following 3 registers.    
    * Mode register(TM3MD)
        This controls operation of the timer. [] of 0/1 is an initial value of onHand/Ruputer.
    Address = 0xfe23
      Bit   symbol      R/W function                            0               1
      0-1   TM3S        Select R/W clock source.                00=SBT1 terminal(event counter)
                                                                01=SYSCLK
                                                                10=Prescaler 0 output
                                                                11=[Prescaler1 output]
      2-5   -       -   No function                              -              -
      6     TM3LD       Read a value of R/W base register       [No function]   Read
                        into a binary counter.
      7     TM3EN       Control of operation of R/W timer       [Stop]          Operation

    * Binary counter(TM3BC)
        This is a binary counter of the timer. It can read out a count value.
        It cannot write.
    Address = 0xfe03
      Bit   symbol      R/W function                            0               1
      0-7   TM3BC       R   Binary count value                  -               -

    * Base register(TM3BR)
        It sets a demultiply ratio. It demultiplies at a set value +1.
    Address = 0xfe13
      Bit   symbol      R/W function                            0               1
      0-7   TM3BR       R/W demultiply ratio(count interval)    -               -

 3-3. Method of setting a prescaler and timer
      We describe the following procedures for setting a demultiply ratio (count interval) of a prescaler and timer.  Here we show you the steps of setting a demultiply ratio of a prescaler.  The procedures for setting a demultiply ratio of a timer are same as those for a prescaler. 
    1) Set a mode register(PS1MD).PS1EN = 0 , PS1LD = 0
    2) Set a demultiply ratio of a prescaler.
       Write a demultiply ratio of -1 to a base register (PS1BR). However, if a demultiply ratio = 1, you should write a dummy value (approximately 15) here.
    3) Set a mode register(PS1MD).PS1EN = 0 , PS1LD = 1
    4) Set a mode register(PS1MD).PS1EN = 0 , PS1LD = 0
    5) Set a mode register(PS1MD).PS1EN = 1 , PS1LD = 0
       Then, start count operation.  However, if a demultiply ratio = 1, execute step 6). 
    6) If a demultiply ratio = 1, write 0 to a base register (PS1BR). 

4.TV remote control waveforms
      I,  the author of this paper, am not an expert of remote controller.  Thus, I may have made some wrong descriptions.  In such a case, please excuse me. 
      Receiving light emitting waveform of a remote control compatible with multiple manufacturers that I bought about 4 years ago, I observed it with an oscilloscope.
 
      Remote control waveforms for TV are composed of some repeated parts of emitting light at approximately 38 KHz (frequencies other than 38KHz are also possible) and those of stopping emission of light.  It seems that different (time) lengths of light emitting parts and light stopping parts are represented by 0 and 1. 
      Many of remote controls for TV seem to be constituted of the following three parts which repeatedly appear. 
    
        fig.4-1
        +--------+      +---------+---------+        +-------+
        |        |      |         |         |        |       |
        +        +------+                   +---//---+       +--//
        |--<00>--+-<02>-+---<58>--+--<14>---+---<12>-+--<00>-+--//
        |--- (1)--+--- (2)--+--- (3)--+----- (4)-----//
        
        (1) Header unit
                <00> Header light emitting time
                <02> Header stop time
        (2) Fixed data unit
                <58>Fixed data
        (3)Button data unit
                <14> Button 1-6ch
                <26>       7-12ch
                <38> Power supply, Volume Loud, Small,ch-,+
                <48>TV,Others
        (4)Repetitions
                <12>Pause
    
    Note: Although (2) fixed data unit and (3) button data unit have waveforms that look similar, there are some fixed part depending on button data contents of which vary depending on a button to be pressed and a model of remote control. 

 4-1. Header unit
      In front of data (head) there is a part named a header. (There are some models without a header.)  There seem to be models having light emitting time of either 3-4 mS and of 9ms.  Stop time may be approximately 1/4 to 1/1 of light emitting time. 
      Two objectives of a header are listed below.  Note, however, they are just an assumption. 
    
        1) Preparation time to prevent subsequent data from being missed, by interrupting CPU on the light receiving side. 
        2) A mark just to identify a header of data. 

 4-2. Fixed data unit
      Data unit (fixed data unit and button data unit) represents 0 and 1 by means of one kind of light emitting time and two kinds of stop time. 
      In most models, light emitting time is constant and most frequently from approximately 400uS to 600uS.  There are two types of stop time, namely, approximately 400uS to 600uS and 1.2m to 1.8mS, approximately a triple of the former.  In this program, we set 0 to shorter stop time and 1 to longer stop time.  
      Note, in addition, the light emitting part shown in fig.4-2 does not continue to emit light, but repeatedly emits and stops light at frequencies of around 30 -40 kHz. (carrier)
    
        fig.4-2
        +-------+      +-------+            +-------+
        | Emit  | Stop | Emit  |    Stop    | Emit  |
        | light |      | light |            | light |
        +       +------+       +------------+       +--//
        |--<08>-+--<10>+--<04>-+----<06>----+-
        |-------0------+---------1----------| 
    
                <08>Data 0 light emitting time
                <10>Data 0 stop
                <04>Data 1 emit light
                <06>Data 1 stop
    
      A fixed data is a part where contents of 0/1 are fixed depending on a model of remote controller.  Some remote controls do not have any fixed data unit. In most cases, the number of bits of the fixed data unit is 8 or 16 bits. 
 4-3. Button data unit
      A button data unit is data assigned to each of button of a remote control (power supply, volume, channel, etc.).  Although there are some remote controls not provided with fixed data units, every model has a button data unit.  The number of bits of button data unit vary, as shown below: 
                6 bits, 8 bits, 11 bits, 12 bits, 16 bits
      In addition, there are some models that emit inverted data immediately after emitting the above number of bits. 

 4-4. Repetition
      Repetitions have the following 3 patterns: 
        1) Models pairing a header unit and a data unit as a set, and repeatedly emitting the set
        2) Models repeatedly emitting a data unit.
        3) Models repeatedly emitting a header unit only. 
    This program corresponds to 1) and 2) above.  It does not correspond to 3). 
Also, there are some models that repeat if you hold down a button, and other models that repeat at least 2 to 3 times even if you hold down a button.    

5.Machine language programs
      Here we describe machine language programs. Please refer to the following 2 points together.
    
    1)For descriptions on assembler of gcc,
        \RupSDK\manual\GCC_AsmManu.txt
    2)For a list of machine language commands of MN10200, CPU of onHand/Ruputer, 
        \RupSDK\manual\MN10200c.txt

 5-1. Data structure
      Data structure of each remote control exists in the latter half of file "COMREM.S".  Data by manufacture and that by model consists of 74 bytes and one of the examples is shown below: 
    
    .align  2
rtype_sanyo_1:      #Actually measured carrier=37.4KHz(set value11)       #model number00
    .hword  (8970 - DHoff) / Deffi                      #<00>header light emitting time
    .hword  (4470 - DLoff) / Deffi                      #<02>header stop
    .hword  ( 560 - DHoff) / Deffi                      #<04>data 1 light emission
    .hword  (1670 - DLoff) / Deffi                      #<06>data 1 stop
    .hword  ( 560 - DHoff) / Deffi                      #<08>data 0 light emission
    .hword  ( 560 - DLoff) / Deffi                      #<10>data0 stop
    .hword  0                                           #<12>Pause
    .hword  0x0008,0x0088,0x0048,0x00c8,0x0028,0x00a8   #<14> Buttons 1-6ch
    .hword  0x0068,0x00e8,0x0018,0x0098,0x0058,0x00d8   #<26>       7-12ch
    .hword  0x0000,0x0090,0x0050,0x005a,0x009a          #<38> Power supply, Volume Loud, Small,ch-,+
    .hword  0x00a0,0x00c0,0x00d0,0x00b0,0x0010          #<48>TV, others
    .hword  0x0cf3                  #<58>Fixed data
    .hword  16                      #<60>Number of fixed data bits
    .hword  8                       #<62>Number of button data bits
    .hword  1                       #<64>Button data inversion 0:no,1:inverted,2:same
    .hword  0                       #<66>Repeat 0:no,1:pause once,2:twice
    .hword  0                       #<68>At the time of repetition 0:no header,1:header exists
    .hword  0x0000                  #<70>Fixed data 2
    .hword  0                       #<72>Fixed data 2 number of bits
rtype_sanyo_2:      #Actually measured carrier=37.4KHz(set value11)       #model number01

    (1).align   2
          A phantom command to place data from an address of even number.  For other phantom commands, refer"\RupSDK\manual\GCC_AsmManu.txt".
    
    (2)rtype_sanyo_1: or rtype_sanyo_2:
          A label. A label is attached to the header of data for every model of remote controls. 
    
    (3)Actually measured carrier
          Actually measured carrier is a frequency of when you observe carrier of remote control compatible with multiple makers that you bought.  Set carrier by using a value of "Set Value" with :_rem_set.  Specify with an input variable id register.    
    (4)Model Number
          A model number is assigned to every remote control model, staring with "00". Specify as an input variable (d0=model number) of:_rem_out. With _rem_out, calculate a header address (rtype_xx) of data for every model from an input variable (d0).  The expression shall be as follows: Here we calculate using #1-1 of _rem_out.
          (rtype_sanyo_2 - rtype_sanyo_1) refers to the number of bytes of every model. Any model should have same number of bytes and be placed in the order of model number. 
        
            rtype_xx = rtype_sanyo_1 + d0 * (rtype_sanyo_2 - rtype_sanyo_1)
        
    (5)#<00>Header light emitting time
          Light emitting time of a header is length of <00> of fig.4-1.
          It describes actually measured header light emitting time in micro second (uS).  In the following example, light emitting time of the header =8.97mS.
        
        .hword  (8970 - DHoff) / Deffi              #<00>Header light emitting time
        
        If there is no header, "0" is described as shown below.
        
        .hword  0                                   #<00>Header light emitting time
        
          Not only header emitting time but also the following time (data 1 light emitting time, etc.) are all managed by the number of loops of machine languages.  The number of loops and time in microseconds are associated by means of 2 constants  (DHoff, Deffi).  They are offset (DHoff) and inclination (Deffi).
          Parts counting time (i.e., loop units) are created in machine languages so that they will not be affected by compile conditions.  It seems, however, that an error of approximately +-10% occurs between specified time in numeric value and actual time.  Even though there is such an error of +-10%, remote control seems to function normally.          
    In addition, <00> of comment refers to the number of bytes from head.  Also, .hword is a phantom command.  IT stores a value of 2 bytes in an address of the current location counter.  For other phantom commands, refer to "\RupSDK\manual\GCC_AsmManu.txt".
        
    (6)#<02>Header stop time
          Header stop time is time length of light stop part of <02> of fig.4-1.  It describes actually measured header stop time in microseconds (uS).  In the following example, header stop time =4.47mS.
        
        .hword  (4470 - DLoff) / Deffi              #<02>Header stop
        
    (7)#<04>Data 1 light emitting time
          Data 1 light emitting time is length of <04> of fig.4-2.  It describes actually measured data 1 light emitting time in microseconds (uS).  In the following example, data 1 light emitting time=0.56mS.
        
        .hword  ( 560 - DHoff) / Deffi              #<04>Data 1 light emission
        
    (8)#<06>Data 1 stop time
          Data 1 stop time is length of <06> of fig.4-2.  It describes actually measured data 1 stop time in microseconds (uS). In the following example, data 1 stop time=1.67mS.
        
        .hword  (1670 - DLoff) / Deffi              #<06>Data 1 stop
        
    (9)#<08>Data 0 light emitting time
          Data 0 light emitting time is length of <08> of fig.4-2. It describes actually measures data 0 light emitting time in microseconds (uS). In the following example, data 0 light emitting time=0.56mS.
        
        .hword  ( 560 - DHoff) / Deffi              #<08>Data 0 light emission
        
    (10)#<10>Data 0 stop time
          Data 0 stop time is length of <10> of fig.4-2.  It describes actually measured data 0 stop time in microseconds (uS).  In the following example, data 0 stop time=0.56mS.
        
    .hword  ( 560 - DLoff) / Deffi              #<10>Data 0 stop
        
    (11)#<12>Pause time
          Pause time is length of light stop part <12> of fig.4-1.  It describes actually measured pause time in microseconds (uS). In the following example, pause time =21.8mS.
        
        .hword  (21800 - DLoff) / Deffi             #<12>pause time
        
    (12)#<66>Repeat 0:none,1:pause once,2:twice
          Repetition means how many times (1) to (3) of fig.4-1 are repeated.  In case of repetitions, they are made after stopping light emission during the above-mentioned pause time only.  Depending on a model of a remote control, a number of repetitions differs. In addition, in some models, light is repeatedly emitted if you hold down a button.  However, this program does not implement that specification.
          In case of "0", no repetition is made. In other words, light is emitted only once
          In case of "1", a repetition is made once. In other means, light is emitted twice. 
          In case of "2", repetitions are made twice.  In other words, light is emitted three times. 
          If you specify "3" or greater, working are named "working:" may overflow.  Thus, do not set any number exceeding "3". 
        "working:" is 256-byte area that has been defined at the end of COMREM.S machine language program file.
        
    (13)#<68>At the time of repetitions 0:no header,1:header exists
          In case of repetitions, specify whether to repeat with a header or without a header.  Some models of remote control attach a header at the time of repetitions, while others do not.
          "0" means that there is no header.  Steps (2) and (3) of fig.4-1are repeated.
          "1" means that there is a header. Steps (1) to (3) of fig.4-1 are repeated. 
        
    (14)#<58>Fixed data, #<60>number of fixed data bits
          Fixed data are contents of <58> of fig.4-1.  The number of fixed data bits is the bit number of that.  Contents of fixed data represent 1 and 0 by means of light emitting/stop waveforms shown in fig.4-2.   
          There are some models of remote control that do not have any fixed data. In such a case, specify the number of fixed data bits = 0.  For instance, rtype_victor_3 does not have fixed data.
          You can specify up to 16 bits in fixed data of <58>.   Models having fixed data exceeding 17 bits should use <70> fixed data 2.  You can specify up to 32 bits of fixed data with two together.
          In contents of 16 bits of <58>, the number of bits specified with <60> counting from low order bit is the number of effective bits.  For instance, 
        
                <58>Fixed data = 0x35a9
                <60>When the number of fixed data bits = 9,,
        
        Low order 9 bits are effective, and light emission starts from higher bits (in this case, bit 8).
        
                Bits    15 14 13 12 11 10  9  8   7  6  5  4  3  2  1  0
                <58>=    0  1  0  1  0  1  0  1   1  0  1  0  1  0  0  1
                                              v   v  v  v  v  v  v  v  v 
                Light emission=               1   1  0  1  0  1  0  0  1
        
          If there are fixed data 2, fixed data 2 is continuously emitted in similar manner.         
    (15)#<14> Buttons 1-6ch, #<62>Number of button data bits
          "#<14> Button 1-6ch - #<48>TV, others" are contents of remote control buttons.  In this sample program, only "#<38> Power supply, Volume loud, small,ch-,+" button is used.  Although other buttons are not used, button data is described in data areas.  Operation of buttons other than "#<38> Power supply, Volume loud, small,ch-,+" have not been checked. 
          Button data are contents of <14>- of fig.4-1. The number of button data bits is the bit number of that.  Contents of button data represent 1 and 0 by light emitting/stop waveforms shown in fig.4-2. 
          Handling (processing of program) of button data and the number of button data bits are same as the case with "#<58>Fixed data,#<60>Fixed data bit number". 
        
    (16)#<64>Button data inversion 0:none,1:inverted,2:same
          Some models of remote control emit button inversion (negative, complement of 1) immediately after emitting button data. 
          Button data inversions are contents of <14> to the latter half of fig.4.1.  Therefore, button data inversion may occur or may not.  If so, there are two cases, namely, 1:when inversion is re-emitted again and 2: same content is emitted. The number of bits is same as that of button data. 
          We suppose inversion is emitted because a bit check of whether button data has any bit error is being made on the receiving side (TV side). 
          In addition, in a sample program "COMREM.S", some models describe a total of 16 bits composed of the button data of 8 bits and the following "button data inversion" of 8 bits as "button data".  An example of this is rtype_aiwa_1(2).
    
 5-2. Descriptions on program operations 
      Here, centering on subroutine:_rem_out:, we describe how machine language programs operate.
    
    (1) Calling from main.c 
          _rem_out  is used as a function ofmain.c , as shown below. 
        
                void rem_out(int model number, int button number);     /* light emission */
        
          In this example, there are "two arguments of int type". Each of the two int-type arguments is given to d0, and d1 regiser, respectively. For a method of handling other than this, refer to "c language-machine language interface" of gcc_asmdescriptions.
          In addition, to call rem_out from the outside such as main.c, you should make a global declaration in COMREM.S. 
        
                .global     _rem_out    # Remote control waveform output
    
    (2).equ PSW_IEbit,  0x0800
          MN10200  has a special register of "psw". psw 0x0800 bit of psw is a bit to allow/prohibit interruption. If you prohibit interruption, any interruption other than non-maskable interruption, will be prohibited. 
          In processing wherein remote control waveform is actually emitted, an interruption is prohibited. This is because a waveform is extended? if any interruption such as 1Hz occurs during light emission.  However, if interruption is prohibiteed for 1 second or longer, onHand/Ruputer system may not be able to process 1Hz. 
        
        (Notes on prohibition of interruptions)
          By the way...
          It is best to create a program without prohibiting interruptions.  However, there are some cases, like this, which inevitably needs interruptions.  In such a case, please try your best to minimize interruption prohibition time for the reasons of creating a program. 
          In usual conditions, onHand/Ruputer system interrupts the following.  With interruptions prohibited, be careful as these processing will be suspended. 
        
            (1)1Hz processing
                .Processing of onHand/Ruputer's clock, alarm matching, etc.
                .Counting of battery remaining volume
            (2)4Hz processing
                .LCD flashing
                .Timeout processing of SIO
                .El turn-on time processing
            (3)64Hz processing
                .Buzzer processing
                .Key hold down monitoring
            (4)Others
                .Key interruption
                .SIO(RS232C,infrared port)interruption of receptions
        
        For instance, if you prohibit interruptions for 1 second or longer, the system may not be able to process 1Hz.  If it cannot, onHand/Ruputer's clock will be delayed and naturally alarm detection, etc., will be delayed together with the clock. 
        (However, even though the system cannot process 1Hz, onHand/Ruputer's real time clock counts correct time.  If you reset onHand/Ruputer, onHand/Ruputer system will read time of the real time clock and starts counting correct time.)
     
    (3)#push d0,d1,d2,d3,a0,a1,a2
          It seems that if it is called back to the calling side, a subroutine (function) to be called from c needs to hold a register value of when it was invoked.  In_rem_out, all registers except a3 were held.  However, it is necessary to do so?  Isn't it enough to hold some of them?  We don't know yet. 
          If we did not hold any register, the system did not operate at all.  It ran away out of control.  Then, when we held all registers except a3, the system ran without any problem. 
          This time the speed of  _rem_out  when it is called back does not pose any problem, and thus we set so that all registers can be held. 
          However, in a stack area that helds d0 was used as a counter of repeated number in sub-routine:_rem_out.  Therefore, register d0 has always a value of "0" and should end subroutine:_rem_out.
    
    (4)Store kinds of waveforms in working
          Here, we start explaining about program operation.  Its overall flow is as follows
        
            1> Start. Called from main.c, _rem_out starts.
            2> Generate a kind of remote control waveform in a working are named working:. (Preparation for light emission)
                Pair light emission and stop as a set and repeat the step 2). 
            3> Emit infrared rays depending on a kind of remote control waveform in working:.
                Pair light emission and stop as a set and repeat step 3). 
        
          There is a 256-byte area after a label working at the end of COMREM. As preparation for light emission of a remote control, store kinds of waveforms (0-3) in working.  Preservation processing is from #1-1 to#5-4. There are 4 kinds of waveforms as shown below.  As waveform kind data is 0 to 3, one byte should be enough.  However, in order to facilitate processing and make the processing speed uniform, 1 word (2 bytes) is used. 
        
            working:    Kinds of waveforms
                0       Data0
                1       Data1
                2       Pause
                3       Header
        
    (5)#1-1.Calculate data address from model number. 
          Calculate data address of that model from model number (d0) with the following expression.
        
            rtype_xx = rtype_sanyo_1 + d0 * (rtype_sanyo_2 - rtype_sanyo_1)
        
    (6)#1-2.Store the number of repetitions in a stack. 
          You should save the number of repetitions in a stack.  Use a value of the stack as a counter of the number of repetitions. When the counter reaches "0", repetitions should end.
        
    (7)#1-3. Set a1 to address of working 
          You should set a1 to address of working.  Every time you save a kind of waveform (1-3) in working, a1 will be incremented by +2. 
        
    (8)#1-4. Save a header in working
          Save a kind of waveform (0-3) in working in the following order with steps described in #1-4-#4-4: 
        
        1)#1-4.Save a header in working (If none, do not save).
        2)#2.Save fixed date in working (If none, do not save).
        3)#2-7.Save fixed data 2 in working (If none, do not save).
        4)#3.Save button data in working.
        5)#4.Save inversion or same button data into working (if none, do not save).
        
    (9)#5-1.Save one section of dummy data in working
          Add one section of dummy data to the end of button data. Unless you do so, you will not know whether the bit emitted last time was 1 or 0.  As this depends on time from rising edge of light emission to that of next light emission, it is necessary to emit light, using dummy once after light stop time of either last bit 1 or 0 terminates. 
          For instance, in order to output 5 bit of 01010, you should emit light 6 times, as illustrated below:
        
        fig.5-1
          (1)     (2)         (3)     (4)         (5)     (6)
         +---+   +---+        +---+   +---+        +---+   +---+
         |   |   |   |        |   |   |   |        |   |   |   |
         +   +---+   +--------+   +---+   +--------+   +---+   +--//
         |---0---+-----1------+---0---+-----1------+---0---+---Dummy
        
    (10)#5-2.-#5-4.Repetion processing
          Use a stack area as a counter of the number of repetitions where d0 is saved. If (0,a3)=0, there is no repetition, and thus you can proceed to light emission. 
          In case of repetitions, in other words, if (0,a3)<>0, deduct -1 from (0,a3), save pause in working and repeat. 
          Depending on whether it is a repetition with a header or without a header, change where to jump. 
    
    (11)#8.Light emission 
          Processing of light emission is relatively simple. Depending on a kind of waveforms (0-3) saved in working, repeat light emission/stop repeatedly.  How many times should we repeat?  We should repeat till we reach content -2 of a1 register. When A1 register terminates save operation (#1-1 to #5-4), it will be at the end +2 of valid data.
          Depending on a kind of waveform saved in working, assign light emitting time and stop time to d0 and d1 register, respectively, and then invoke subroutine  :rem_HL.  In rem_HL, emit light only while looping d0 times, stop light emission while looping d1 time, and return to the calling side. 
        
      This is the end of our descriptions on program operation. Please let me apologize in advance for any unclear and difficult points to understand. 
    
      As hardware functions of onHand/Ruputer are restricted (limited), those who will create a program for implementing a remote control on onHand/Ruputer may encounter various difficulties.  However, we appreciate your understanding.    
    
===============================================================================
 Copyright (c) 1998-1999.  Seiko Instruments Inc.  All rights reserved. 
===============================================================================
