PIC16F877A一路舵机参数化控制程序
时间:12-02
来源:互联网
点击:
;** 日期: 2010年.10月
;** 描述: 一路舵机参数化控制
;** 功能: 用Time1中断,RD6口输出
;**595417f4d0a35e02&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F3062%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">晶振: 12M
;** 适用机型: PIC16F877A,TowerPro MG995
*********************************************************************************/
#include
#define uchar unsigned char
#define uint unsigned int
uint f;
uchar servo_angle_H;
uchar servo_angle_L;
uchar compensate_L;
uchar compensate_H;
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void init()
{
TRISD=0x00;
PORTD=0x00;
INTCON=0xc0;
PIE1=0x01;
TMR1L=0;
TMR1H=0;
T1CON=0x21;
f=0;
}
void servo(uint angle)
{
uint temp,value;
value=(65536-368)-(75*angle)/9;
temp=(65536-14617)+(75*angle)/9;
servo_angle_H=value%256;
servo_angle_L=value/256 ;
compensate_L=temp%256;
compensate_H=temp/256;
}
void main()
{
init();
uint angle;
servo(0);
delay(200);
while(1)
{
for(angle=0;angle<181;angle++)
{
servo(angle);
delay(100);
}
for(angle=180;angle>0;angle--)
{
servo(angle);
delay(100);
}
}
}
void interrupt time1()
{
TMR1IF=0;
f=~f;
if(f==0)
{
TMR1L=servo_angle_H;
TMR1H=servo_angle_L;
RD6=1;
}
else
{
TMR1L=compensate_L;
TMR1H=compensate_H;
RD6=0;
}
}
;** 描述: 一路舵机参数化控制
;** 功能: 用Time1中断,RD6口输出
;**595417f4d0a35e02&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F3062%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">晶振: 12M
;** 适用机型: PIC16F877A,TowerPro MG995
*********************************************************************************/
#include
#define uchar unsigned char
#define uint unsigned int
uint f;
uchar servo_angle_H;
uchar servo_angle_L;
uchar compensate_L;
uchar compensate_H;
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void init()
{
TRISD=0x00;
PORTD=0x00;
INTCON=0xc0;
PIE1=0x01;
TMR1L=0;
TMR1H=0;
T1CON=0x21;
f=0;
}
void servo(uint angle)
{
uint temp,value;
value=(65536-368)-(75*angle)/9;
temp=(65536-14617)+(75*angle)/9;
servo_angle_H=value%256;
servo_angle_L=value/256 ;
compensate_L=temp%256;
compensate_H=temp/256;
}
void main()
{
init();
uint angle;
servo(0);
delay(200);
while(1)
{
for(angle=0;angle<181;angle++)
{
servo(angle);
delay(100);
}
for(angle=180;angle>0;angle--)
{
servo(angle);
delay(100);
}
}
}
void interrupt time1()
{
TMR1IF=0;
f=~f;
if(f==0)
{
TMR1L=servo_angle_H;
TMR1H=servo_angle_L;
RD6=1;
}
else
{
TMR1L=compensate_L;
TMR1H=compensate_H;
RD6=0;
}
}
PIC16F877A一路舵机参数化控 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)