[2022-04-02]C51单片机实现按键控制舵机
#include "reg52.h"
sbit SG90=P1^1;
sbit key1=P2^1;
sbit key2=P2^0;
int Angle;
int cnt;
void Time0Init()
{
TMOD=0x01;
TL0=0x33;
TH0=0xFE;//配置定时器,时长0.5ms
TR0=1;
TF0=0;
ET0=1;
EA=1; //中断开启
}
void main()
{
Delay300ms();
Time0Init();
Angle=1;
cnt=0;
SG90=1;
while(1)
{
if(key1==0)//key1按下,转动0°
{
Angle=1;
cnt=0;
}
if(key2==0)//key2按下,转动135°
{
Angle=4;
cnt=0;
}
}
}
void Timebaobiao() interrupt 1
共有 0 条评论