您的位置:首页 > 其它

用AT89S52控制单个舵机程序

2016-02-16 15:40 369 查看
#include<reg52.h>

#define uint unsigned int

#define uchar unsigned char

sbit jia=P2^1;

sbit jian=P2^2;

sbit PWM=P2^3;

uint count;

uint jd;

void delay(uint ms)

{

uint i,j;

for(i=ms;i>0;i--)

for(j=110;j>0;j--);

}

void tim0()

{

TMOD=0x01;

TH0=0Xfe; //用11.0592MHZ 1.0851us时钟周期是1个机器周期
461 65075=65536-461 比如256是0100所以 65075/256就是多少个0100那么就是高八位剩下的取余就是低八位

TL0=0X33;

TR0=1;// 启动定时器0

}



void tim0_() interrupt 1

{

TH0=0XFE;

TL0=0X33;

if(count<jd)

PWM=1;

else

PWM=0;

count+=1;

count%=40;

}

void anjian()

{

if(jia==0) //角度增加按键是否按下

{

delay(10);//消抖

if(jia==0)//确认按下

jd++;

count=0;//

if(jd==6)

jd=5;

while(1);

}

if(jian==0)

{

delay(10);

if(jian==0)

jd--;

count=0;

if(jd==0)

jd=1;

while(1);

}

}



void main()

{

count=0;

jd=1;

while(1)

{

anjian();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: