Using FPPA make a IR remote Digital Output

使用Padauke FPPA的紅外線遙控器的數位輸出控制器
動作說明
    用 KINYO RC-1220 型的電視遙控器
    1. 按下 紅外線的 Power 鍵,可以反覆開關(PWR_IND LED會反覆顯示開關狀態, 亮為開, 暗為關)
    2. 在開的狀況下, 按下 數字鍵 0 ~ 9, 100, 與 往返鍵可以 讓所屬的 GPIO 腳呈現 High 的狀態, 此時對應的 LED 會熄滅
    3. 在關的狀態下則 PWR_IND 熄滅,而其他的 相連 GPIO的 LED 則為亮
 

電路圖
程式碼, 是由 Padauke 的 Applicaiton note. 改過來的

//***************************************************************************
//*****  PDK80Cxx Peocessor Application Example Project   *************
//***************************************************************************
// Example Name :: IRDO    Version 1.00  
// Module Name  :: IRDO
// Abstract:
//         IRDO Demonstration
// Environment:
//         PADAUK FPPA(TM) IDE Tool Version : 0.500 Beta
//
// Revision History:
//         Mar. 22, 2007        Kun-Yi Chen  Created                
/////////////////////////////////////////////////////////////////////////
//  
//————for real IC SOP28 PDK80C18—————————-
IR_rxIO  equ pb.1; //pb.1 input
BEEP        equ pb.2;   //pb.2 output, for Buzzer
PWR_Ind     equ pb.3;   //pb.3 output, function indicator
//————for real IC SOP28 PDK80C18—————————-
FPP0_SP     equ 0x53;
FPP1_SP     equ 0x56;
FPP2_SP     equ 0x62;
FPP3_SP     equ 0x6C;
FPP4_SP     equ 0x70;
FPP5_SP     equ 0x78;
FPP6_SP     equ 0x7A;
FPP7_SP     equ 0x8F;
// IRData_Code
// for KINYO RC-1220
IR_PWR      equ 0x3D;
IR_TVAV     equ 0x05;
IR_PREV     equ 0x35;
IR_NEXT     equ 0x34;
IR_VOLI     equ 0x20;
IR_VOLD     equ 0x21;
IR_NUM1     equ 0x10;
IR_NUM2     equ 0x11;
IR_NUM3     equ 0x12;
IR_NUM4     equ 0x13;
IR_NUM5     equ 0x14;
IR_NUM6     equ 0x15;
IR_NUM7     equ 0x16;
IR_NUM8     equ 0x17;
IR_NUM9     equ 0x18;
IR_NUM0     equ 0x19;
IR_N100     equ 0x9C;
IR_TOG      equ 0x37;
//==================================
//— Internal Memory Define —
//==================================
//—
word RAMindex;
word TxStrPt ;
//–
//—
int  IRDlyCnt;
//—
//—Processor 0 Application parameters definition block
//—-
//–
int  DT0;
int  DT1;
int  DT2;
int  DT3;
//
//–
//–
//—Processor 4 & 5 Application parameters definition block
//  Melody Music player Module
//–
//IR control parameters definition block
IR_DataADR   equ     0x36;
.ramadr IR_DataADR;
int  IRData_ID0; 
int  IRData_ID1; 
int  IRData_ID2; 
int  IRData_ID3; 
int  IRData_Code;
int  IRData_CodeInv;  
int  IRHighDuty;
int  IRSerialBit;
word RAMPtr;
//–
int  IRdt1;
int  IRdt2;
int  IRCtrl;
IR_POWERON  equ     IRCtrl.0;
//— Mouse Tx Buffer —
//—
 // Program Begin
 goto fpp0Boot ;
 goto fpp1Boot ;
 goto fpp2Boot ;
 goto fpp3Boot ;
 goto fpp4Boot ;
 goto fpp5Boot ;
 goto fpp6Boot ;
 goto fpp7Boot ;
//========= start MCU0 program ============//
fpp0Boot:
 set0 clkmd.1;  // turn-off watchdog
 call initGPIO;
