|
下面程序是上電馬達(dá)轉(zhuǎn)動45度后延時10秒再轉(zhuǎn)動45度,往復(fù)循環(huán),我想在馬達(dá)停止后延時60秒,我把100000這個值改多大也不能延時60秒,請問這程序該怎么改,請各位給個提示,謝謝!
單片機源程序如下:
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uint i,j,k ;
uint N=128; //角度范圍調(diào)節(jié),對應(yīng)于45度,512對應(yīng)于360度
uchar code single_pos[4]={0x04,0x08,0x10,0x20}; /*單四拍正轉(zhuǎn)表*/
//uchar code single_rev[4]={0x20,0x10,0x08,0x04}; /*單四拍反轉(zhuǎn)表*/
void delay(uint z);
void m_single_pos();
//void m_single_rev();
void main()
{
while(1)
{
m_single_pos(); //單四拍正轉(zhuǎn)45度
delay(100000);
m_single_pos(); //單四拍正轉(zhuǎn)45度
delay(100000);
}
}
void delay(uint z) /*延時z毫秒*/
{
uint x,y;
for(x=z;x>0;x--)
for(y=300;y>0;y--) ; //轉(zhuǎn)速調(diào)節(jié),數(shù)值越大馬達(dá)越慢
}
/******************************單四拍驅(qū)動正轉(zhuǎn)(N*45/16)*************************************/
void m_single_pos()
{
for(k=0;k<N;k++)
{
for(i=0;i<4;i++) //單四拍一個脈沖轉(zhuǎn)子轉(zhuǎn)動5.625*2=11.625度,四拍共45度
{
P3=single_pos[ i] ;
delay(10) ; //適當(dāng)延時,保證轉(zhuǎn)子轉(zhuǎn)動時間,延時過短會丟拍
}
}
}
|
|