智能客车超载检测程序.docx

上传人:b****4 文档编号:4638037 上传时间:2022-12-07 格式:DOCX 页数:19 大小:19KB
下载 相关 举报
智能客车超载检测程序.docx_第1页
第1页 / 共19页
智能客车超载检测程序.docx_第2页
第2页 / 共19页
智能客车超载检测程序.docx_第3页
第3页 / 共19页
智能客车超载检测程序.docx_第4页
第4页 / 共19页
智能客车超载检测程序.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

智能客车超载检测程序.docx

《智能客车超载检测程序.docx》由会员分享,可在线阅读,更多相关《智能客车超载检测程序.docx(19页珍藏版)》请在冰豆网上搜索。

智能客车超载检测程序.docx

智能客车超载检测程序

#include

#include

#include

#defineucharunsignedchar

#defineuintunsignedint

#defineznum9

uchari,j,kk=0;

#defineDATAP1//P1接数据口

sbitrs=P2^3;//寄存器选择输入

sbitrw=P3^6;//液晶读/写控制

sbitrd=P3^7;//串/并方式控制

sbitlcd_en=P2^4;//液晶使能控制

voiddelay_ms(uint);

voidchek_busy();

voidsend_com(uchar);

voidsend_data(uchar);

voidlcd_init();

voidlcd_init1();

voidfyin();

//定义全局变量

uintcounter=0;//车上人数

uintsumnum=0;//还可上人数

ucharcounter_char[3]={""};

ucharsumnum_char[3]={""};

//=======分段录音首地址定义======================

#defineISD_ADDS10x0000//录音存放地址1

#defineISD_ADDS20x0100//录音存放地址2

#defineISD_ADDS30x0200//录音存放地址3

//#defineISD_ADDS40x0300//录音存放地址4

//#defineISD_ADDS50x0400//录音存放地址5

//========ISD4004指令定义========================

#definePOWER_UP0x20//上电指令

#defineSET_PLAY0xE0//指定放音指令

#definePLAY0xF0//当前放音指令

#defineSET_REC0xA0//指定录音指令

#defineREC0xB0//当前录音指令

#defineSET_MC0xE1//指定快进指令

#defineMC0xF1//快进执行指令

#defineSTOP0x30//停止当前操作

#defineSTOP_WRDN0xF1//停止当前操作并掉电

#defineRINT0x30//读状态:

OVF和EOM

//=========ISD4004--S51接口定义=================

sbitISD_SS=P0^0;//片选

sbitISD_MOSI=P0^1;//数据输入

sbitISD_MISO=P0^2;//数据输出

sbitISD_SCLK=P0^3;//ISD4004时钟

sbitISD_INT=P3^5;//溢出中断

sbitISD_RAC=P3^6;//行地址时钟

//=========按键接口定义=================

sbitK1=P2^0;//录音键

//sbitK2=P2^1;//放音键

//=========LED灯状态定义=================

sbitLED_Red=P0^6;

sbitLED_Green=P0^7;

//==========ISD4004函数定义===================

voidISD_SPI_Send8(ucharisdx8);//spi串行发送子程序,8位数据,从低到高

voidISD_SPI_Send16(uintisdx16);//spi串行发送子程序,16位数据.从低到高

uintISD_SPI_Radd(void);//读取标行地址

voidISD_Stop(void);//发送stop指令

voidISD_PowerUp(void);//发送上电指令,并延迟50ms

voidISD_PowerDown(void);//发送掉电指令,并延迟50ms

voidISD_Play(void);//发送放音指令,并延迟50ms

voidISD_SetPlay(uintadd);//发送指定放音指令,并延迟50ms

voidISD_Rec(void);//发送录音指令,并延迟50ms

voidISD_SetRec(uintadd);//发送指定录音指令,并延迟50ms

ucharISD_Chk_Isdovf(void);

voidPLAY_now(ucharadd_sect);//按指定地址开始放音

voidREC_now(ucharadd_sect);//按指定地址开始录音

//========延时函数===========================

voidDelay1Ms(uchart);//延时t*1毫秒

voidDelay();

/******************************************************************

名称:

PLAY_now(ucharadd_sect)

功能:

按指定地址段开始播放

指令:

调用:

返回:

/*****************************************************************/

voidPLAY_now(ucharadd_sect)

