標(biāo)題: 單片機uln2003按鍵控制步進(jìn)電機正反轉(zhuǎn)Proteus仿真程序 [打印本頁]

作者: Mfb971016    時間: 2020-12-9 18:20
標(biāo)題: 單片機uln2003按鍵控制步進(jìn)電機正反轉(zhuǎn)Proteus仿真程序
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機源程序如下:
  1. #include "reg51.h"
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. #define out  P2
  5. sbit pos=P0^0;
  6. sbit neg=P0^1;
  7. void delayms(uint);
  8. uchar code turn[]={0x07,0x06,0x0e,0x0c,0x0d,0x09,0x0b,0x03};
  9. uchar code turn1[]={0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};


  10. void main(void)
  11. {
  12.         uchar i;
  13.         out=0x03;
  14.         while(1)
  15.         {
  16.                 if(!pos)
  17.                 {
  18.                         //i = i < 8 ? i+1 : 0;
  19.                         if(i<8)
  20.                                 i=i+1;
  21.                         else
  22.                                 i=0;
  23.                         out=turn[i];
  24.                         delayms(1000);
  25.                 }
  26.                 else if(!neg)
  27.                 {
  28.                         i = i > 0 ? i-1 : 7;        
  29.                         out=turn[i];
  30.                         delayms(1000);
  31.                 }        
  32.         }
  33. }

  34. void delayms(uint j)
  35. {
  36.         uchar i;
  37.         for(;j>0;j--)
  38.           {
  39.                 i=250;
  40.                    while(--i);
  41.                    i=249;
  42.                    while(--i);
  43.            }
  44. }
復(fù)制代碼

所有資料51hei提供下載:
JINBU.zip (52.94 KB, 下載次數(shù): 53)






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