//——Low clock switch to High clock—————————————
// mov  a, 0xD0;(d0=11010000)
 mov  a, 0x00;
 mov  eoscr, a; //External OSCillator Register
      // bit-0: 1=Enable XTAL Smith trigger strong mode
      //   0=Disable XTAL Smith trigger strong mode
      // bit-1: 1=Enable XTAL Smith trigger
      //   0=Disable XTAL Smith trigger
      // bit4-2: Option of driving strength in crystal oscillator
      // bit6-5: 00=External RC oscillator
      //   01=32KHz crystal oscillator
      //   10=4Mhz crystal oscillator
      //   11=20MHz crystal oscillator
      // bit7: 1=Enable external RC oscillator or crystal oscillator
      //   0=Disable external RC oscillator or crystal oscillator
 delay 0xFF;  // internal 32KHz need delay 30m/S
 delay 0xFF;  // internal 32KHz need delay 30m/S
 delay 0xFF;  // internal 32KHz need delay 30m/S
 delay 0xFF;  // internal 32KHz need delay 30m/S
 delay 0xFF;  // internal 32KHz need delay 30m/S
 delay 0xFF;  // internal 32KHz need delay 30m/S // external 20MHz need delay 1m/S
 //–  
 mov  a, 0x00 ;
 mov  ihrcrh, a; //bit-0:Internal high RC
 mov  a, 0x88;
 mov  ihrcrl, a; //Calibrate the internal RC as 16Mhz
 delay 0x40 ;  //
    
// mov  a, 0xA4; // select External 4MHz Crystal Clock! (A4=10100100)
 mov  a, 0x14; // (14=00010100)
 mov  clkmd, a;  // Internal Low RC, Watch Dog disable,
      // bit-0: Reset Function
      // bit-1: 1=Enable Watch Dog (default)
      //   0=Disable Watch Dog
      // bit-2: 1=Enable Internal Low RC (default)
      //   0=Disable Internal Low RC
      // bit-3: No Used
      // bit-4: 1=Enable Internal High RC (default)
      //   0=Disable Internal High RC
      // bit-7~5: 000=internal high RC/4
      //   001=internal high RC/2
      //   010=internal high RC
      //   011=external OSC/4
      //   100=external OSC/2
      //   101=external OSC
      //   110=internal low RC/4
      //   111=internal low RC (default)
//——Low clock switch to High clock End———————————–
 delay 0x40 ;  //
 // Stack Pointer Setting for Processor-0
 mov  a, FPP0_SP ;
 mov  sp, a ; 
 //— 
 //– Clear Internal RAM — 
 mov  a, 0x7F;
 mov  lb@RAMindex, a; 
 mov  a, 0x00;
 mov  hb@RAMindex, a;
ClearRAMLoop:
 wdreset;
 idxm RAMindex, a;
 dzsn lb@RAMindex
 goto ClearRAMLoop;    
 // IO setting
 call initGPIO;
 //–
 // MCU setting
 pmode 2 ;    // All of FPPx are running in 500 KHz
 mov  a, 0x03 ; // Enable FPP1 !!
 mov  fppen, a ; 
 
 
FPP0_ReBoot: 
 //—- LED PA.1 Toggle One Time —
FPP0_loop:
 //*************************************************************
 //—— Processor-0 Program routine  ——————
 //*************************************************************
 // Processor Demo is handle the LED sequencer Flasher
 //  the LED Sequence is based on the definition of Table !
 //—- Processor 1 Running in 500KHz —-
 //–
 mov  a, 0x00;
 mov  a, 0x00;
 
fpp0MainLoop: 
 goto  FPP0_loop;  // Wait FPP7 clear control flag
initGPIO:
 
 mov  a, 0xFF;
 mov  pcc, a;
 not  a;
 mov  pc, a;
 
 
 mov  a, 0xFC;
 mov  pbc, a
 not  a;
 or  a, 0x08;
 mov  pb, a;
 ret
 
suspend:
 set0 IRCtrl.7;
 mov  a, 0xFF;
 mov  pac, a ;  //
 // 
 mov  a, 0xFD;  //
 mov  pbc, a ;  //       
 //stopsys;
 goto  fpp0MainLoop;
 
//========== end of MCU0 program ====================================//
//–
//========== start MCU1 PROGRAM =====================================//
fpp1Boot:
 mov  a, FPP1_SP;
 mov  sp, a ; 
 mov  a, 0x07 ; // Enable FPP2 !!
 mov  fppen, a ; 
 