{

ISD_PowerUp();//ISD上电

Delay1Ms(50);

switch(add_sect)//发送setplay指令,从0x0000地址开始放

{

case0:

ISD_SetPlay(ISD_ADDS1);break;//发送地址的SetRec指令

case1:

ISD_SetPlay(ISD_ADDS2);break;//发送地址的SetRec指令

case2:

ISD_SetPlay(ISD_ADDS3);break;//发送地址的SetRec指令

//case4:

ISD_SetPlay(ISD_ADDS4);break;//发送地址的SetRec指令

//case5:

ISD_SetPlay(ISD_ADDS5);break;//发送地址的SetRec指令

//

}

ISD_Play();//发送放音指令

}

/******************************************************************

名称:

REC_now(ucharadd_sect)

功能:

按指定地址段开始录音

指令:

调用:

返回:

/******************************************************************/

voidREC_now(ucharadd_sect)

{

ISD_PowerUp();//ISD上电

Delay1Ms(50);//延迟录音

ISD_PowerUp();//ISD上电

Delay1Ms(100);//延迟录音

switch(add_sect)

{

case0:

ISD_SetRec(ISD_ADDS1);break;//发送地址的SetRec指令

case1:

ISD_SetRec(ISD_ADDS2);break;//发送地址的SetRec指令

case2:

ISD_SetRec(ISD_ADDS3);break;//发送地址的SetRec指令

//case4:

ISD_SetRec(ISD_ADDS4);break;//发送地址的SetRec指令

//case5:

ISD_SetRec(ISD_ADDS5);break;//发送地址的SetRec指令

//case6:

……`

}

ISD_Rec();//发送rec指令

}

/******************************************************************

名称:

ISD_SPI_Send8(ucharisdx)

功能:

spi串行发送子程序,8位数据

指令:

调用:

返回:

/******************************************************************/

voidISD_SPI_Send8(ucharisdx8)

{

uchari;

ISD_SS=0;//选中ISD4004

ISD_SCLK=0;

for(i=0;i<8;i++)//先发低位再发高位,依次发送。

{

if((isdx8&0x01)==1)//发送最低位

ISD_MOSI=1;

else

ISD_MOSI=0;

isdx8>>=1;//右移一位

ISD_SCLK=1;//时钟下降沿发送

ISD_SCLK=0;

}

}

/******************************************************************

名称:

ISD_SPI_Send16(uintisdx16)

功能:

spi串行发送子程序,16位数据

指令:

调用:

返回:

/******************************************************************/

voidISD_SPI_Send16(uintisdx16)

{

uchari;

ISD_SS=0;//选中ISD4004

ISD_SCLK=0;

for(i=0;i<16;i++)//先发低位再发高位,依次发送。

{

if((isdx16&0x0001)==1)//发送最低位

ISD_MOSI=1;

else

ISD_MOSI=0;

isdx16=isdx16>>1;//右移一位

ISD_SCLK=1;//时钟下降沿发送

ISD_SCLK=0;

}

}

/******************************************************************

名称:

ISD_SPI_Radd(void)

功能:

读取16位行地址

指令:

调用:

返回:

/******************************************************************/

uintISD_SPI_Radd(void)

{

uchari;

uintaddsig;

ISD_SS=0;//选中ISD4004

ISD_SCLK=0;

//==============读16位地址================

for(i=0;i<16;i++)//读行地址

{

ISD_SCLK=1;//时钟下降沿数据移出ISD

ISD_SCLK=0;

if(ISD_MISO==1)

addsig|=0x8000;

if(i<15)addsig>>=1;//最先读出的是地址的低位,所以要左移,最后一次地址不用左移,否则地址溢出

}

ISD_Stop();//发送stop指令

ISD_SS=1;//关闭spi通信端

returnaddsig;//返回地址值

}

/******************************************************************

名称:

ISD_Stop(void)

功能:

发送stop指令

指令:

ISD_SPI_Send8(ucharisdx8);

调用:

返回:

/******************************************************************/

voidISD_Stop(void)

{

//ISD_SS=0;

ISD_SPI_Send8(STOP);

ISD_SS=1;//关闭片选

}

/******************************************************************

名称:

ISD_PowerUp(void)

功能:

发送上电指令,并延迟50ms

指令:

ISD_SPI_Send8(ucharisdx8);

调用:

返回:

/******************************************************************/

voidISD_PowerUp(void)

{

//ISD_SS=0;//选中ISD4004

ISD_SPI_Send8(POWER_UP);

ISD_SS=1;

}

/******************************************************************

名称:

ISD_PowerDown(void)

功能:

发送掉电指令,并延迟50ms

指令:

ISD_SPI_Send8(ucharisdx8);

调用:

返回:

/******************************************************************/

voidISD_PowerDown(void)

{

//ISD_SS=0;

ISD_SPI_Send8(STOP_WRDN);

ISD_SS=1;

}

/******************************************************************

名称:

ISD_Play(void)

功能:

发送play指令,并延迟50ms

指令:

ISD_SPI_Send8(ucharisdx8);

调用:

返回:

/******************************************************************/

voidISD_Play(void)

{

//ISD_SS=0;

ISD_SPI_Send8(PLAY);

ISD_SS=1;

}

/******************************************************************

名称:

ISD_Rec(void)

功能:

发送rec录音指令,并延迟50ms

指令:

ISD_SPI_Send8(ucharisdx8);

调用:

返回:

/******************************************************************/

voidISD_Rec(void)

{

//ISD_SS=0;

ISD_SPI_Send8(REC);

ISD_SS=1;

}

/******************************************************************

名称:

ISD_SetPlay(uintadd)

功能:

发送setplay指令,并延迟50ms

指令:

ISD_SPI_Send8(ucharisdx8);

ISD_SPI_Send16(uintisdx16);

调用:

返回:

/******************************************************************/

voidISD_SetPlay(uintadd)

{

Delay1Ms

(1);

ISD_SPI_Send16(add);//发送放音起始地址

ISD_SPI_Send8(SET_PLAY);//发送setplay指令字节

ISD_SS=1;

}

/******************************************************************

名称:

ISD_SetRec(uintadd)

功能:

发送setrec指令,并延迟50ms

指令:

ISD_SPI_Send8(ucharisdx8);

ISD_SPI_Send16(uintisdx16);

调用:

返回:

/******************************************************************/

voidISD_SetRec(uintadd)

{

Delay1Ms

(1);

ISD_SPI_Send16(add);//发送录音起始地址

ISD_SPI_Send8(SET_REC);//发送setrec指令字节

ISD_SS=1;

}

//************************************

//检查芯片是否溢出(读OVF,并返回OVF值)

//************************************

/*ucharISD_Chk_Isdovf(void)

{

ISD_SS=0;

ISD_SCLK=0;

ISD_SCLK=1;

ISD_SCLK=0;

if(ISD_MISO==1)

{

ISD_SCLK=0;

ISD_SS=1;//关闭spi通信端

ISD_Stop();//发送stop指令

return1;//OVF为1,返回1

}

else

{

ISD_SCLK=0;

ISD_SS=1;//关闭spi通信端

ISD_Stop();//发送stop指令

return0;//OVF为0,返回0

}

}*/

/*=========================================================================

名称:

voidDelay1Ms(uchart);

功能:

延时0.1ms

参数:

t,最大255

调用:

返回:

=========================================================================*/

voidDelay1Ms(uchart)

{

uchari;

for(;t>0;t--)

{

for(i=0;i<150;i++)

{

_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();

}

}

}

//========================================

voidDelay()

{

uchari;

uintd=5000;

while(d--)

{

i=255;

while(i--);

}

}

voiddelay_ms(uintn)

{

uinti,j;

for(i=0;i

for(j=0;j<=110;j++);

}

/********************测忙碌**********************/

//测忙碌子程序

//RS=0,RW=1,E=H,D0-D7=状态字

/************************************************/

voidchek_busy()

{

rs=0;

rw=1;

lcd_en=1;

DATA=0xff;

while((DATA&0x80)==0x80);

lcd_en=0;

}

/********************写命令**********************/

//写命令子程序

//

/************************************************/

voidsend_com(ucharcmd)

{

chek_busy();

rs=0;

rw=0;

DATA=cmd;

lcd_en=1;

lcd_en=0;

}

/********************写数据**********************/

//写数据子程序

//

/************************************************/

voidsend_data(uchardat)

{

chek_busy();

rs=1;

rw=0;

DATA=dat;

lcd_en=1;

lcd_en=0;

}

//-------------------显示字符串----------------------

voidhzkdis(uchar*s)

{

while(*s>0)

{

send_data(*s);

s++;

delay_ms(5);

}

}

//--------------------显示项目名称-----------------

voidsend_project_title()

{

send_com(0x80);//第一项

hzkdis("注意安全一路平安");

send_com(0x90);

hzkdis("车上已有:

");

send_com(0x97);

hzkdis("人");

send_com(0x88);//第二项

hzkdis("可上车:

");

send_com(0x8e);

hzkdis("人");

}

/********************初始化**********************/

//复位、通讯方式选择

/***********************************************

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 成人教育 > 专升本

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1