#include<reg52.h>
#define iniMotor() (MOTOR=0x00)
sfr MOTOR=0x90;//define the sfr MOTOR is the address of P1 port
static void iniTimer0(); //ini timer 0
static void motorDrive(unsigned char const pul,unsigned char const dir); //stepper motor drive function
int main(){
/*ini MOTOR(set P1 port to low)*/
iniMotor();
/*ini timer 0*/
iniTimer0();
/*infinite loop,wait to interrupt of T0*/
while(1);
return 0;
}
void iniTimer0(){
EA=1;
ET0=1; //open the T0 interrupt
TMOD=0x01; //use mode 1:M1M0=01
TR0=1; //run timer 0
}
void motorDrive(unsigned char const pul,unsigned char const dir){
static unsigned char count;
/*counterclockwise rotation sequential of motor:A- --> B- --> A+ --> B+
clockwise rotation sequential of motor:B+ --> A+ --> B- --> A- */