标题:
基于51单片机的SG90舵机用433无线模块控制源程序
[打印本页]
作者:
郭龙·
时间:
2019-7-21 15:49
标题:
基于51单片机的SG90舵机用433无线模块控制源程序
#include <reg52.h>
sbit SG_PWM=P0^0;
sbit Key_1=P2^4;
sbit Key_2=P2^3;
sbit Key_3=P2^2;
unsigned char count=0;
unsigned char PWM_count=1;
void delay(unsigned char i)
{
unsigned char j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void Timer_Init()
{
TMOD=0X01;
TH0=0Xfe;
TL0=0X33;
ET0=1;
TR0=1;
EA=1;
}
void Timer() interrupt 1
{
TR0=0;
TH0=0Xfe;
TL0=0X33;
if(count<=PWM_count)
{
SG_PWM=1;
}
else
{
SG_PWM=0;
}
count++;
if(count>=40)
{
count=0;
}
TR0=1;
}
void main()
{
Timer_Init();
while(1)
{
if(Key_1==1)
{
delay(10);
EA=0;
if(Key_1==1)
{
PWM_count=2;
count=0;
EA=1;
}
while(!Key_1);
}
if(Key_2==1)
{
delay(10);
EA=0;
if(Key_2==1)
{
PWM_count=4;
count=0;
EA=1;
}
while(!Key_2);
}
if(Key_3==1)
{
delay(10);
EA=0;
if(Key_3==1)
{
PWM_count=3;
count=0;
EA=1;
}
while(!Key_3);
}
}
}
作者:
admin
时间:
2019-7-21 18:41
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1