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