⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ir_send.lst

📁 一个用MCU将SHARP 遥控码转为NEC码的小程序
💻 LST
字号:
C51 COMPILER V7.06   IR_SEND                                                               04/28/2008 19:08:16 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE IR_SEND
OBJECT MODULE PLACED IN .\bin\ir_send.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ir_send.c BROWSE DEBUG OBJECTEXTEND OBJECT(.\bin\ir_send.obj)

stmt level    source

   1          /***********项目描述******************************
   2          *本项目的功能:用于将识别到的按键转换为NEC遥控码转发给外围主板
   3          *MCU芯片:AT89S52
   4          *编译环境:KELL-C51
   5          ************************************************/
   6          
   7          /*****************IC Config***********************
   8          *P0(0-7),P1(0-4)P2(0-7) for KEY input
   9          *P1.0 for send IR code pin
  10          *use isp update
  11          *
  12          *****************IC Config***********************/
  13          #include <reg51.h>
  14          #include <main_define.h>
  15          
  16          //#include <AT89x52.H> 
  17          
  18          #define XTALO_FRE_XM   12 //4//  4
  19          //#define XTALO_FRE_12M     1
  20          
  21          #define uchar unsigned char
  22          #define uint    unsigned int  
  23          
  24          //-------ir send pin config------------
  25          #define IR_PIN 0
  26          #define IR_PIN_H  (P1|=(1<<IR_PIN))
  27          #define IR_PIN_L  (P1&=!(1<<IR_PIN))
  28          #define IR_SEND_SYS_CODE             0x7f00 
  29          
  30          #define SUPPORT_KEY_SCAN 0
  31          
  32          #if SUPPORT_KEY_SCAN
              //------------key define------------------
              #define KEY_DIGITAL_0    !((P3&0x01)==0x01)//p3.0
              #define KEY_DIGITAL_1    !((P3&0x02)==0x02)//   (P3|!(0x01<<3))// p3.1
              #define KEY_DIGITAL_2    !((P3&0x04)==0x04) //p3.2
              #define KEY_DIGITAL_3    !((P3&0x08)==0x08)// (P3|!(0x01<<5)) // p3.3
              #define KEY_DIGITAL_4    !((P3&0x10)==0x10) //p3.4
              #define KEY_DIGITAL_5    !((P3&0x20)==0x20)// p3.5
              #define KEY_DIGITAL_6    !((P3&0x80)==0x80)//p3.7
              #define KEY_DIGITAL_7    !((P1&0x01)==0x01)//p1.0
              #define KEY_DIGITAL_8  P2&(1<<0)
              #define KEY_DIGITAL_9  P2&(1<<1)
              #define KEY_VIDEO         P2&(1<<2)
              #define KEY_AUDIO         P2&(1<<3)
              #define KEY_CH_UP         P2&(1<<4)
              #define KEY_CH_DOWN   P2&(1<<5)
              #define KEY_VOL_UP       P2&(1<<6)
              #define KEY_VOL_DOWN P2&(1<<7)
              #define KEY_POWER        P1&(1<<1)
              #define KEY_BACK           P1&(1<<2)
              #define KEY_MUTE          P1&(1<<3)
              #define KEY_NONE         0xff
              
              //------IR SEND CODE DEFINE--------
