您的位置:首页单片机PIC单片机
内容搜索:
阅读内容
背景:#EDF0F5 #FAFBE6 #FFF2E2 #FDE6E0 #F3FFE1 #DAFAF3 #EAEAEF 默认  

pic单片机软件解码PT2240

[日期:2008-05-12 ] [来源:net 作者:佚名] [字体: (投递新闻)

1:单片机软件解码PT2240
2:选用PIC16F877A作为软件解码芯片
3:单片机时钟频率选用外部4MHZ晶振
4:选用外部中断脚作为编码信号脚输入脚
5:可解PT2240芯片(8脚的学习型编码芯片 编码地址位:2的20次方 重复几率100万分之一)
6:功能有:遥控器学习(DEMO上的S9作为学习按纽) 清除记忆(长按DEMO上的S9即可清除遥控器地址的记忆)
7:学习遥控器数量可以设定(可根据EEPROM的大小 随便设定)
8:输出功能(有三路是 单击遥控器双稳,可以通过PORTC上的LED可以看到结果.还有一路是 双击遥控器双稳)
9:可选用315MHZ/433MHZ的饿超再生/超外差接收模块


/******************************************************************************/
/****************************** 遥控器接收程序 ********************************/
/******************************************************************************/
#i nclude <pic.h>
#i nclude <pic1687x.h>
#define remote_geshu 10
/******************************************************************************/
union BIT_16
{
  int TIMER1_REG;
  unsigned char REG[2];
}
union BIT_32
{
  unsigned long data_temp_long;
  unsigned char data_temp_byte[4];
}
/******************************************************************************/
static union BIT_16 TIMER1_TEMP;//16位定时器1
static union BIT_32 data_temp;
/******************************************************************************/
static volatile unsigned char rec_status @ 97;
static unsigned char data_cout;//接收的遥控器码位数
static unsigned char data;//接收的4位数据
static unsigned int h_pulse;//高电平宽度
static unsigned int l_pulse;//低电平宽度
static unsigned char remote_cout;//遥控器数量
static unsigned char remote_numb;//遥控器编号
/******************************************************************************/
static unsigned char TIMER15S1;//清除学习码按键长按时间
static unsigned char TIMER15S2;//学习等待时间
static unsigned char TIMER15S3;//遥控器数据缓冲时间
static unsigned char TIMER15S4;//LED显示时间
static unsigned char TIMER15S5;//
static unsigned char TIMER15S6;//
static unsigned char TIMER15S7;//
static unsigned char TIMER15S8;//
/******************************************************************************/
static bit head @ ((unsigned)(&rec_status)*8+(0));//同步头标志位
static bit learn @((unsigned)(&rec_status)*8+(1));//学习标志位
static bit recieved @((unsigned)(&rec_status)*8+(2));//接收完成标志位
static bit remote_button_status @((unsigned)(&rec_status)*8+(3));//遥控器按键标志位
static bit first_click_status @((unsigned)(&rec_status)*8+(4));//遥控器按键单击标志位

/******************************************************************************/
/********************************** 数据接收 **********************************/
/******************************************************************************/
unsigned char data_read(void)
{
  if(h_pulse>l_pulse)
   {
    if((l_pulse>200)&&(l_pulse<1000))
     {
      if(h_pulse<(l_pulse<<2))return 1;//数据为1
     }
    return 2;//无效的数据
   }
  else if(h_pulse<l_pulse)
   {
    if((h_pulse>200)&&(h_pulse<1000))
     {
      if(l_pulse<(h_pulse<<2))return 0;//数据为0
     }
    return 2;//无效的数据
   }
}
/******************************************************************************/
void clr_head(void)//清除寄存器
{
  data_cout=0;
  head=0;  
}
/******************************************************************************/
#pragma interrupt_level 1
void check_data(void)//检测数据是否正确
{
  if(head)
   {
    switch(data_read())
     {
      case 0:(data_temp.data_temp_long)<<=1;;data_cout++;break;
      case 1:(data_temp.data_temp_long)<<=1;(data_temp.data_temp_long)++;;data_cout++;break;
      default:clr_head();break;
     }
    if(data_cout>23)
     {
      INTE=0;
      recieved=1;
      clr_head();//
     
     }
   }
}
/******************************************************************************/
#pragma interrupt_level 1
void check_head(void)
{
  if((!head)&&(!recieved))//
   {
    if((h_pulse>300)&&(h_pulse<1000))
     {
      if((l_pulse>h_pulse*27)&&(l_pulse<h_pulse*35))
       {
        head=1;
       }
     }
   
   }
}

阅读:
录入:JETTA

推荐 】 【 打印
本文评论
      全部评论
发表评论


点评: 字数
姓名:
赞助商广告