国产免费AV|泡泡玛特欧洲总部将设在伦敦|中文天堂网www新版资源在线|一本久道综合在线中文|国精产品一二三产区的使用方法|香蕉鱼在线观看|www.27eee
ELEOK
標(biāo)題:
基于51單片機(jī)超聲波雷達(dá)測(cè)距(源程序+Proteus仿真)
[打印本頁(yè)]
作者:
eng
時(shí)間:
2021-7-12 16:12
標(biāo)題:
基于51單片機(jī)超聲波雷達(dá)測(cè)距(源程序+Proteus仿真)
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
3.gif
(102.93 KB)
下載附件
2021-7-12 16:08 上傳
部分源碼:完整源碼見附件
#include <reg52.H>//器件配置文件
#include <intrins.h>
#include "eeprom52.h"
//傳感器接口
sbit RX = P3^2;
sbit TX = P3^3;
//按鍵聲明
sbit S1 = P1^4;
sbit S2 = P1^5;
sbit S3 = P1^6;
//蜂鳴器
sbit Feng= P2^0;
sbit W1=P1^0;
sbit W2=P1^1;
sbit W3=P1^2;
sbit W4=P1^3;
//變量聲明
unsigned int time=0;
unsigned int timer=0;
unsigned char posit=0;
unsigned long S=0;
unsigned long BJS;//報(bào)警距離
//模式 0正常模式 1調(diào)整
char Mode=0;
bit flag=0;
bit flag_KEY=0;
unsigned char const discode[] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0xff/*-*/}; //數(shù)碼管顯示碼0123456789-和不顯示
//unsigned char const positon[4]={0xfd,0xfb,0xf7,0xfe}; //位選
unsigned char disbuff[4] ={0,0,0,0}; //數(shù)組用于存放距離信息
unsigned char disbuff_BJ[4] ={0,0,0,0};//報(bào)警信息
void Display();
/******************把數(shù)據(jù)保存到單片機(jī)內(nèi)部eeprom中******************/
void write_eeprom()
{
SectorErase(0x2000);
byte_write(0x2000, BJS);
byte_write(0x2060, a_a);
}
/******************把數(shù)據(jù)從單片機(jī)內(nèi)部eeprom中讀出來*****************/
void read_eeprom()
{
BJS = byte_read(0x2000);
a_a = byte_read(0x2060);
}
/**************開機(jī)自檢eeprom初始化*****************/
void init_eeprom()
{
read_eeprom(); //先讀
if(a_a != 1) //新的單片機(jī)初始單片機(jī)內(nèi)問eeprom
{
BJS = 50;
a_a = 1;
write_eeprom(); //保存數(shù)據(jù)
}
}
//延時(shí)20ms(不精確)
void delay(void)
{
unsigned char a,b,c;
for(c=2;c>0;c--)
for(b=38;b>0;b--)
for(a=60;a>0;a--);
}
//按鍵掃描
void Key_()
{
if(flag_KEY==0)
{
if(Mode!=0)
{
//+
if(S1==0)
{
delay(); //延時(shí)去抖
if(S1==0)
{
BJS++; //報(bào)警值加
flag_KEY=1;
if(BJS>=151) //最大151
{
BJS=0;
}
write_eeprom();//保存數(shù)據(jù)
// while(S1==0)
// Display();
}
}
//-
if(S2==0)
{
delay();
if(S2==0)
{
BJS--; //報(bào)警值減
flag_KEY=1;
if(BJS<=1) //最小1
{
BJS=150;
}
write_eeprom();//保存數(shù)據(jù)
復(fù)制代碼
仿真文件和完整源碼下載:
超聲波測(cè)距.zip
(160.74 KB, 售價(jià): 3 E幣)
2021-7-12 16:09 上傳
點(diǎn)擊文件名下載附件
售價(jià): 3 E幣
[記錄]
[
購(gòu)買
]
歡迎光臨 ELEOK (http://www.afoofa.cn/)
Powered by Discuz! X5.0