FPP1_ReBoot:
//–
FPP1_LockLoop:
// call  LEDDelay300mS
 goto  FPP1_LockLoop; // Wait FPP0 clear control flag
ClearandBack:
 goto  FPP1_LockLoop;
//================== end of MCU1 program =================================//
//–
//================= start of MCU2 program ================================//
//*********************************************************************
 //*************************************************************
 //—— Processor-2 Program routine  ——————
 //*************************************************************
 // Processor 2 Demo is handle the receiver from Infra-Red module
 //– This IR Command will dominate this demo kit !
 //— and debug this IR Code to UART
 //—- Processor 2 Running in 500KHz —-
fpp2Boot:
 mov  a, FPP2_SP;
 mov  sp, a ;  
 mov  a, 0x0f ; // Enable FPP3!
 mov  fppen, a ; 
  
FPP2_ReBoot: 
FPP2LockLoop:
IR_ReceiverLoop:
 //— Phase 0, lock in High, wait for going low —
 //–    
 //— Phase 1, Identify to Header —
 //— Panasonic header is
 
 // IR Low !! 
IR_WaitIO2Low: 
 
 wait1 IR_rxIO;  // make sure IO is high first !! 
 wait0 IR_rxIO;  // Wait the IR IO low, Header Low phase
 delay 0xC0;   // delay some duration for debounce the Input,
     // this Duration should wide more normal Data !! 
 t0sn IR_rxIO;  // Wait the IR IO low
 goto IR_WaitIO2Low; // Noise maybe !!
 // — IR is Low really!!
 
IR_PassID_High: 
 
 
 wait1 IR_rxIO;   // Wait the IR IO High, pass the ID, Header High phase
 mov  a, 0x08;  //
 mov  IRSerialBit, a;  // 8 bit serial data in
 mov  a, IR_DataADR;        //setting pointer to 0x36 IRData_ID0
 mov  lb@RAMPtr, a; 
 //—————
IR_DataSerialLow:
 wait0 IR_rxIO;   // Wait the IR IO low, then go next phase wait high and calculate High duty
 // IR is low !
IR_DataSerialHigh:   // Next phase !!
 // wait high for calculate the Duty —
 wait1 IR_rxIO;   // Wait the IR IO High!!
 //— Monitor the High Duty — Here —
 // — IR data is High now !!
 clear IRHighDuty; 
IR_PollingHighDuty:
 t1sn IR_rxIO;   // calcultae High duty until IR Data is low
 goto IRFromHigh2Low;    
 nop; // increament the counter length, avoid overflow persistently  
 nop; // increament the counter length, avoid overflow persistently  
 izsn IRHighDuty;
 goto  IR_PollingHighDuty; 
 //—- Time-Out, Error Correction —
 goto IR_ReadDataTimeOutError;
 
IRFromHigh2Low:
 mov  a, IRHighDuty;
 sub  a, 0x40; 
 t0sn flag.1 ;  // data is 1 or 0 ? 
 goto IR_ReadSerialDataHighBit;
 set1 flag.1 ; // set Flag.c = 1
 nop
 goto IR_ReadSerialnextBit;
IR_ReadSerialDataHighBit: 
 nop
 set0 flag.1 ; // set Flag.c = 0
IR_ReadSerialnextBit: 
 idxm a, RAMPtr;
 src  a;
 idxm RAMPtr, a;
 dzsn IRSerialBit; 
 goto IR_DataSerialHigh; 
 //–
 inc  lb@RAMPtr;
 mov  a, lb@RAMPtr;
// ceqsn a, 0x26 ;
 ceqsn a, 0x3C ;
 goto IR_NextBytesLoop ;
 goto IR_ReadDataSuccessEnd;
IR_NextBytesLoop: 
// tog pb.3;    //debug
 mov  a, 0x08;  //
 mov  IRSerialBit, a;  // 8 bit serial data in 
 goto IR_DataSerialHigh;
 
