Infrared remote control program writing code based on 51 single chip microcomputer

Publisher:nu23Latest update time:2015-07-08 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#define uchar unsigned char
#define uint unsigned int
unsigned char code smg_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
unsigned char code smg_we[]={0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78};
fly away;
flying startflag;
volatile irdata[33];
flying bitnum;
flying irreceok;
fly ircode[4];
flying irprosok;
float disp[8];
//************************************************
//Delay function, at 12MHz crystal frequency
//About 50us delay
//************************************************
void delay_50us(uint t)
{
 flying j;
 for(;t>0;t--)
        for(j=19;j>0;j--);
}
//************************************************
//Delay function, at 12MHz crystal frequency
//About 50ms delay
//************************************************
void delay_50ms(uint t)
{
 uint j;
 for(;t>0;t--)
 for(j=6245;j>0;j--);
}
void timer0init(void)
{
 TMOD=0x02;
 TH0=0x00;
 TL0=0x00;
 ET0=1;
 EA=1;
 TR0=1;
}
void int0init(void)
{
 IT0=1;
 EX0=1;
 EA=1;
}
void irwork(void)
{
 disp[0]=ircode[0]/16;
 disp[1]=ircode[0]%16;
 disp[2]=ircode[1]/16;
 disp[3]=ircode[1]%16;
 disp[4]=ircode[2]/16;
 disp[5]=ircode[2]%16;
 disp[6]=ircode[3]/16;
 disp[7]=ircode[3]%16;
  
}
void display(void)
{
 flying i;
 for(i=0;i<8;i++)
 {
  P1=smg_du[disp[i]];
  P2=smg_we[i];
  delay_50us(20);
 }
}
void irpros(void)  //0x1c
{
 flying k,i,j;
 uchar value;
 k=1;
 for(j=0;j<4;j++)
 {
  for(i=0;i<8;i++)
  {
   value=value>>1;   //7
   if(irdata[k]>6)   //8
   {
    value=value | 0x80;
   }
   k++;
  }
  ircode[j]=value;
 }
 irprosoks=1;
}
void main()
{
 timer0init();
 int0init();
 while(1)
 {
  if(irreceok)
  {
   irpros();
   irreceok=0;
  }
  if(irprosok)
  {
   irwork();
   irprosok=0;
  }
  display();
  
 }
 
 
}
void timer0 () interrupt 1
{
 irtime++; //255
}
void int0 () interrupt 0
{
 if(start flag)
 {
  if(irtime>32) //Detect boot code
  {
    bit=0;
  }
  irdata[bitnum]=irtime;
  irtime=0;
  the bite++;
  if(bitnum==33)
  {
   bit=0;
   irreceok=1;
  }
 }
 else
 {
  start flag=1;
  irtime=0;
 }
}
Reference address:Infrared remote control program writing code based on 51 single chip microcomputer

Previous article:PROTUS simulation 51 single chip microcomputer frequency measurement program
Next article:Based on C8051f020 Wu Weibiao animation LCD control display

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号