基于51的wifi视频小车制作masonson…
来源:互联网 发布:易语言阿里云api接口 编辑:程序博客网 时间:2024/05/29 04:45
//请根据自己马达的控制 来改变程序
#include<reg52.h>
#include<math.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar Buffer=0; //从串口接收的数据
uint URTAReceivedCount=0,n=1;
uchar data Tempdatatable[5],CommandDatatable[5];//数据包
uchar serVal[2];
//uint pwm[]={1120,1190,1382,1382,1382,1382,1382,1382};//初始90度,(实际是1382.4,取整得1382)
//uchar pwm_flag=0;
uint code ms0_5Con=461; //0.5ms计数 (实际是460.8,取整得461)
uint code ms2_5Con=2304; //2.5ms计数
bit key_stime_ok;
void Delay_1ms(uint i)//1ms延时
{
uchar x,j;
for(j=0;j
for(x=0;x<=148;x++);
}
void Send_Data(uchar type,uchar cmd,uchar dat)
{
uchar dataBuffer[5];//构建数据包
uchar *p;
uint Send_Count=0;
p = Buffer;
Buffer[0]=0XFF;
Buffer[1]=type;
Buffer[2]=cmd;
Buffer[3]=dat;
Buffer[4]=0XFF;
while(1)
{
if(*p==0XFF)
{
Send_Count++; //0XFF标志统计位
}
SBUF = *p; //发送
while(!TI) //如果发送完毕,硬件会置位TI,等待发送完毕
{
_nop_();
}
p++;
TI = 0;
if(Send_Count == 2) //当统计到两次出现0XFF,则认为一个数据包发送完毕,跳出循环
{
TI = 0;
break;
}
}
}
void Com_Int(void) interrupt 4
{
uchar temp;
ES=0; //关串口中断
RI=0; //软件清除接收中断
temp=SBUF;
if(temp==0XFF &&URTAReceivedCount<3)
{
Tempdatatable[0]==0XFF; //包头
URTAReceivedCount++;
}
else
{
Tempdatatable[n]=temp;
n++;
if(URTAReceivedCount==0&&n==2)
n=1;
}
if(URTAReceivedCount==2)//包尾
{
Tempdatatable[0]=0XFF;
Tempdatatable[4]=0XFF;
n=1;
URTAReceivedCount=0; //组包完毕
temp=" ";
//Send_Data(Tempdatatable[1],Tempdatatable[2],Tempdatatable[3]);
#include<reg52.h>
#include<math.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar Buffer=0;
uint URTAReceivedCount=0,n=1;
uchar data Tempdatatable[5],CommandDatatable[5];//数据包
uchar serVal[2];
//uint pwm[]={1120,1190,1382,1382,1382,1382,1382,1382};//初始90度,(实际是1382.4,取整得1382)
//uchar pwm_flag=0;
uint code ms0_5Con=461; //0.5ms计数 (实际是460.8,取整得461)
uint code ms2_5Con=2304; //2.5ms计数
bit key_stime_ok;
void Delay_1ms(uint i)//1ms延时
{
uchar x,j;
for(j=0;j
for(x=0;x<=148;x++);
}
void Send_Data(uchar type,uchar cmd,uchar dat)
{
}
void Com_Int(void) interrupt 4
{
uchar temp;
ES=0; //关串口中断
RI=0; //软件清除接收中断
temp=SBUF;