本程序中用到的头文件12c5a.h下载:http://www.51hei.com/f/12c5a.rar
#include <12c5a.H> //STC12C5A系列单片机
#include”intrins.h”
void delay(uint16 time); //软件延时函数
void Timer_init(); //守时器初始化函数
void Timer0(uint32 us); //守时器0守时函数
void qhuan(unsigned int ms50,char zushu);
char n,a=101;
int LK[8]={0},*K;
int shuju[8][8]=
{ //舵机动作数据
{2500,2500,2500,2500,2500,2500,2500,2500},
{500,500,500,500,500,500,500,500},
{2500,2500,2500,2500,2500,2500,2500,2500},
{500,500,500,500,500,500,500,500},
{2500,2500,2500,2500,2500,2500,2500,2500},
{500,500,500,500,500,500,500,500},
{2500,2500,2500,2500,2500,2500,2500,2500},
{500,500,500,500,500,500,500,500},
};
int *PWMM,pwm[8]; //PWMM用以寻址动作数据的指针,LP接纳信息时用以指向数据缓存
unsigned int thesea;
sbit pwm8=P0^5;
sbit pwm7=P0^6;
sbit pwm6=P0^7;
sbit pwm5=P4^6;
sbit pwm4=P4^1;
sbit pwm3=P4^5;
sbit pwm2=P4^4;
sbit pwm1=P2^7;
void main(void)
{
uint8 i=0;
P0M1=0; //设置P口为强推免输出形式,下同
P0M0=0XFF;
P1M1=0;
P1M0=0XFF;
P2M1=0;
P2M0=0XFF;
P3M1=0;
P3M0=0XFF;
Timer_init(); //守时器初始化
Timer0(31); //经过一个守时值进入守时循环
K=LK;
PWMM=shuju[0];
delay(100);
while(1)
{
;
}
}
void delay(uint16 time)
{
uint16 i;
uint16 j;
for(i=0;i<1000;i++)
for(j=0;j}
void Timer_init()
{
EA=1; //开总中止
AUXR|=0xC0; //T0,T1作业在1T
TMOD|= 0x11; //T0作业在方法1,16位
ET0 = 1; //开守时器0中止
ET1 = 1;
TR0=1;
TR1=0;
}
void Timer0(uint32 us)
{
uint32 valu;
valu=us*11; //作业在1T,最大守时时刻0xffff/11us
valu=valu;
valu=0xffff-valu; //
TH0=valu>>8;
TL0=valu;
}