標(biāo)題: 單片機(jī)之間雙向通信Proteus仿真程序 [打印本頁]

作者: dong12    時間: 2020-5-11 10:52
標(biāo)題: 單片機(jī)之間雙向通信Proteus仿真程序


單片機(jī)源程序如下:
  1. /***************   writer:shopping.w   ******************/
  2. #include <reg52.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. sbit LED1 = P1^0;
  6. sbit LED2 = P1^3;
  7. sbit K1 = P1^7;
  8. uchar Operation_NO = 0;
  9. uchar code DSY_CODE[]=
  10. {
  11.         0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
  12. };

  13. void Delay(uint x)
  14. {
  15.         uchar i;
  16.         while(x--)
  17.         {
  18.                  for(i=0;i<120;i++);
  19.         }
  20. }

  21. void putc_to_SerialPort(uchar c)
  22. {
  23.         SBUF = c;
  24.         while(TI == 0);
  25.         TI = 0;
  26. }

  27. void main()
  28. {
  29.         LED1=LED2=1;
  30.         P0 = 0x00;
  31.         SCON = 0x50;
  32.         TMOD = 0x20;
  33.         PCON = 0x00;
  34.         TH1  = 0xfd;
  35.         TL1  = 0xfd;
  36.         TI   = 0;
  37.         RI   = 0;
  38.         TR1  = 1;
  39.         IE   = 0x90;
  40.         while(1)
  41.         {
  42.                  Delay(100);
  43.                 if(K1 == 0)
  44.                 {
  45.                          while(K1==0);
  46.                         Operation_NO=(Operation_NO+1)%4;
  47.                         switch(Operation_NO)
  48.                         {
  49.                                  case 0:
  50.                                                 putc_to_SerialPort('X');
  51.                                                 LED1=LED2=1; break;
  52.                                 case 1:
  53.                                                 putc_to_SerialPort('A');
  54.                                                 LED1=0;LED2=1;break;
  55.                                 case 2:
  56.                                                 putc_to_SerialPort('B');
  57.                                                 LED2=0;LED1=1;break;
  58.                                 case 3:
  59.                                                 putc_to_SerialPort('C');
  60.                                                 LED1=0;LED2=0;break;
  61.                         }
  62.                 }
  63.         }
  64. }

  65. void Serial_INT() interrupt 4
  66. {
  67.         if(RI)
  68.         {
  69.                  RI = 0;
  70.                 if(SBUF>=0&&SBUF<=9)
  71.                         P0 = DSY_CODE[SBUF];
  72.                 else
  73.                         P0 = 0x00;
  74.         }
  75. }
復(fù)制代碼

所有資料51hei提供下載:
單片機(jī)之間雙向通信.zip (85.59 KB, 下載次數(shù): 22)



作者: dong12    時間: 2020-5-14 10:43
不錯的資料
作者: xiaodong11    時間: 2020-5-14 11:01
加油,資料很好




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1