標題: 單片機+步進電機旋轉(zhuǎn)角度在數(shù)碼管顯示 [打印本頁]

作者: kongqi    時間: 2020-10-12 00:13
標題: 單片機+步進電機旋轉(zhuǎn)角度在數(shù)碼管顯示
/********************************************************************
* 文件名  :  步進電機.c
* 描述    :  用單片機驅(qū)動ULN2003去控制步進電機。
                         數(shù)碼管旋轉(zhuǎn)的角度會在數(shù)碼管上進行顯示。                        
* 創(chuàng)建人  : 東流,2012年2月8日
* 版本號  : 1.0
* 杜邦線接法:
P1.3用杜邦線連接到J17的D端。
P1.4用杜邦線連接到J17的C端。
P1.5用杜邦線連接到J17的B端。
P1.6用杜邦線連接到J17的A端。
步進電機接到J18的五個端口,其中,步進電機的紅線接J18的VCC端。
***********************************************************************/
#include <reg52.h>
#define uchar unsigned char
#define uint  unsigned int

uchar  Step = 0;
bit FB_flag = 0;

unsigned char code F_Rotation[8]={0x08,0x18,0x10,0x30,0x20,0x60,0x40,0x48};    //順時針轉(zhuǎn)表格
unsigned char code B_Rotation[8]={0x48,0x40,0x60,0x20,0x30,0x10,0x18,0x08};    //逆時針轉(zhuǎn)表格

uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code LED_W[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

/********************************************************************
* 名稱 : Delay_1ms()
* 功能 : 延時子程序,延時時間為 1ms * x
* 輸入 : x (延時一毫秒的個數(shù))
* 輸出 : 無
***********************************************************************/
void Delay(uint i)
{
        uchar x,j;
        for(j=0;j<i;j++)
        for(x=0;x<=148;x++);        
}

main()
{
         uchar i,count=0;
        uint j;
        uint k = 0;
        while(1)
        {
                for(k=0;k<512;k++)
                {
                          for(i=0;i<8;i++)               //因為有8路的控制時序
                    {
                             P1 = F_Rotation[ i];  //順時針轉(zhuǎn)動
                             Delay(2);                 //改變這個參數(shù)可以調(diào)整電機轉(zhuǎn)速
                        }
                        j=(uint)((360000/512) * k /1000);
                        P0 = table[j%10];
                        P2 = LED_W[0];
                        Delay(1);
        
                        P0 = table[j/10%10];
                        P2 = LED_W[1];
                        Delay(1);
               
                        P0 = table[j/100%10];
                        P2 = LED_W[2];
                        Delay(1);
                }
        }
}

【實驗80】步進電機旋轉(zhuǎn)角度在數(shù)碼管顯示.zip

14.64 KB, 下載次數(shù): 40, 下載積分: 黑幣 -5

步進電機旋轉(zhuǎn)角度在數(shù)碼管顯示






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