89S51輸出信號來驅動一個步進馬達c程序
Target:89S51
本文引用地址:http://butianyuan.cn/article/201611/315591.htm程序描述:這個程序利用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); /* 無窮循環(huán) */
}
評論