这个程序使用89S51输出信号来驱动一个步进马达/*
Target:89S51
程序描绘:这个程序使用89S51输出信号来驱动一个步进马达*/
/* ***************************************************** */
#include
#define TIMER0_COUNT 0xEE11/*10000h-((12,000,000/(12*FREQ))*/
#define STOP 0
#define FORWARD 1
#define BACKWARD 2
char gotkey();
co
co
unsigned char timer0_tick=0,i=0,times=100,status=1;
static void timer0_isr(void) interrupt TF0_VECTOR using 1
{
TR0=0;
TL0=(TIMER0_COUNT & 0x00FF);
TH0=(TIMER0_COUNT >> 8);
TR0=1;
timer0_tick++;
if (timer0_tick==times) {
i++;
if(i==4) i=0;
timer0_tick=0;
if (status==FORWARD) P1=forward[i];
if (status==BACKWARD) P1=backward[i];
}
}
static void timer0_initialize(void)
{
EA=0;
timer0_tick=0;
TR0=0;
TMOD=0x01;
TL0=(TIMER0_COUNT & 0x00FF);
TH0=(TIMER0_COUNT >> 8);
PT0=0;
ET0=1;
TR0=1;
EA=1;
}
void main (void) {
char command;
timer0_initialize();
do {
command=gotkey();
if(command==15) status=FORWARD; //按下F键
if(command==11) status=BACKWARD; //按下B键
if(command==12) status=STOP; //按下C键
if((command==10) && (times>1)) times=times/2;
//按下A键
if(command==13) times=times*2; //按下D键
} while (1); /* 无量循环 */
}