STC12C5410AD learning board---infrared decoding

Publisher:平静宁静Latest update time:2016-09-06 Source: eefocusKeywords:STC12C5410AD Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
        This is the infrared decoding program for my homemade STC12C5410AD learning board. This program is for decoding the SAA3010 infrared encoder chip. If you change other chips, just modify the header file of the infrared chip.

STC12C5410AD Learning Board --- Infrared Decoding - Xiaowen - Xiaowen Electronic Design

Video demonstration address:

http://v.youku.com/v_show/id_XMTUyMzQwMjg4.html

The following are the detailed procedures:

/*****Program Author : ZhengWen(ClimberWin) *****/
/*****E_mail :   cooldianzi@163.com               *****/
/********************************************************************/
/*****File Function : IR Soft Recode(SAA3010) *****/
/*****Compile Date : 2009/2/4 *****/
/*****Edition Info : V1.0 *****/ /
*****Amend Date : *****/
/*****************************************************************/
/************Infrared software decoding, remote control model, SAA3310 chip************/
/***********************2009.2.4******************************/
/***********Can infrared decoding LCD display****************/
#include
#include "intrins.h "
#include "SAA3010_Recode.h"
#include "LCD12864.H"
#include
#include
#include
#include

#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long

sbit speaker=P2^1;
uchar LCD_IR_da ta[16]={0xbc,0xfc,0xd6,0xb5,0xce,0xaa,0x3a,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00};// The key value is: 0x00
void Delay1ms(unsigned int count);
void Key_Beep(void);
void Delay_Beep(unsigned int count1);
void init_rs232(void);

