#include 〈AT89X51
h> static unsigned int count; //计数static int step_index; //步进索引数,值为 0-7static bit turn; //步进电机转动方向static bit stop_flag; //步进电机停止标志static int speedlevel; //步进电机转速参数,数值越大速度越慢,最小值为 1,速度最快static int spcount; //步进电机转速参数计数void delay(unsigned int endcount); //延时函数,延时为 endcount*0
5 毫秒void gorun(); //步进电机控制步进函数void main(void) { count = 0; step_index = 0; spcount = 0; stop_flag = 0; P1_0 = 0; P1_1 = 0; P1_2 = 0; P1_3 = 0; EA = 1; //允许 CPU 中断 TMOD = 0x11; //设定时器 0 和 1 为 16 位模式 1 ET0 = 1; //定时器 0 中断允许 TH0 = 0xFE; TL0 = 0x0C; //设定时每隔 0
5ms 中断一次 TR0 = 1; //开始计数 turn = 0; speedlevel = 2; delay(10000); speedlevel = 1; do{ speedlevel = 2; delay(10000); speedlevel = 1; delay(10000); stop_flag=1; delay(10000); stop_flag=0; }while(1);} //定时器 0 中断处理 void timeint(void) interrupt 1 { TH0=0xFE;