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

QQ登錄

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

搜索
查看: 2684|回復(fù): 1
收起左側(cè)

51單片機(jī)用鎖存器控制多個(gè)步進(jìn)電機(jī)的運(yùn)動(dòng),代碼仿真如下,可能是鎖存器程序出問(wèn)題...

[復(fù)制鏈接]
ID:372703 發(fā)表于 2018-8-7 20:43 | 顯示全部樓層 |閱讀模式

proteus

proteus


單片機(jī)源程序如下:
  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code FFW[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
  5. uchar code REW[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
  6. sbit K1=P3^0;
  7. sbit K2=P3^1;
  8. sbit K3=P3^2;
  9. sbit D40=P2^6;
  10. sbit D50=P2^7;
  11. void Delayms(uint i)
  12. {
  13. uchar j;
  14. while(i--)
  15. {
  16. for(j=0;j<115;j++)
  17. {
  18. ;
  19. }
  20. }
  21. }
  22. void setp_motor1_ffw(uchar n)//設(shè)置轉(zhuǎn)動(dòng)的圈數(shù)
  23. {
  24. uchar i,j;
  25. for(i=0;i<5*n;i++)//一個(gè)八拍72度,旋轉(zhuǎn)一圈要5個(gè)八拍
  26. {
  27. for (j=0;j<8;j++)
  28. {
  29. if(K3==0)break;
  30. P1=FFW[j];
  31. Delayms(100);//兩個(gè)脈沖之間的長(zhǎng)短,用來(lái)改變電機(jī)的轉(zhuǎn)速
  32. }
  33. }
  34. }
  35. void setp_motor2_ffw(uchar n)//設(shè)置轉(zhuǎn)動(dòng)的圈數(shù)
  36. {
  37. uchar i,j;
  38. for(i=0;i<5*n;i++)//一個(gè)八拍72度,旋轉(zhuǎn)一圈要5個(gè)八拍
  39. {
  40. for (j=0;j<8;j++)
  41. {
  42. if(K3==0)break;
  43. P1=FFW[j];
  44. Delayms(100);//兩個(gè)脈沖之間的長(zhǎng)短,用來(lái)改變電機(jī)的轉(zhuǎn)速
  45. }
  46. }
  47. }
  48. void setp_motor1_rew(uchar n)
  49. {
  50. uchar i,j;
  51. for(i=0;i<5*n;i++)
  52. {
  53. for (j=0;j<8;j++)
  54. {
  55. if(K3==0)break;
  56. P1=REW[j];
  57. Delayms(50);
  58. }
  59. }
  60. }
  61. void setp_motor2_rew(uchar n)
  62. {
  63. uchar i,j;
  64. for(i=0;i<5*n;i++)
  65. {
  66. for (j=0;j<8;j++)
  67. {
  68. if(K3==0)break;
  69. P1=REW[j];
  70. Delayms(50);
  71. }
  72. }
  73. }
  74. void main()
  75. {
  76. uchar n=5;
  77. while(1)
  78. {
  79. if(K1==0)
  80. {
  81. D40=1;
  82. setp_motor1_ffw(n);
  83. D40=0;
  84. D50=1;
  85. P0=0x00;
  86. setp_motor2_rew(n);
  87. D50=0;
  88. }
  89. else if(K2==0)
  90. {
  91. D40=1;
  92. setp_motor1_rew(n);
  93. D40=0;
  94. D50=1;
  95. P0=0x00;
  96. setp_motor2_ffw(n);
  97. D50=0;
  98. }
  99. else
  100. {
  101. P1=0x00;
  102. }
  103. }
  104. }

復(fù)制代碼



回復(fù)

使用道具 舉報(bào)

ID:1012634 發(fā)表于 2022-4-6 16:51 | 顯示全部樓層
請(qǐng)問(wèn) 有沒(méi)有控制8個(gè)步進(jìn)電機(jī)的  有沒(méi)有原理圖 能不能分享給大家  非常感謝
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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