C51 COMPILER V7.06   IR_SEND                                                               04/28/2008 19:08:16 PAGE 2   

              #define IR_SEND_DIGITAL_0  0x00
              #define IR_SEND_DIGITAL_1  0x01
              #define IR_SEND_DIGITAL_2  0x02
              #define IR_SEND_DIGITAL_3  0x03
              #define IR_SEND_DIGITAL_4  0x04
              #define IR_SEND_DIGITAL_5  0x05
              #define IR_SEND_DIGITAL_6  0x06
              #define IR_SEND_DIGITAL_7  0x07
              #define IR_SEND_DIGITAL_8  0x08
              #define IR_SEND_DIGITAL_9  0x09
              #define IR_SEND_VIDEO         0x0a
              #define IR_SEND_AUDIO         0x0b
              #define IR_SEND_CH_UP         0x0c
              #define IR_SEND_CH_DOWN   0x0d
              #define IR_SEND_VOL_UP       0x0e
              #define IR_SEND_VOL_DOWN  0x0f
              #define IR_SEND_POWER        0x10
              #define IR_SEND_BACK           0x11
              #define IR_SEND_MUTE           0x12
              #endif
  76          
  77          //-----timer----------
  78          void delay_xms(uchar i)
  79          {
  80   1      #if(XTALO_FRE_XM==4)
              uint  b=40,a;//XTALO_FREQUENCE/(12000*10),a;
              #elif(XTALO_FRE_XM==12)
  83   1      //uint  b=3*40,a;//XTALO_FREQUENCE/(12000*10),a;
  84   1      uint  b=3*37,a;//XTALO_FREQUENCE/(12000*10),a;
  85   1      #endif
  86   1               for( a=b*i;a;a--)
  87   1                              ;
  88   1              //          for(b=270;b;b--);//A=100 AND B=270 FOR  ms
  89   1      }
  90          void delay_560us(uchar i)
  91          { 
  92   1      #if(XTALO_FRE_XM==4)
              uint a, b=20;
              #elif(XTALO_FRE_XM==12)
  95   1      uint a, b=3*20;
  96   1      #endif
  97   1      
  98   1               for( a=i*b;a;a--);
  99   1      }
 100          
 101          #if SUPPORT_KEY_SCAN
              //----------------------------------
              uchar key_scan(void)
              {
              if(KEY_DIGITAL_0) 
                      return IR_SEND_DIGITAL_0;                
              else if(KEY_DIGITAL_1)
                      return IR_SEND_DIGITAL_1;
              else if(KEY_DIGITAL_2)
                      return IR_SEND_DIGITAL_2;
              else if(KEY_DIGITAL_3)
                      return IR_SEND_DIGITAL_3;
              else if(KEY_DIGITAL_4)
                      return IR_SEND_DIGITAL_4;
              else if(KEY_DIGITAL_5)
                      return IR_SEND_DIGITAL_5;
              else if(KEY_DIGITAL_6)
C51 COMPILER V7.06   IR_SEND                                                               04/28/2008 19:08:16 PAGE 3   

                      return IR_SEND_DIGITAL_6;
              /*
              else if(KEY_DIGITAL_7)
                      return IR_SEND_DIGITAL_7;
              else if(KEY_DIGITAL_8)
                      return IR_SEND_DIGITAL_8;
              else if(KEY_DIGITAL_9)
                      return IR_SEND_DIGITAL_9;
              else if(KEY_VIDEO)
                      return IR_SEND_VIDEO;
              else if(KEY_AUDIO)
                      return IR_SEND_AUDIO;
              else if(KEY_CH_UP)
                      return IR_SEND_CH_UP;
              else if(KEY_CH_DOWN)
                      return IR_SEND_CH_DOWN;
              else if(KEY_VOL_UP)
                      return IR_SEND_VOL_UP;
              else if(KEY_VOL_DOWN)
                      return IR_SEND_VOL_DOWN;
              else if(KEY_BACK)
                      return IR_SEND_BACK;
              else if(KEY_POWER)
                      return IR_SEND_POWER;
              else if(KEY_MUTE)
                      return IR_SEND_MUTE;
              */
              else return KEY_NONE;
              
              }
              #endif
 149          /*
 150          void mcu_init(void)
 151          {
 152          P0=0xff;
 153          P1=0xff;
 154          P2=0xff;
 155          P3=0xff;
 156          }
 157          */
 158          void ir_send_code_0_bit()
 159          {
 160   1      IR_PIN_L;
 161   1      delay_560us(1);
 162   1      IR_PIN_H;
 163   1      delay_560us(1);
 164   1      }
 165          
 166          void ir_send_code_1_bit()
 167          {
 168   1      IR_PIN_L;
 169   1      delay_560us(1);
 170   1      IR_PIN_H;
 171   1      delay_560us(3);
 172   1      }
 173          
 174          void ir_send_code_one_bit(bit state)
 175          {
 176   1      if(state) 
 177   1              ir_send_code_1_bit();
 178   1      else 
 179   1              ir_send_code_0_bit();
C51 COMPILER V7.06   IR_SEND                                                               04/28/2008 19:08:16 PAGE 4   

 180   1      }
 181          
 182          void ir_send_start_code(void)
 183          {
 184   1      IR_PIN_L;
 185   1      delay_xms(9);
 186   1      IR_PIN_H;
 187   1      delay_xms(4);
 188   1      #if(XTALO_FRE_XM==12)
 189   1      delay_560us(2);// 20080127 add
 190   1      #endif
 191   1      }
 192          
 193          void ir_send_stop_code(void)
 194          {
 195   1      IR_PIN_L;
 196   1      delay_560us(1);
 197   1      IR_PIN_H;
 198   1      //delay_560us(1);
 199   1      }
 200          
 201          void ir_send_sys_code(void)
 202          {
 203   1              uchar i;
 204   1              bit ir_code_bit;
 205   1              for(i=0;i<16;i++)
 206   1              {
 207   2              ir_code_bit=IR_SEND_SYS_CODE&(0x0001<<i);
 208   2              ir_send_code_one_bit(ir_code_bit);
 209   2              }
 210   1              //反码
 211   1      }
 212          void ir_send_command_code(uchar command_code)
 213          {
 214   1              uchar i;
 215   1              bit ir_code_bit;
 216   1              for(i=0;i<8;i++)
 217   1              {
 218   2              ir_code_bit=command_code&(0x01<<i);
 219   2              ir_send_code_one_bit(ir_code_bit);
 220   2              }
 221   1              //反码
 222   1              for(i=0;i<8;i++)
 223   1              {
 224   2              ir_code_bit=command_code&(0x01<<i);
 225   2              ir_send_code_one_bit(!ir_code_bit);
 226   2              }       
 227   1      }
 228          
 229          bit  ir_send(uchar ir_code)
 230          {
 231   1      ir_send_start_code();
 232   1      ir_send_sys_code();
 233   1      ir_send_command_code(ir_code);
 234   1      ir_send_stop_code();
 235   1      return IR_SEND_END;
 236   1      }
 237          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    242    ----
C51 COMPILER V7.06   IR_SEND                                                               04/28/2008 19:08:16 PAGE 5   

   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       3
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -