色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 甲機(jī)通過(guò)串口控制乙機(jī)LED閃爍

          甲機(jī)通過(guò)串口控制乙機(jī)LED閃爍

          作者: 時(shí)間:2016-11-17 來(lái)源:網(wǎng)絡(luò) 收藏
          C代碼

          乙機(jī)程序:

          本文引用地址:http://cafeforensic.com/article/201611/315533.htm

          /*************** writer:shopping.w ******************/
          #include
          #define uint unsigned int
          #define uchar unsigned char
          sbit LED1 = P0^0;
          sbit LED2 = P0^3;

          void Delay(uint x)
          {
          uchar i;
          while(x--)
          {
          for(i=0;i<120;i++);
          }
          }

          void main()
          {
          SCON = 0x50;
          TMOD = 0x20;
          TH1 = 0xfd;
          TL1 = 0xfd;
          PCON = 0x00;
          RI = 0;
          TR1 = 1;
          LED1 = LED2 =1;
          while(1)
          {
          if(RI)
          {
          RI = 0;
          switch(SBUF)
          {
          case A: LED1=~LED1;LED2=1;break;
          case B: LED2=~LED2;LED1=1;break;
          case C: LED1=~LED1;LED2=LED1;
          }
          }
          else
          LED1=LED2=1;
          Delay(100);
          }
          }

          甲機(jī)程序:

          /*************** writer:shopping.w ******************/
          #include
          #define uint unsigned int
          #define uchar unsigned char
          sbit LED1 = P0^0;
          sbit LED2 = P0^3;
          sbit K1 = P1^0;

          void Delay(uint x)
          {
          uchar i;
          while(x--)
          {
          for(i=0;i<120;i++);
          }
          }

          void putc_to_SerialPort(uchar c)
          {
          SBUF = c;
          while(TI == 0);
          TI = 0;
          }

          void main()
          {
          uchar Operation_NO = 0;
          SCON = 0x40;
          TMOD = 0x20;
          PCON = 0x00;
          TH1 = 0xfd;
          TL1 = 0xfd;
          TI = 0;
          TR1 = 1;
          while(1)
          {
          if(K1 == 0)
          {
          while(K1==0);
          Operation_NO=(Operation_NO+1)%4;
          }
          switch(Operation_NO)
          {
          case 0:
          LED1=LED2=1; break;
          case 1:
          putc_to_SerialPort(A);
          LED1=~LED1;LED2=1;break;
          case 2:
          putc_to_SerialPort(B);
          LED2=~LED2;LED1=1;break;
          case 3:
          putc_to_SerialPort(C);
          LED1=~LED1;LED2=LED1;break;
          }
          Delay(10);
          }



          關(guān)鍵詞: 串口控制LED閃

          評(píng)論


          技術(shù)專(zhuān)區(qū)

          關(guān)閉