IR_ReadDataSuccessEnd: 
//—
//======== IR Command Code parser and decode command ===
//— 
 
 call    DeBounceDly;
 //—- Command #1 ?!
 mov  a, IRData_Code;
 ceqsn a, IR_PWR;   // KINYO RC-1220
 goto IRParseCommandCode1;
 // — Press PowerKey
    t1sn    IR_POWERON; // Is IR Running
    goto    IRPowerCommandParser0;
    // will trun off all output 
    set0    IR_POWERON;
    // trun off LED of power indication;
 set1 PWR_Ind;
 call ClearPBH;
 call ClearPC;
 // Generation a Tone
 mov     a, 152;
 mov     DT3, a;
 call    GenTone;  
 goto  IRCommandParserEnd;  // end of IR Command Parser
 // will trun on
IRPowerCommandParser0: 
 //— IR startup —
 set1 IR_POWERON;  // Enable Remote-Controller Mode
 // Trun on LED of power indication
 set0    PWR_Ind;
 call ClearPBH; q
 call ClearPC;
 
 // Generation a Tone
 mov     a, 128;
 mov     DT3, a;
 call    GenTone;
 goto  IRCommandParserEnd; // end of IR Command Parser
// Subroutine for Generation tone
GenTone:
    mov     a, 0xFF;
 mov  DT1, a;
 mov  a, 5;
 mov  DT2, a;
GenTone_Loop: 
 delay DT3;
 tog  pb.2;
 dzsn DT1;
 goto GenTone_Loop;
 dzsn DT2;
 goto GenTone_Loop;
 set0 pb.2;
    ret
IRParseCommandCode1:
 t1sn IR_POWERON;  // check Is PowerOn Mode;
 goto IRCommandParserEnd;
 
 //—- Command #2 ?!
 ceqsn a, IR_NUM1;  // // KINYO RC-1220
 goto IRParseCommandCode2;
 mov  a, 0x01;
 mov  pc, a;
 call ClearPBH;
 goto  IRCommandParserEnd; // end of IR Command Parser
ClearPBH:
 mov  a, pb;
 and  a, 0x0F;
 mov  pb, a;
 ret
ClearPC:
 mov  a, 0x00;
 mov  pc, a;
 ret
 
IRParseCommandCode2:
 //—- Command #3 ?!
 ceqsn a, IR_NUM2;  // // KINYO RC-1220
 goto IRParseCommandCode3;
 mov  a, 0x02;
 mov  pc, a;
 call ClearPBH;
 goto IRCommandParserEnd;
 
IRParseCommandCode3:
 //—- Command #4 ?!
 ceqsn a, IR_NUM3;  // // KINYO RC-1220
 goto IRParseCommandCode4;
 mov  a, 0x04;
 mov  pc, a;
 call ClearPBH; 
 goto IRCommandParserEnd;
IRParseCommandCode4:
 //—- Command #5 ?!
 ceqsn a, IR_NUM4;  // // KINYO RC-1220
 goto IRParseCommandCode5;
 mov  a, 0x08;
 mov  pc, a;
 call ClearPBH; 
 goto IRCommandParserEnd;
IRParseCommandCode5:
//—- Command #6 ?!
 ceqsn a, IR_NUM5;  // // KINYO RC-1220
 goto IRParseCommandCode6;
 mov  a, 0x10;
 mov  pc, a;
 call ClearPBH;
 goto IRCommandParserEnd;
 
IRParseCommandCode6:
//—- Command #7 ?!
 ceqsn a, IR_NUM6;  // // KINYO RC-1220
 goto IRParseCommandCode7;
 mov  a, 0x20;
 mov  pc, a;
 call ClearPBH;
 goto IRCommandParserEnd;
IRParseCommandCode7:
//—- Command #8 ?!
 ceqsn a, IR_NUM7;  // // KINYO RC-1220
 goto IRParseCommandCode8;
 mov  a, 0x40;
 mov  pc, a;
 call ClearPBH;
 goto IRCommandParserEnd;
IRParseCommandCode8:
//—- Command #9 ?!
 ceqsn a, IR_NUM8;  // // KINYO RC-1220
 goto IRParseCommandCode9;
 mov  a, 0x80;
 mov  pc, a;
 call ClearPBH;
 goto IRCommandParserEnd;
IRParseCommandCode9:
//—- Command #10 ?!
 ceqsn a, IR_NUM9;  // // KINYO RC-1220
 goto IRParseCommandCode0A;
 call ClearPC;
 call ClearPBH;
 set1 pb.4;
 goto IRCommandParserEnd;
 
