/*********************************************************** STC90C51RD+ÓëHC-06À¶ÑÀÁ¬Ïߣº À¶ÑÀ STC90C51RD+ RXD TXD TXD RXD ÆäËûÁ¬Ïߣº P2.0¡¢P2.1¡¢P2.3·Ö±ð½ÓÒ»¸öָʾµÆ £¡£¡£¡£¡ £¡£¡£¡£¡×¢Ò⣺Èôµ¥Æ¬»úTXD£¨P3.1£©ÎÞÉÏÀÄÜÁ¦£¬±ØÐëÔÚP3.1¶Ë½ÓÉÏÀµç×è¡£±¾´Î²âÊÔÐèÒª½ÓÉÏÀµç×è £¡£¡£¡£¡ ÊÖ»ú²ÉÓÃÀ¶ÑÀ´®¿ÚͨÐÅÖúÊÖ ×îºóÒѸÄÓÃAndroid×Ô±àÀ¶ÑÀͨÐÅÈí¼þ By itas109 http://blog.csdn.net/itas109 ***********************************************************/ #include <reg52.h> #include <intrins.h> unsigned char tmp; unsigned int c=0; sbit led1=P2^0; //ָʾµÆ0 sbit led2=P2^1; //ָʾµÆ1 sbit led3=P2^3; //ָʾµÆ3 void init(); //´®¿Ú³õʼ»¯ void send(unsigned char a); //µ¥×Ö½Ú·¢Ëͺ¯Êý void ctrl(); //½ÓÊÕ´¦Àíº¯Êý void main() { init(); while(1) { if(RI==1) // ÊÇ·ñÓÐÊý¾Ýµ½À´ { RI = 0; tmp = SBUF; // ÔÝ´æ½ÓÊÕµ½µÄÊý¾Ý ctrl(); } } } void init() //´®¿Ú³õʼ»¯ { ES=0; //¹ØÖÐ¶Ï SCON = 0x50; // REN=1ÔÊÐí´®ÐнÓÊÜ״̬£¬´®¿Ú¹¤×÷ģʽ1, //10λUART£¨1λÆðʼ룬8λÊý¾Ý룬1λֹͣ룬ÎÞÆæżУÑ飩£¬²¨ÌØÂʿɱä TMOD = 0x20; // ¶¨Ê±Æ÷1¹¤×÷ÓÚ·½Ê½2£¬8λ×Ô¶¯ÖØÔØģʽ, ÓÃÓÚ²úÉú²¨ÌØÂÊ TH1=TL1=0xFD; // ²¨ÌØÂÊ9600 £¨±¾´Î²âÊÔ²ÉÓþ§ÕñΪ11.0592£© PCON &= 0x7f; // ²¨ÌØÂʲ»±¶Ôö TR1 = 1; //¶¨Ê±Æ÷1¿ªÊ¼¹¤×÷£¬²úÉú²¨ÌØÂÊ //·¢Ëͱê־λÖÃ0 TI=0; //½ÓÊÕ±ê־λÖÃ0 RI=0; //EA=0; ES=1; led1=0; //³õʼ»¯ÉèÖÃ3¸öָʾµÆÈ«ÁÁ led2=0; led3=0; } void send(unsigned char a) //µ¥×Ö½ÚÊý¾Ý·¢ËÍ { //×¢Ò⣺Èôµ¥Æ¬»úTXD£¨P3.1£©ÎÞÉÏÀÄÜÁ¦£¬±ØÐëÔÚP3.1¶Ë½ÓÉÏÀµç×è¡£±¾´Î²âÊÔÐèÒª½ÓÉÏÀµç×è TI=0; SBUF=a; while(TI==0); TI=0; if(c%2) //·¢ËÍָʾµÆ±êÖ¾£¬Ã¿½ÓÊÕÒ»´Î£¬´ËµÆÁÁÃð½»Ìæ led3=1; else led3=0; c++; } void ctrl() //½ÓÊÕ´¦Àíº¯Êý { switch(tmp) { case '1': led1=1; //ÊÕµ½×Ö·û1£¬Ö¸Ê¾µÆ0Ãð send(tmp); break; case '2': //ÊÕµ½×Ö·û2£¬Ö¸Ê¾µÆ1Ãð led2=1; send(tmp); break; case '3': //ÊÕµ½×Ö·û3£¬Ö¸Ê¾µÆ0¡¢1ÁÁ led1=0; led2=0; send(tmp); break; case '4': //ÊÕµ½×Ö·û4£¬Ö¸Ê¾µÆ0¡¢1Ãð led1=1; led2=1; send(tmp); break; case '5': //ÊÕµ½×Ö·û5£¬Ö¸Ê¾µÆ3ÁÁ led3=0; send(tmp); break; default: //ÆäËû£¬µÆÈ«Ãð led1=1; led2=1; led3=1; send(tmp); } } |