用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();
}
}
#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();
}
}
相关文章推荐
- 深入理解PHP内核(五)函数的内部结构
- 算法训练 比赛安排
- java post raw 的示例
- 关于java堆内存溢出的几种情况
- 视图、同义词、索引
- 使用xshell及xftp上传下载文件或目录
- 应对编程疲劳,试试如下方法(转载)
- python内置map和six.moves.map的区别
- asp.net 前后台页面交互数据的四种方案,非ajax
- github设置添加SSH
- 统计java代码行数和jar包中*.class代码的行数
- 2>/dev/null;1>/dev/null
- 杭电1715大菲波数(打表)
- halcon之屌炸天的自标定
- 3.1-闭包
- Android IPC进程通信——Messager方式
- 大数据——数据库优化
- iOS开发——关于开发者账号引发的血案
- 节点合并、改写提交——rebase
- 详解Node.js包的工程目录与NPM包管理器的使用