新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 舵機(jī)程序之?dāng)?shù)據(jù)的處理

舵機(jī)程序之?dāng)?shù)據(jù)的處理

作者: 時(shí)間:2016-12-01 來(lái)源:網(wǎng)絡(luò) 收藏
//上位機(jī)對(duì)于舵機(jī)的每次調(diào)度信息通過(guò)shujuchuli函數(shù)提取出來(lái)

#define BIAOZHI(x,y,z) Biaozhi=x;Biaozhip=y;Biaozhit=z
char ASC_zhuan_Valu(char asc)
{
char valu;
switch(asc)
{
case 0x30:valu=0;break; //0的ASC碼時(shí)0x30,,十進(jìn)制48
case 0x31:valu=1;break;
case 0x32:valu=2;break;
case 0x33:valu=3;break;
case 0x34:valu=4;break;
case 0x35:valu=5;break;
case 0x36:valu=6;break;
case 0x37:valu=7;break;
case 0x38:valu=8;break;
case 0x39:valu=9;break;
}
return valu;
}
void shujuchuli(char *Huancen,unsigned int *Pwm)//數(shù)據(jù)處理
{
char Biaozhi,Biaozhip,Biaozhit;
unsigned int Shuju=0,Shujup=0,Shujut=0;
while(*Huancen!=10)
{
if(Biaozhi==1&*Huancen!=80&*Huancen!=84)
{
Shuju=Shuju*10+ASC_zhuan_Valu(*Huancen);
}
if(Biaozhip==1&*Huancen!=35&*Huancen!=84)
{
Shujup=Shujup*10+ASC_zhuan_Valu(*Huancen);
}
if(Biaozhit==1&*Huancen!=80&*Huancen!=35)
{
Shujut=Shujut*10+ASC_zhuan_Valu(*Huancen);
}
if(*Huancen==35) //#
{
BIAOZHI(1,0,0);
}
if(*Huancen==80) //P
{
BIAOZHI(0,1,0);
}
if(*Huancen==84) //T
{
BIAOZHI(0,0,1);
}
Huancen++;
if(*Huancen==10)
{
if(Shujup>500)
{
*(Pwm+Shuju-1)=Shujup;//新的位置數(shù)據(jù)產(chǎn)生進(jìn)行調(diào)度
}
return;
}
}
}

本文引用地址:http://m.butianyuan.cn/article/201612/324195.htm


關(guān)鍵詞: 舵機(jī)程序數(shù)

評(píng)論


技術(shù)專區(qū)

關(guān)閉