加入星計(jì)劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴(kuò)散
  • 作品版權(quán)保護(hù)
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長(zhǎng)期合作伙伴
立即加入

基于51單片機(jī)的震動(dòng)報(bào)警器設(shè)計(jì)

10/03 16:12
1258
服務(wù)支持:
技術(shù)交流群

完成交易后在“購(gòu)買成功”頁面掃碼入群,即可與技術(shù)大咖們分享疑惑和經(jīng)驗(yàn)、收獲成長(zhǎng)和認(rèn)同、領(lǐng)取優(yōu)惠和紅包等。

虛擬商品不可退

當(dāng)前內(nèi)容為數(shù)字版權(quán)作品,購(gòu)買后不支持退換且無法轉(zhuǎn)移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論
放大
實(shí)物圖
相關(guān)方案
  • 方案介紹
  • 相關(guān)文件
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請(qǐng)入駐 產(chǎn)業(yè)圖譜

基于51單片機(jī)和ADXL345震動(dòng)檢測(cè)模塊檢測(cè)震動(dòng);用LED燈和蜂鳴器表示超限報(bào)警,用LCD顯示模擬檢測(cè)結(jié)果。

主要選用ADXL345三軸振動(dòng)傳感器結(jié)合微分電路測(cè)得加速度,并且利用LCD顯示震動(dòng)信號(hào)。

a61d3b58e4ab4cd5b13c2f27ace7938b.png

程序運(yùn)行圖:

部分程序:

#include "system.h"

uint8 buffer[16];
int16 XAxisDegree,YAxisDegree,ZAxisDegree;
int16 XAxisDegreeTemp,YAxisDegreeTemp,ZAxisDegreeTemp;

int16 temp0,temp1;?? ??? ??? ??? ? //int ? ?int16
int8 XAlarmL=-90,XAlarmH=90;?? ??? ? ?//char ? int8
int8 YAlarmL=-90,YAlarmH=90;
int8 ZAlarmL=-90,ZAlarmH=90;

uint8 SystemSet;?? ??? ? ?//unsigned char uint8
bit tab;

void LcdDisplay(void)
{
int16 temp;

if(SystemSet==0)
{
if(XAxisDegree==0) ? ? ?LCD1602_DisStr(0,0,"X: ");
else if(XAxisDegree>0) ?LCD1602_DisStr(0,0,"X:+");
else ? ? ? ? ? ? ? ? ? ?LCD1602_DisStr(0,0,"X:-");
if(XAxisDegree<0) ?temp=(-1)*XAxisDegree; ?// 轉(zhuǎn)化為正數(shù),顯示需要
else ? ? ? ? ? ? ? temp=XAxisDegree;
sprintf(buffer,"%02d.%d",temp/10,temp%10);
LCD1602_DisStr(0,3,buffer);

if(YAxisDegree==0) ? ? ?LCD1602_DisStr(0,9,"Y: ");
else if(YAxisDegree>0) ?LCD1602_DisStr(0,9,"Y:+");
else ? ? ? ? ? ? ? ? ? ?LCD1602_DisStr(0,9,"Y:-");
if(YAxisDegree<0) ?temp=(-1)*YAxisDegree;
else ? ? ? ? ? ? ? temp=YAxisDegree;
sprintf(buffer,"%02d.%d",temp/10,temp%10);
LCD1602_DisStr(0,12,buffer);

if(ZAxisDegree==0) ? ? ?LCD1602_DisStr(1,0,"Z: ");
else if(ZAxisDegree>0) ?LCD1602_DisStr(1,0,"Z:+");
else ? ? ? ? ? ? ? ? ? ?LCD1602_DisStr(1,0,"Z:-");
if(ZAxisDegree<0) ?temp=(-1)*ZAxisDegree;
else ? ? ? ? ? ? ? temp=ZAxisDegree;
sprintf(buffer,"%02d.%d",temp/10,temp%10);
LCD1602_DisStr(1,3,buffer);
}
else
{
if(SystemSet==1) ? ? ? LCD1602_DisStr(0,4,"<X Set>");
else if(SystemSet==2) ?LCD1602_DisStr(0,4,"<Y Set>");
else if(SystemSet==3) ?LCD1602_DisStr(0,4,"<Z Set>");

if(DataVal0==0) ? ? ?LCD1602_DisStr(1,0,"L: ");
else if(DataVal0>0) ?LCD1602_DisStr(1,0,"L:+");
else ? ? ? ? ? ? ?LCD1602_DisStr(1,0,"L:-");
if(temp0<0) ?temp=(-1)*DataVal0;?? ? ?//
else ? ? ? ? temp=DataVal0;
sprintf(buffer,"%02d",temp);
LCD1602_DisStr(1,3,buffer);

if(DataVal1==0) ? ? ?LCD1602_DisStr(1,9,"H: ");
else if(DataVal1>0) ?LCD1602_DisStr(1,9,"H:+");
else ? ? ? ? ? ? ?LCD1602_DisStr(1,9,"H:-");
if(temp1<0) ?temp=(-1)*DataVal1;
else ? ? ? ? temp=DataVal1;
sprintf(buffer,"%02d",temp);
LCD1602_DisStr(1,12,buffer);
}
}

