12T single-chip microcomputer sending infrared level sample program

Source: Internet
Author: User
Tags set time

GND of the single-chip microcomputer is connected to the infrared receiving head

TTL output pin of the IO Infrared receiver Head of MCU

/*89c52 @12m */#include  <reg51.h> sfr auxr  = 0x8e; static  bit RealOutput;                     //static unsigned int count;    of infrared emitter tube      //Delay Counter static unsigned int endcount;      //terminating delay Count static unsigned char flag;        // Infrared Send flag sbit send_isr=p2^0;sbit runled  =p2^1;char iraddr1;  // The first byte of a 16-bit address char iraddr2;  //the second byte of a 16-bit address unsigned char code key_0=0x10;unsigned  char code key_1=0x11;unsigned char code key_2=0x12;unsigned char code  key_3=0x13;unsigned char code key_4=0x14;unsigned char code key_5=0x15; Unsigned char code key_6=0x16;uNsigned char code key_7=0x17;unsigned char code key_8=0x18;unsigned char  code key_9=0x19;unsigned char code key_up=0x19;unsigned char code key _down=0x19;unsigned char code key_left=0x19;unsigned char code key_right=0x19; unsigned char code key_menu=0x19;unsigned char code key_ok=0x19;unsigned  Char code key_back=0x1c; void delay (Unsigned int a) {  //[email  protected]  1ms    unsigned int i;    while  (  --a != 0 )         for  (i=0;i<=20;i++);}  void sendcode (unsigned char code) { unsigned char irdata,i; irdata= Code;              for (i=0;i<8;i++)   {     endcount=10;     flag=1;     count=0;      do{}while (Count<endcount);      if (irdata%2)  {endcount = 41;}      else{endcount=15;}      flag=0;     count=0;     do{} while (Count<endcount);     irdata=irdata>>1;  }}void  Sendirdata (Char keycode) {  char usercode1=0x11;  char usercode2=0x11;     char irdata=usercode1;  endcount=223;                 //sends a 9ms starting code,.   flag=1;  count= 0;  do{}while (Count<endcount);endcount=117;                 //send 4.5ms result codes   flag=0;  count=0;  do{}while (Count<endcount);   sendcode (USERCODE1); Sendcode (USERCODE2); Sendcode (KeyCode); Sendcode (~keycode);   endcount=100;  flag=1;  count=0;  do{}while (count <endcount);   flag=0;}        void main (void)  {  count = 0;   flag = 0;  RealOutput = 0;  Send_ISR = 0;   ea = 1;         //Allow CPU Interrupt    tmod =  0x11;    //Set timers 0 and 1 for 16-bit mode 1   et0 = 1;         //Timer 0 Interrupt Allow     th0 = 0xff;   tl0  = 0xe6;       //set time value of 0 is 38k  interrupt every 26us      tr0 = 1;          //OpenStart Count  while (1) {      sendirdata (KEY_0);       Delay (      sendirdata);       delay (key_1); (//runled=!); Runled;//      delay (+);   }}  void timeint (void)  interrupt 1 {   th0=0xff;   tl0=0xe6; //Set Value is 38k  That is, every 26us interrupt once   count++;//  if  (flag)  {realoutput=~realoutput;}   if  (flag)  {realoutput=0;}   else{realoutput = 1;}   send_isr = realoutput;}



Compile

Rebuild target ' target 1 ' assembling startup.a51...compiling SEND_ISR. C...linking ... Program size:data=17.1 xdata=0 code=337creating hex file from "Send_isr" ... "Send_isr"-0 Error (s), 0 Warning (s).


12T single-chip microcomputer sending infrared level sample program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.