📄 ex5-5.c
字号:
#include <REGX51.H>
#define TIMER0_COUNT 0xEE11/*10000h-((12,000,000/(12*FREQ))*/
#define STOP 0
#define FORWARD 1
#define BACKWARD 2
char gotkey(); //声明函数
code forward[8]={0xfe,0xfc,0xfd,0xf9,0xfb,0xf3,0xf7,0xf6};//{0XFE,0XFD,0XFB,0X07};
//提高转速旋转度步进角度。
unsigned char timer0_tick=0,i=0,times=40,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)
{
timer0_tick=0;
i++;
if(i==8) i=0;
if (status==FORWARD)
P2=forward[i];
if (status==BACKWARD)
{
P2=forward[7-i];//反转时逆向取数。
}
}
}
static void timer0_initialize(void)
{
EA=0;
timer0_tick=0;
TR0=0;
TMOD=0x01;
TL0=(TIMER0_COUNT & 0x00FF);
TH0=(TIMER0_COUNT >> 8);
PT0=1;
ET0=1;
TR0=1;
EA=1;
}
void main (void)
{
unsigned 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>0))
times/=2;
//按下A键
if(command==13)
times*=2; //按下D键
} while (1); //无穷循环
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -