欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
關于單片機超聲波控制數碼管程序 改變距離數碼管無反應
[打印本頁]
作者:
1888888
時間:
2022-3-24 13:31
標題:
關于單片機超聲波控制數碼管程序 改變距離數碼管無反應
51hei截圖20220324132517.png
(64.8 KB, 下載次數: 30)
下載附件
2022-3-24 13:30 上傳
單片機源程序如下:
#include <REGX52.H>
sbit SH_CP1 = P0^1;
sbit DS = P0^0;
sbit ST_CP1 = P0^2;
int distL,distR;
unsigned char code table[]={
0x06,0x5B,0x4F,0x66,0x6D,
0x7D,0x07,0x7F,0x6F,0x3F};
sbit TrigL = P2^4; // 超聲波模塊的Trig管腳
sbit EchoL = P2^5; // 超聲波模塊的Echo管腳
sbit TrigR = P2^6; // 超聲波模塊的Trig管腳
sbit EchoR = P2^7; // 超聲波模塊的Echo管腳
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--)
{
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
void send_data_74hc595(int data_74hc595) //傳送數據給74hc595
{
char a;
SH_CP1 = 0;
for(a = 0; a < 8; ++a)
{
DS = (data_74hc595 << a) & 0x80; //從高位開始傳輸
SH_CP1 = 1;
SH_CP1 = 0;
}
}
void show_74hc595()
//數據顯示
{
ST_CP1 = 0;
ST_CP1 = 1;
}
void Nixie()
{
switch(distR)
{
case 1:send_data_74hc595(table[1]);show_74hc595();break;
case 2:send_data_74hc595(table[2]);show_74hc595();break;
case 3:send_data_74hc595(table[3]);show_74hc595();break;
case 4:send_data_74hc595(table[4]);show_74hc595();break;
case 5:send_data_74hc595(table[5]);show_74hc595();break;
case 6:send_data_74hc595(table[6]);show_74hc595();break;
case 7:send_data_74hc595(table[7]);show_74hc595();break;
case 8:send_data_74hc595(table[8]);show_74hc595();break;
case 9:send_data_74hc595(table[9]);show_74hc595();break;
case 10:send_data_74hc595(table[0]);show_74hc595();break;
}
switch(distL)
{
case 1:send_data_74hc595(table[1]);show_74hc595();break;
case 2:send_data_74hc595(table[2]);show_74hc595();break;
case 3:send_data_74hc595(table[3]);show_74hc595();break;
case 4:send_data_74hc595(table[4]);show_74hc595();break;
case 5:send_data_74hc595(table[5]);show_74hc595();break;
case 6:send_data_74hc595(table[6]);show_74hc595();break;
case 7:send_data_74hc595(table[7]);show_74hc595();break;
case 8:send_data_74hc595(table[8]);show_74hc595();break;
case 9:send_data_74hc595(table[9]);show_74hc595();break;
case 10:send_data_74hc595(table[0]);show_74hc595();break;
}
}
//模塊程序
void GetDistanceL()
{
TH0 = 0;
TL0 = 0;
TrigL=0;
TrigL=1;
Delay(0.001);
TrigL=0;
while(!EchoL);
TR0=1; //開啟計數
while(EchoL);
TR0=0; //關閉計數
//timeL=TH0*256+TL0;
// timeL *= 12/11.0592;
//s=(timeL*1.7)/100; //算出來是CM
distL=((TH0*256+TL0)*0.034)/2;
}
void GetDistanceR()
{
TH0 = 0;
TL0 = 0;
TrigR=0;
TrigR=1;
Delay(0.001);
TrigR=0;
while(!EchoR);
TR0=1;
while(EchoR);
TR0=0;
//timeR=TH0*256+TL0;
//s=(timeR*1.7)/100; //算出來是CM
distR=((TH0*256+TL0)*0.034)/2;
}
void set()
{
TMOD=0x21;
TH0=0;
TL0=0;
ET0=1;
EA=1;
}
void main()
{
while(1)
{
set();
GetDistanceL();
GetDistanceR();
Nixie();
}
}
復制代碼
作者:
1888888
時間:
2022-3-24 13:32
超聲波改變距離數碼管無反應,求大佬們支個招
作者:
lkc8210
時間:
2022-3-25 00:41
1. Delay(0.01) = Delay(0), Delay(X) X只可以是0~65535的正整數
2. TrigL=1;到TrigL=0;之間要最少要有10us延時,弄個i=3;while(i--);就夠了(unsigned int i)
3. 由于Trig啟動不成功,程序在while(!Echo)那里卡死了
4. Nixie();只接受0~10, 也有可能是distL和dist大于10所以沒反應
5. switch(distR%11)switch(distL%11)加個取余看看
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1