?? bjdj_4.c
字號(hào):
//電機(jī)轉(zhuǎn)一圈走27MM
#include <iom128v.h>
#include <iom128.h>
#include <macros.h>
#include "BIT.h"
#include "zlg7290_avr.c"
#define uint unsigned int
#define uchar unsigned char
/*********電機(jī)1控制端口************/
#define cw1 _PA1
#define hf1 _PA3
#define en1 _PA5
#define rst1 _PA7
#define clk1 _PC6
/*********電機(jī)2控制端口************/
#define cw2 _PA0
#define hf2 _PA2
#define en2 _PA4
#define rst2 _PA6
#define clk2 _PG2
//uint bjl,rev,key,set=0;
/*******************************************
函數(shù)名稱: delayus
功 能: 延時(shí)指定微秒(16M晶振)
參 數(shù): us--延時(shí)的微秒數(shù)(大約,不是很精確,MS越大越準(zhǔn)確)
返回值 : 無(wú)
/********************************************/
void delayus(uint us)
{
uint i;
us=us*5/2; //9/8是在16MHz晶振下,通過(guò)反復(fù)實(shí)驗(yàn)得到的數(shù)值
for( i=0;i<us;i++);
}
/*******************************************
函數(shù)名稱: delayms()
功 能: 16MHz晶振下延時(shí) z ms
參 數(shù): z
返回值 : 無(wú)
/********************************************/
void delayms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=2660;y>0;y--);
}
void bjdj_init1()
{
DDRA|=BIT(1)|BIT(3)|BIT(5)|BIT(7);
DDRC|=BIT(6);
cw1=1; // 0:正傳 1:反轉(zhuǎn)
en1=0; //
rst1=0;//
hf1=0;// 0:半步 1:整步
}
void bjdj_init2()
{
DDRA|=BIT(0)|BIT(2)|BIT(4)|BIT(6);
DDRG|=BIT(2);
cw2=1;//0:正傳 1:反轉(zhuǎn)
en2=0;//
rst2=0;//
hf2=0;//0:半步 1:整步
}
void main()
{
uint i,dat;
bjdj_init1();
bjdj_init2();
clk1=1;
clk2=1;
while(1)
{
clk1=1;
clk2=1;
delayms(2);
clk1=0;
clk2=0;
delayms(2);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -