找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4166|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)Proteus串口仿真+虛擬終端顯示 源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
晶振11.0592M,波特率9600,用了虛擬終端,打算加上  虛擬串口,嘿嘿


單片機(jī)源程序如下:
  1. #include<reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. ///共陽(yáng)數(shù)碼管 0-9 P 滅
  5. uchar code smdm[]=
  6. {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xFF}; //
  7. #define sm_dm  P0
  8. sbit Led=P3^7;
  9. sbit Key_set=P3^2;
  10. uchar code hello_world[]="Hello World ";
  11. uchar Dat_rxd;
  12. uchar work_mode=0;
  13. /******************************************************************/
  14. void DelayUs(unsigned char us)//delay us
  15. {
  16.                  unsigned char uscnt;
  17.                  uscnt=us>>1;        /*12MHz頻率*/
  18.                  while(--uscnt);
  19. }
  20. /******************************************************************/
  21. /*                    毫秒函數(shù)聲明                                */
  22. /******************************************************************/
  23. void DelayMs(unsigned int ms)
  24. {
  25. while(--ms)
  26.          {
  27.                  DelayUs(250);
  28.                  DelayUs(250);
  29.                  DelayUs(250);
  30.                  DelayUs(250);
  31.          }
  32. }

  33. //******************串口初始化函數(shù)****************************//
  34. void Com0_Init(void)
  35. {
  36. EA=1;        //開(kāi)總中斷
  37. ES=1;        //允許串口中斷
  38. TMOD=0x20;   //定時(shí)器T1,在方式3中斷產(chǎn)生波特率
  39. SCON=0x50;   
  40. TH1=0xfd;    //波特率設(shè)置為9600(晶振12M)
  41. TL1=0xfd;
  42. TR1=1;       //開(kāi)定時(shí)器T1運(yùn)行控制位
  43. }
  44. ///////////////////////
  45. void Com0(void) interrupt 4 using 1
  46. {
  47.    if(RI)                          
  48.   {
  49.       Led=~Led;        
  50.           Dat_rxd=SBUF;                 //串口接收
  51.           Dat_rxd=Dat_rxd-0x30;
  52.           sm_dm=smdm[Dat_rxd];
  53.       RI=0;
  54.   }
  55. }
  56. void send_string(uchar *p)
  57. {
  58.     while(*p!= '\0')
  59.         {
  60.           SBUF=*p;
  61.           p++;
  62.           while(TI==0);
  63.           TI=0;
  64.         }
  65. }
  66. //////////////////////
  67. void main(void)
  68. {
  69.         ////////////
  70.         Com0_Init();
  71.     while(1)
  72.         {
  73.             if(~Key_set)
  74.                         {
  75.                         DelayMs(3);
  76.                         if(~Key_set)
  77.                            {
  78.                                  work_mode=1;                                                                                                                                                                 
  79.                              while(~Key_set);
  80.                            }        
  81.                         }
  82.                 switch(work_mode)
  83.                  {
  84.                         case 0:        break;
  85.                         case 1: Led=~Led;
  86.                                        send_string(hello_world);
  87.                                 work_mode=0;
  88.                     break;                                       
  89.                  }
  90.         }
  91. }
復(fù)制代碼

仿真代碼51hei附件下載:
仿真代碼.7z (308.84 KB, 下載次數(shù): 131)


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:1041116 發(fā)表于 2023-6-14 13:30 | 只看該作者
請(qǐng)問(wèn),protues串口能發(fā)送浮點(diǎn)型小數(shù)嗎
回復(fù)

使用道具 舉報(bào)

板凳
ID:161164 發(fā)表于 2023-6-14 14:59 | 只看該作者
Cgy030139 發(fā)表于 2023-6-14 13:30
請(qǐng)問(wèn),protues串口能發(fā)送浮點(diǎn)型小數(shù)嗎

不能
只能單字節(jié)發(fā)送
回復(fù)

使用道具 舉報(bào)

地板
ID:1041116 發(fā)表于 2023-6-14 19:17 | 只看該作者
lkc8210 發(fā)表于 2023-6-14 14:59
不能
只能單字節(jié)發(fā)送

明白了,謝謝
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表