89S51输出信号来驱动一个步进马达c程序
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); /* 无穷循环 */
}
89S51输出信号步进马 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)