標(biāo)題: 用Proteus仿真H橋+直流伺服電機(jī) 附詳細(xì)文檔+源程序 [打印本頁]

作者: jjjffff    時(shí)間: 2019-12-13 20:42
標(biāo)題: 用Proteus仿真H橋+直流伺服電機(jī) 附詳細(xì)文檔+源程序
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. /*******************************************************************************
  2. * 文 件 名       : main.c
  3. * 函數(shù)功能                 : LCD 顯示控制|中斷初始化|主程序
  4. *******************************************************************************/


  5. #include <reg52.h>
  6. #include "stdio.h"
  7. #include "lcd.h"
  8. #include "key.h"

  9. sbit motor_en1=P2^4;                 //電機(jī)方向控制引腳
  10. sbit motor_en2=P2^5;
  11. sbit motor_en=P2^0;

  12. sbit Led_start=P2^2;
  13. sbit Led_stop=P2^1;

  14. double speed=0;
  15. uint state=0;                                 //電機(jī)狀態(tài)
  16. uint dirt=0;                                //運(yùn)行方向


  17. sbit temp=P0^7;

  18. void init()
  19. {
  20.         TMOD=0x51;
  21.         TH0=(65536-1000)/256;                        //定時(shí)1ms
  22.         TL0=(65536-1000)%256;                        //低8位
  23.         TH1=0;
  24.         TL1=0;
  25.         EA=1;                                                   //總中斷開啟
  26.         ET0=1;
  27.         TR1=1;                                                         //計(jì)數(shù)
  28.         TR0=1;

  29.           Led_start=0;
  30.           Led_stop=0;
  31.           motor_en=0;
  32. }

  33. void main ()
  34. {
  35.         uchar str[9];
  36.         init();
  37.         lcd_init();                                //LCD初始化


  38.         
  39.         while(1)
  40.         {
  41.                 sprintf((char*)str,"%.1frpm",speed);
  42.                 write_com(0x80+0x06);
  43.                 write_string(str);
  44.                 write_com(0x80+0x40+10);
  45.                 if(dirt)
  46.                 {
  47.                         write_data('+');
  48.                 }
  49.                 else
  50.                 {
  51.                         write_data('-');
  52.                 }



  53.                 key_judge();
  54.                 motor_control();
  55.                
  56.                
  57.         }

  58. }
復(fù)制代碼


所有資料51hei提供下載:
控制電機(jī)第十組(1).rar (395.64 KB, 下載次數(shù): 272)


作者: yamboo    時(shí)間: 2024-4-25 13:06
這個(gè)電機(jī)不是用的伺服電機(jī)吧

作者: donglw    時(shí)間: 2024-4-26 09:38
可以使用直流電機(jī)。
作者: 51heiartist    時(shí)間: 2024-7-20 15:06
感謝,幫到我了!
作者: Tonghao666    時(shí)間: 2024-8-9 14:45
很不錯(cuò),代碼寫的很直觀,學(xué)到東西了




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