标题: 单片机与PC机串口通讯Proteus仿真程序 [打印本页]

作者: 1236222    时间: 2020-12-11 20:59
标题: 单片机与PC机串口通讯Proteus仿真程序
单片机与PC机串口通讯仿真,包含程序和仿真图


单片机源程序如下:
  1. /***************   writer:shopping.w   ******************/
  2. #include <reg52.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. uchar Receive_Buffer[101];
  6. uchar Buf_Index = 0;
  7. uchar code DSY_CODE[]=
  8. {
  9.         0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00
  10. };

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

  19. void main()
  20. {
  21.         uchar i;
  22.         P0 = 0x00;
  23.         Receive_Buffer[0]=i;
  24.         SCON = 0x50;
  25.         TMOD = 0x20;
  26.         PCON = 0x00;
  27.         TH1  = 0xfd;
  28.         TL1  = 0xfd;
  29.         EA   = 1;
  30.         EX0  = 1;
  31.         IT0  = 1;
  32.         ES   = 1;
  33.         IP   = 0x01;
  34.         TR1  = 1;
  35.         while(1)
  36.         {
  37.                  for(i=0;i<100;i++)
  38.                 {
  39.                          if(Receive_Buffer[i]==-1)
  40.                                 break;
  41.                         P0 = DSY_CODE[Receive_Buffer[i]];
  42.                         Delay(200);
  43.                 }
  44.                 Delay(200);
  45.         }
  46. }

  47. void Serial_INT() interrupt 4
  48. {
  49.         uchar c;
  50.         if(RI==0)
  51.                 return;
  52.         ES = 0;
  53.         RI = 0;
  54.         c  = SBUF;
  55.         if(c>='0' && c<='9')
  56.         {
  57.                  Receive_Buffer[Buf_Index]=c-'0';
  58.                 Receive_Buffer[Buf_Index+1]=-1;
  59.                 Buf_Index = (Buf_Index+1)%100;       
  60.         }
  61.         ES = 1;
  62. }

  63. void EX_INT0() interrupt 0
  64. {
  65.         uchar *s = ("Receiving From 8051...\r\n");
  66.         uchar i = 0;
  67.         while(s[i]!='\0')
  68.         {
  69.                  SBUF = s[i];
  70.                 while(TI == 0);
  71.                 TI = 0;
  72.                 i++;
  73.         }
  74. }
复制代码

所有资料51hei提供下载:
单片机与PC机串口通讯仿真.zip (35.02 KB, 下载次数: 91)



作者: 青街古城    时间: 2021-2-8 15:29
有没有更加详细的注释呢
作者: 2676681386    时间: 2021-3-3 19:19
开启仿真啥都没有
作者: 51hei团团    时间: 2021-3-4 15:23
2676681386 发表于 2021-3-3 19:19
开启仿真啥都没有

肯定没有啊,你看这个函数void Serial_INT() interrupt 4,串口中断以后 置一才有显示,,你得向pc发送一个字符才显示
作者: wangwing    时间: 2021-12-24 17:02
仿真时,向PC发送,PC收到“D5 E2 CA C7 D3 C9 38 30 35 31 B7 A2 CB CD B5 C4 D7 D6 B7 FB B4 AE 21 0D 0A ”。从PC发送时,一次只能发一个ASCII,如41,则VT1显示“A"




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1