新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 基于Atmega128L单片机控制的声音监测与无线定位系统

基于Atmega128L单片机控制的声音监测与无线定位系统

作者: 时间:2013-11-12 来源:网络 收藏
基于Atmega128L单片机控制的声音监测与无线定位系统
图7
7.程序设计及其流程图
采用同平面内三点定位方法即可得到准确的定位,统一轨道平面内有A、B、C三个定位监测点,到目标声源距离分别为Da、Db 、Dc。当某一个发生物体一旦发声,声音通过介质空气传播,被监测点的三个传感器所接受。设声源分别经过时间Ta、Tb、Tc被A、B、C监测点识别到。通过ATmega128处理,可计算出两个时间差t1、t2。已知声音在某介质中传播速度为v。通过几何定律可计算出声源0的准确坐标值(x,y)。这样就能简单、准确、高效、无误的达到对声音信号监测定位的目的。如图8所示。
基于Atmega128L单片机控制的声音监测与无线定位系统
图8
#includeiom128v.h>
#includemacros.h>
#include"define.h"
extern char Reverse_Display;//是否反相显示(白底黑字/黑底白字)
void wr_com(unsigned char value)//写指令,写指令时必须为RS=0;RW=0;
{
E_clear;
RS_clear;
RW_clear;
delay_ms(1);
LCD_DB_PORT=value;
E_set;
delay_ms(2); //如果没有延时就必须要加查忙指令
E_clear;
}
void wr_data(unsigned char sj)//写数据,写数据时必须为 RS=1;RW=0;
{
E_clear;
RS_set;
RW_clear;
delay_ms(1);
//if(!Reverse_Display)
LCD_DB_PORT=sj;
//else
//PORTA=~sj;
E_set;
delay_ms(1);//如果没有延时就必须要加查忙指令
E_clear;
}
void LCD12864_Initialization (void)
{
LCD_DB_PORT=0x00;
LCD_DB_DDR=0xff;
COM_PORT=0x00;
COM_DDR=0xff;
wr_com(0x01); //清屏
wr_com(0x08); //关显示
wr_com(0x03); //归位
wr_com(0x30); //功能设置
//wr_com(0x0D); //开显示 有光标
wr_com(0x0C);//开显示 无光标
wr_com(0x01); //清屏
}
//****************
//outChinese 为函数名
//place 为显示地址的首地址
//unit 字符长度
//charcode[] 要显示数据的内容
void outChinese(unsigned char place,unsigned char unit,unsigned char *point)
{
unsigned char i,progdata;
wr_com(place);
for(i=0;iunit*2;i++)//一个汉字为两个字符
{
progdata=*(point+i);
wr_data(progdata);
}
}
void outchar(unsigned char place,unsigned char unit,unsigned char *point)
{
unsigned char i,progdata;
wr_com(place);
for(i=0;iunit;i++)
{
progdata=*(point+i);
wr_data(progdata);
}
}
#includeiom128v.h>
#includemacros.h>
#include"define.h"
#pragma interrupt_handler INT_0:2
const uchar Place_show[]="声源坐标为:";
const uchar Digits[]="0123456789";
uchar soures[7]={0,};
void main()
{
init();
//outChinese(0x80,1,Place_show+0*2);
EICRA=0X03;//上升沿触发0-2中断
EIMSK=0X01;//使能0-2中断
while(1)
{
display();
delay_ms(1000);
EIMSK=0X01;//使能0-2中断
SEI();
}
}
void init()
{
LCD12864_Initialization ();
}
void INT_0()
{
soures[0]=soures[0]+1;
if(soures[0]==50) soures[0]=0;
EIMSK=0X00;//使能0-2中断
CLI();
}
void delay_us(uint us) //在8M时钟情况下的US延时
{
uint i;
us = us*5/4; //5/4是在8MHz晶振下,通过软件仿真反复实验得到的数值
for(i=0; ius; i++);
}
void delay_ms(uint ms)
{
uint i,j;
for(i=0;ims;i++)
{
for(j=0;j1141;j++);

评论


相关推荐

技术专区

关闭