/***************************1 second delay subroutine start***************************/
void Delay1ms(unsigned int count)
{
 unsigned int i,j;
 for(i=0;i  for(j=0;j<120;j++);
}

/***************************1 second delay subroutine end***************************/

/**********************Key sound************************/
void Key_Beep(void)
{ uchar i;
     for (i=0;i<250;i++)
     { speaker=1;
      Delay_Beep(30);

      speaker=0;

      Delay_Beep(30);
      }
   speaker=1;
}

/****************************************************** */

/***************************Buzzer delay subroutine start**********************/
void Delay_Beep(unsigned int count)
{
 unsigned int i,j;
 for(i=0;i  for(j=0;j<10;j++);
}
/***************************Buzzer delay subroutine end************************/
/* Serial communication initialization settings*/
void init_rs232(void)
 {
 AUXR=74; //Set the baud rate to 12 times of ordinary 51, and allow AD interrupt
 SCON=0x50;
 PCON=0x00;
 TH1=0xFA; //Baud rate 115200 22.1184MHZ (F4 4800 FA 9600 FDH 9600)*12
 TL1=0XFA;
 TMOD=0X20;
 TR1=1;    
 }


void main(void)
{
uchar key_co de_b; //Infrared remote control key value hundreds digit
uchar key_co de_s; //Infrared remote control key value tens digit
uchar key_co de_g; //Infrared remote control key value units digit
 Delay1ms(1000);
 init_rs232();
 TI=1;
 printf("STC12C5410AD learning board infrared remote control decoding\n");
 printf("ClimberWin 2009.2.4\n\n");
 Delay1ms(5000);

  LCD_INIT();
  Delay1ms(1000);
  LCD_LOCAL(1,1,"STC MCU Learning Board");
  LCD_LOCAL(2,1,"MCU:STC12C5410AD");
  LCD_LOCAL(4,1,"Date:2009.2.4 ");
  LCD_LOCAL(3,1,"By ClimberWin ");
/********************************************/
  Delay1ms(50000);
  LCD_LOCAL(1,1,"Infrared remote control test interface");
  LCD_LOCAL(2,1,"Remote control chip:SAA3010");
  LCD_LOCAL(3,1,"Test result: ");
  LCD_LOCAL(4,1," ");
  printf("Infrared remote control test interface\n"); 
    //Delay100us(8); // Actually 760uS
 Key_Beep();
    IR_Input = 1; //Pull the signal line high first, waiting for receiving infrared signalwhile
    (1)
    {
     LCD_IR_data [7]=0x30; //Initial value setting display 000
  LCD_IR_data [8]=0x30;
  LCD_IR_data [9]=0x30;
     if(!IR_Input) SAA3010_Recode();
     if(SAA3010_CODE [0]==0x03)
     {Key_Beep();
  SBUF=SAA3010_CODE [3]; //Send decoded value to serial
  portkey_code_b =SAA3010_CODE [3]/100; //Express the key value in decimalkey_code_s
     = (SAA3010_CODE [3]%100)/10;
     key_code_g =(SAA3010_CODE [3]%100)%10;
     LCD_IR_data ta[7]=LCD_IR_da ta[7]+key_co de_b;
  LCD_IR_da ta[8]=LCD_IR_da ta[8]+key_co de_s;
  LCD_IR_da ta[9]=LCD_IR_da ta[9]+key_co de_g;
  LCD_LOCAL(4,1,LCD_IR_da ta);//Display the decoded data on the LCD
  SAA3010_CO DE [0]=0x00;
  SAA3010_CO DE[1]=0x00;
  SAA3010_CO DE[2]=0x00;
  SAA3010_CO DE[3]=0x00;
  }
     else
     {SAA3010_CO DE[0]=0x00;}
    }
}

LCD12864.H is as follows:

/*****Program Author : ZhengWen(ClimberWin) *****/
/*****E_mail :   cooldianzi@163.com                        *****/
/****************************************************************/
/*****File Function : LCD12864 Display Module *****/
/*****Compile Date : 2009/1/28 *****/
/*****Edition Info : V1.0 *****/
/*****Amend Date : *****/
/*********************************************************************/
#ifndef __LCD12864__
#define __LCD12864__         
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit LCD_CS = P1^7; //Chip select high level is valid when single-chip LCD is used, high level rs can be fixed
sbit LCD_SID = P1^6; //data r/w
sbit LCD_SCLK = P1^5; //clock e

/************************LCD12864******************************/
void LCD_SEND(uchar date);
void LCD_SCOM(bit st,uchar date);
void LCD_DELAY(void);
void LCD_INIT(void);
void LCD_write(uchar *p);
void LCD_LOCAL(uchar x,uchar y,uchar *p);  
void LCD_cblank(uchar x,uchar y);
void LCD_count(long s,uchar x1,uchar y1,uchar x,uchar y,uchar *p);
void DELAYLCD(uchar t);
/********* ************************************************/
/**** ************************lcd12864****************************** ***********/
void DELAYLCD(uchar t)
 {
   while(--t);
  }

void LCD_SEND(uchar date)
 {
      uchar i;
      LCD_SCLK=0;
      for(i=0;i<8;i++)
         {
           LCD_SID=date&0x80;
           LCD_SCLK=1;
           LCD_SCLK=0;
           date<<=1;
         }
  }
void LCD_SCOM( bit st,uchar date)
 {
         uchar st_temp,hdate,ldate;
         if(st)
              st_temp=0xfa;
         else st_temp=0xf8;
         hdate=date&0xf0;
         ldate=date&0x0f;
         ldate <<= 4;
         LCD_CS = 1;
         LCD_SEND(st_temp);
         LCD_SEND(hdate);
         LCD_SEND(ldate);
         LCD_CS = 0;
         DELAYLCD(38);
 }
 void LCD_DELAY(void)
  { uchar s;
    s=10;
    while(--s)
   DELAYLCD(250);
   }
 void LCD_INIT(void)
  {
    LCD_SCOM(0,0x30);
    LCD_DELAY();
    LCD_SCOM(0,0x0c);
    LCD_DELAY();
    LCD_SCOM(0,0x01); //Clear the screen and reset the DDRAM address counter to zero
    LCD_DELAY();
  }
 void LCD_write(uchar *p)
  {
    while(*p)
     {
      LCD_SCOM(1,*p);
      p++;
     }
  }
  void LCD_LOCAL(uchar x,uchar y,uchar *p) //lcd string (x,y) write !
  {
   switch (x)
   {
    case 1:LCD_SCOM(0,0x7f+y); LCD_write(p);break;
    case 2:LCD_SCOM(0,0x8f+y); LCD_write(p);break;
    case 3:LCD_SCOM( 0,0x87+y); LCD_write(p);break;
    case 4:LCD_SCOM(0,0x97+y); LCD_write(p);break;
    default :LCD_SCOM(0,0x7f+y); LCD_write(p);
   }
  }
  void LCD_cblank(uchar x,uchar y)
  {
     switch (x)
      {
       case 1:LCD_SCOM(0,0x7f+y); LCD_SCOM(0,0x0d);break;
       case 2:LCD_SCOM(0,0x8f+y); LCD_SCOM(0,0x0d);break;
       case 3:LCD_SCOM(0, 0x87+y); LCD_SCOM(0,0x0d);break;
       case 4:LCD_SCOM(0,0x97+y); LCD_SCOM(0,0x0d);break;
       default :LCD_SCOM(0,0x7f+y); LCD_SCOM(0, 0x0d);
      }
  }

/****************************************************** *************************/

/****************************************************** ****************************/
#endif

SAA3010_Rncode.H is as follows:

/*****Program Author : ZhengWen(ClimberWin) *****/
/*****E_mail :   cooldianzi@163.com                       *****/
/********************************************************************/
/*****File Function : SAA3010 IR_Input soft recode *****/
/*****Compile Date : 2009/2/4 *****/
/*****Edition Info : V1.0 *****/
/*****Amend Date : *****/
/*****************************************************************/
/***************Software decoding of infrared remote control SAA3010*******************/
#ifndef __SAA3010_Rncode__
#define __SAA3010_Rncode__
#define uchar unsigned char
#include
sbit IR_Input=P3^4;
uchar SAA3010_CODE DE[4];

void SAA3010_Recode(void);
void Delay100us(uchar i);

/*************SAA3010 decoding program**************/
void SAA3010_Recode(void)
{
    unsigned char i, j;
    bit FBIT;
    // IR_Input changes from high to low, skip the first sampling
    for (i=0; i<4; i++)
    {
        SAA3010_CO DE[i] =0x00;
    }
    /*--------------------------------------
        Manchester code:
        input binary code Manchester code
            0 01
            1 10
    ********************************************/
    // Set as the second sampling, sampling time interval 800uS
    Delay100us(8);

    if (!IR_Input)
    {
        // Because the start bit of SAA3010 is 1
        SAA3010_CO DE[0] |=0x01;
        SAA3010_CO DE[0] <<= 1;
        // Start the second bit and sample once
        Delay100us(8);
        if (IR_Input)
        { // The sample is 1
            SAA3010_CO DE[0] |=0x01;
            FBIT = 1;
        }
        else
        { // The sample is 0
            FBIT = 0;
        }
        if (FBIT)
        { // If the first sample is 1
            while (IR_Input); 
        }
        else
        {
            while (!IR_Input); 
        }
        // Second sampling
        Delay100us(8);
        //----------------------------------------------------------------------------
        // Sampling control bit
        // One sampling
        Delay100us(8);
        if (IR_Input)
        {
            SAA3010_CO DE[1] |=0x01;
            FBIT = 1;
        }
        else
        {
            FBIT = 0;
        }

        if (FBIT)
        {
            while (IR_Input);
        }
        else
        {
            while (!IR_Input); // Wait for IR_Input to rise
        }
        // Second sampling
        Delay100us(8);
//----------------------------------------------------------------------------------
        // Collect system code (5 bits)
        for (j=0; j<5; j++)
        {
            // First sampling
            Delay100us(8);
            if (IR_Input)
            {
                SAA3010_CO DE[2] |=0x01;
                FBIT = 1;
            }
            else
            {
                FBIT = 0;
            }

            if (FBIT)
            {
                while (IR_Input);
            }
            else
            {
                while (!IR_Input);
            }
            // Second sampling
            Delay100us(8);
            SAA3010_CO DE[2] <<= 1;
        }

//------------------------------------------------ --------------------------

        // Collect data code (6 bits)
        for (j=0; j<6; j++)
        {
            // One sampling
            Delay100us(8);
            if (IR_Input)
            {
                SAA3010_CODE [3] |=0x01;
                FBIT = 1;
            }
            else
            {
                FBIT = 0;
            }

            if (FBIT)
            {
                while (IR_Input);
            }
            else
            {
                while (!IR_Input);
            }
            // Second sampling
            Delay100us(8);
            SAA3010_CO DE[3] <<= 1;
        }
//-----------------------------------------------------------------------------
    }
    else
    { // It is jitter
        for (i=0; i<4; i++)
        {
            SAA3010_CO DE[i] =0x00;
        }

        return;
    }

    SAA3010_CO DE[3]>>= 1;//09.2.4
}

/************760us delay program************************/
void Delay100us(uchar i)
{
  uchar j;
    while(i<50)//50
    {
    for(j=0;j<50;j++)
    { _nop_();} 
    i++;
    }
}

/****************************************************** *****/
#endif

Keywords:STC12C5410AD Reference address:STC12C5410AD learning board---infrared decoding

Previous article:STC12C5410AD learning board --- serial communication
Next article:STM8S103 Unique ID Reader

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号