IRParseCommandCode0A:
 //—- Command #11 ?!
 ceqsn a, IR_NUM0;  // // KINYO RC-1220
 goto IRParseCommandCodeB;
 call ClearPC;
 call ClearPBH;
 set1 pb.5;
 goto IRCommandParserEnd;
IRParseCommandCodeB:
 //—- Command #12 ?!
 ceqsn a, IR_N100;  // // KINYO RC-1220
 goto IRParseCommandCodeC;
 call ClearPC;
 call ClearPBH;
 set1 pb.6;
 goto IRCommandParserEnd;
IRParseCommandCodeC:
 //—- Command #13 ?!
 ceqsn a, IR_TOG;  // KINYO RC-1220
    goto IRCommandParserEnd;
 call ClearPC;
 call ClearPBH;
 set1 pb.7;
 goto IRCommandParserEnd;
///============== For Debug using the UART ===========
IRCommandParserEnd:
IR_ReadDataTimeOutError:
// call IR_DelaySometime;
//====== End of Debug for UART ===========================
 
 goto IR_ReceiverLoop; // goto Motor Begin; 
 
 //–
IR_DelaySometime:                        // ~ 256*256*15*1us
        mov     a, 0x40 ;
        mov     IRdt1, a ;
        mov a, 0x03 ;
        mov     IRdt2, a ;
IR_DelayIntLoop:
        delay   0x60 ;
        dzsn    IRdt1 ;
        goto    IR_DelayIntLoop ;
        dzsn    IRdt2 ;
        goto    IR_DelayIntLoop ;
        ret 
// — IR Sub Routines —
DeBounceDly:
    mov     a, 0xFF
    mov     IRDlyCnt, a
DeBounceDlyLoop:   
    delay   0xFF
    dzsn    IRDlyCnt
    goto    DeBounceDlyLoop
    ret
 
//============== end of MCU2 program ===========================//
//—
//=================start of MCU3 program =======================//
//— PS2 _ UART Function —
fpp3Boot:
    mov     a, FPP3_SP;
 mov  sp, a ; 
 mov  a, 0x1f ; // Enable FPP4 !!
 mov  fppen, a;
// mov  a, 0xCf ; // adjument the I/O delay clock for match 9600 Baudrate
  mov  a, 0x2D ;
  mov  Tx0Baud, a; // 0x2F::19200, 0x63::9600, 0xCB::4800
UART:
  
FPP3_ReBoot: 
FPP3LockLoop:
 //— buzzer  
 goto  UART;
//========== end of MCU3 program ==========================//
//–
//========== start of MCU4 program ========================//
fpp4Boot:
 mov  a,  FPP4_SP ;
 mov  sp, a ; 
 mov  a, 0x3f ; // Enable FPP5 !!
 mov  fppen, a ; 
 //–
 
FPP4_ReBoot:
 goto FPP4_ReBoot; // Wait FPP3 clear control flag
//========== end of MCU4 program ===========//
//–
//========== start of MCU5 program =========//  
fpp5Boot:
 mov  a, FPP5_SP;
 mov  sp, a ; 
 mov  a, 0x7f ; // Enable FPP6 !!
 mov  fppen, a ; 
 //
 //–
FPP5LockLoop:
 goto  FPP5LockLoop; 
//========== end of MCU5 program ===========//
//–
//========== start of MCU6 program =========//
fpp6Boot:
 mov  a, FPP6_SP;
 mov  sp, a ; 
 mov  a, 0xff ; // Enable FPP7, now all FPPx is running !!
 mov  fppen, a ;
 
FPP6_ReBoot: 
 goto  FPP6_ReBoot;
//========== end of MCU6 program ===========//
//–
//========== start of MCU7 program =========//
fpp7Boot: 
 mov  a, FPP7_SP;
 mov  sp, a ; 
 
 
FPP7_ReBoot:  
 goto  FPP7_ReBoot;  // Wait FPP6 clear control flag
//========== end of MCU7 program ===========//
//==================================================
//–
delaySomemS:                        //
        mov     a, 0x28 ;
        mov     DT3, a ;
dloop6:       
  mov  a, 0x80 ;
        mov     DT2, a ;
dloop7:
        delay   0xCA ;
        dzsn    DT2 ;
        goto    dloop7 ;
        dzsn    DT3 ;
        goto    dloop6 ;
        ret
 
廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: