初级会员
- 积分
- 78
- 金钱
- 78
- 注册时间
- 2016-12-10
- 在线时间
- 16 小时
|
楼主 |
发表于 2018-7-6 12:16:28
|
显示全部楼层
#include<reg52.h>
unsigned long beats = 0;
void StartMotor(unsigned long angle);
void main()
{
EA = 1;
TMOD = 0x01;
TH0 = 0xf8;
TL0 = 0xcd;
ET0 = 1;
TR0 = 1;
StartMotor(360);
while (1) {};
}
void StartMotor(unsigned long angle)
{
EA = 0;
beats = (angle*4076)/360;
EA = 1;
}
void InterruptTimer0() interrupt 1
{
unsigned char tmp;
static unsigned char index = 0;
unsigned char code BeatCode[8] = {
0x0E, 0x0C, 0x0D, 0x09, 0x0B, 0x03, 0x07, 0x06};
TH0 = 0xf8;
TL0 = 0xcd;
if(beats != 0)
{
tmp = P1;
tmp = tmp & 0xf0;
tmp = tmp | BeatCode[index];
P1 = tmp;
index++;
index = index & 0x07;
beats--;
}
else
{
P1 = P1 | 0x0f;
}
}
这是原程序,可行 |
|