欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
單片機舵機轉動超聲波測距程序 為啥我加入超聲波測距舵機就不轉了 求幫助
[打印本頁]
作者:
人生這里
時間:
2019-5-7 20:24
標題:
單片機舵機轉動超聲波測距程序 為啥我加入超聲波測距舵機就不轉了 求幫助
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar num=0,sun;
uchar shi,ge,bai;
int jia=0;
unsigned long int s=0;
void delay(uint max)
{
int x,y;
for(x=0;x<max;x++)
for(y=0;y<500;y++);
}
int cade[]={1,8,18};
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
sbit trig=P2^1;
sbit echo=P2^2;
sbit pwm=P2^0;
void start()
{
trig=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
trig=0;
}
uchar Lcd1602_ReadBusy()
{
uchar temp;
RS=0;
RW=1;
_nop_();
P0=0xff;
_nop_();
E=1;
_nop_();
temp=P0;
_nop_();
E=0;
return (temp&0x80);
}
void Lcd1602_WriteCom(uchar com)
{
while(Lcd1602_ReadBusy());
RS=0;
RW=0;
_nop_();
P0=com;
_nop_();
E=1;
_nop_();
_nop_();
E=0;
_nop_();
_nop_();
}
void Lcd1602_WriteData(uchar dat)
{
while(Lcd1602_ReadBusy());
RS=1;
RW=0;
_nop_();
P0=dat;
_nop_();
E=1;
_nop_();
_nop_();
E=0;
_nop_();
_nop_();
}
void Lcd1602_init()
{
delay(15);
Lcd1602_WriteCom(0x38);
delay(5);
Lcd1602_WriteCom(0x38);
delay(5);
Lcd1602_WriteCom(0x38);
Lcd1602_WriteCom(0x0c);
Lcd1602_WriteCom(0x01);
Lcd1602_WriteCom(0x06);
}
void count()
{
TMOD=0x01;
ET0=1;
EA=1;
TL0=0;
TH0=0;
start();
while(!echo);
TR0=1;
while(echo);
TR0=0;
s=TH0*256+TL0+jia;
jia=0;
s=s*0.017*12/11;
Lcd1602_init();
bai=s/100;
shi=s/10%10;
ge=s%10%10;
Lcd1602_WriteCom(0x80+0x02);
Lcd1602_WriteData(0x30+bai);
Lcd1602_WriteData(0x30+shi);
Lcd1602_WriteData(0x30+ge);
}
void T1_time()interrupt 3
{
jia=jia+65536;
TH0=0;
TL0=0;
}
void duoji(uint i)
{
TMOD=0X11;
TH0=(65536-100)/256;
TR0=(65536-100)%256;
EA=1;
ET0=1;
TR0=1;
sun=cade[i];
}
void T0_time()interrupt 1
{
TH0=(65536-100)/256;
TL0=(65536-100)%256;
num++;
if(num==50) num=0;
if(num>sun) pwm=0;
else pwm=1;
}
void main()
{
duoji(0);
delay(100);
duoji(1);
delay(100);
count();
duoji(2);
delay(100);
}
復制代碼
作者:
大克汐
時間:
2019-11-3 12:44
補下電路圖
作者:
大克汐
時間:
2019-11-3 13:03
你舵機TMOD為0x11,超聲波為0x01,先舵機設置,后超聲波,TMOD數值改了
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1