// 角度測(cè)量
void DegreeMeasure(void)
{
uint16 temp;
int32 temp0;
int16 XTemp,YTemp,ZTemp;
double temp1;

ADXL345_ReadBytes();
temp=((uint16)XyzDataBuf[1]<<8)|XyzDataBuf[0]; // 合成數(shù)據(jù)
XTemp=(int16)temp; ? // 由于是以二進(jìn)制補(bǔ)碼的形勢(shì)存放的數(shù)據(jù),所以要編制轉(zhuǎn)換成帶符號(hào)的值
temp=((uint16)XyzDataBuf[3]<<8)|XyzDataBuf[2];
YTemp=(int16)temp;
temp=((uint16)XyzDataBuf[5]<<8)|XyzDataBuf[4];
ZTemp=(int16)temp;

temp0 = (int32)YTemp*YTemp;
temp0 += (int32)ZTemp*ZTemp;
temp1 = sqrt(temp0);
temp1 = atan(XTemp/temp1); ? ? ? ? ?// 計(jì)算傾角的弧度值
XAxisDegreeTemp= temp1*1800/PI; ? ? // 弧度值變?yōu)榻嵌戎?,放?0倍,保留1位小數(shù)

temp0 = (int32)XTemp*XTemp;
temp0 += (int32)ZTemp*ZTemp;
temp1 = sqrt(temp0);
temp1 = atan(YTemp/temp1);
YAxisDegreeTemp= temp1*1800/PI;

temp0 = (int32)YTemp*YTemp;
temp0 += (int32)XTemp*XTemp;
temp1 = sqrt(temp0);
temp1 = atan(ZTemp/temp1);
ZAxisDegreeTemp= temp1*1800/PI;
}

void CalcAvrgDegree(void)
{
static int16 XSum=0,XMin=900,XMax=-900;
static int16 YSum=0,YMin=900,YMax=-900;
static int16 ZSum=0,ZMin=900,ZMax=-900;
static uint8 i=0;

if(XMin>XAxisDegreeTemp) ?XMin=XAxisDegreeTemp; //求最小值
if(XMax<XAxisDegreeTemp) ?XMax=XAxisDegreeTemp; //求最大值
XSum += XAxisDegreeTemp; //累加

if(YMin>YAxisDegreeTemp) ?YMin=YAxisDegreeTemp; //求最小值
if(YMax<YAxisDegreeTemp) ?YMax=YAxisDegreeTemp; //求最大值
YSum += YAxisDegreeTemp; //累加

if(ZMin>ZAxisDegreeTemp) ?ZMin=ZAxisDegreeTemp; //求最小值
if(ZMax<ZAxisDegreeTemp) ?ZMax=ZAxisDegreeTemp; //求最大值
ZSum += ZAxisDegreeTemp; //累加

i++;
if(i>=10) ?//采樣10次求平均
{
XSum = XSum-XMax-XMin; ? ? // 去除極值
XAxisDegree=XSum/(i-2); ? ?// 求出平均AD值(因?yàn)槿コ藰O值,所以次數(shù)要減2)
XSum=0;XMin=900;XMax=-900; // 變量復(fù)位,準(zhǔn)備下一次計(jì)算

YSum = YSum-YMax-YMin;
YAxisDegree=YSum/(i-2);
YSum=0;YMin=900;YMax=-900;

ZSum = ZSum-ZMax-ZMin;
ZAxisDegree=ZSum/(i-2);
ZSum=0;ZMin=900;ZMax=-900;

i=0;
}
}

  • 有需要資料的可了解一下.docx

相關(guān)推薦

電子產(chǎn)業(yè)圖譜