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

QQ登錄

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

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

51單片機(jī)PWM直流電機(jī)測(cè)速proteus仿真加源代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
51單片機(jī)PWM直流電機(jī)測(cè)速的仿真原理圖如下:


單片機(jī)源代碼:
  1. #include <reg51.h>
  2. #include <math.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. #define ON 0
  6. #define OFF 1
  7. sbit PWM=P3^5;
  8. sbit MP=P3^4;
  9. bit FLAG=0;
  10. uchar code dispbit[6]=
  11. {
  12.     0x20,0x10,0x08,0x04,0x02,0x01
  13. }
  14. ;

  15. uchar code seg[]=
  16. {
  17.     0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90
  18. }
  19. ;
  20. //0,1,2,3,4,5,6,7,8,9
  21. uchar disbuf[6]=
  22. {
  23.     0,0,0,0,10,10
  24. }
  25. ;
  26. uint temp[6];
  27. uint discount=0;
  28. uint timecount=0;
  29. //定時(shí)的次數(shù)
  30. uint T0count=0;
  31. uint hus=0;
  32. uint k=60;
  33. uint Vc;
  34. uint Vs;
  35. uint tm=3000;
  36. uint x;
  37. void t0_serv()interrupt 1
  38. {
  39.     T0count++;
  40. }
  41. void t1_serv()interrupt 3
  42. {
  43.     PWM=1;
  44.     TH1=(65536-tm)/256;
  45.     TL1=(65536-tm)%256;
  46.     hus++;
  47.     if(hus==tm)
  48.     {
  49.         PWM=0;
  50.         TH1=(25536+tm)/256;
  51.         TL1=(25536+tm)%256;
  52.         
  53.     }
  54.     timecount++;
  55.     if(timecount==250)
  56.     {
  57.         //FLAG=1;
  58.         TR0=0;
  59.         hus=0;
  60.         timecount=0;
  61.         Vc=T0count*65536+TH0*256+TL0;
  62.         Vs=144;
  63.         if(abs(Vc-Vs)>5)
  64.         {
  65.             tm=abs(k*(Vc-Vs));
  66.             T0count=0;
  67.             TR0=1;
  68.             TR1=1;
  69.             ET0=1;
  70.             ET1=1;
  71.             EA=1;
  72.         }
  73.         FLAG=1;
  74.         TR0=0;
  75.         timecount=0;
  76.     }
  77.     P0=dispbit[discount];
  78.     P1=seg[disbuf[discount]];
  79.     discount++;
  80.     if(discount==6)
  81.     {
  82.         discount=0;
  83.     }
  84. }
  85. void main()
  86. {
  87.     uint i;
  88.     TMOD=0x15;
  89.     TH0=0;
  90.     TL0=0;
  91.     TH1=(65536-tm)/256;
  92.     TL1=(65536-tm)%256;
  93.     TR0=1;
  94.     TR1=1;
  95.     ET0=1;
  96.     ET1=1;
  97.     EA=1;
  98.     while(1)
  99.     {
  100.         if(FLAG==1)
  101.         {
  102.             FLAG=0;
  103.             x=T0count*65536+TH0*256+TL0;
  104.             for(i=0;i<6;i++)
  105.             {
  106.                 temp[i]=0;
  107.             }
  108.             i=0;
  109.             while(x/10)
  110.             {
  111.                 temp[i]=x%10;
  112.                 x=x/10;
  113.                 i++;
  114.             }
  115.             temp[i]=x;
  116.             for(i=0;i<6;i++)
  117.             {
  118.                 disbuf[i]=temp[i];
  119.             }
  120.             
  121.             timecount=0;
  122.             T0count=0;
  123.             TH0=0;
  124.             TL0=0;
  125.             T0count=0;
  126.             TR0=1;
  127.             
  128.         }
  129.     }
  130.    
  131. }
復(fù)制代碼


下載:
C51直流電機(jī)PWM測(cè)速源程序.rar (26.37 KB, 下載次數(shù): 150)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:200424 發(fā)表于 2017-5-13 21:10 | 只看該作者
為啥我運(yùn)行不成功呢

評(píng)分

參與人數(shù) 1黑幣 +5 收起 理由
y1125024414 + 5 贊一個(gè)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

板凳
ID:1023888 發(fā)表于 2022-5-4 22:29 | 只看該作者
Q清嘻嘻 發(fā)表于 2017-5-13 21:10
**** 作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽 ****

我也嘗試了一下
回復(fù)

使用道具 舉報(bào)

地板
ID:541750 發(fā)表于 2024-9-12 21:21 | 只看該作者
有成功的嗎
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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