基于bmp085氣壓傳感器制作的大氣壓強、溫度、海拔高度測量儀(含詳細源代碼)_第1頁
基于bmp085氣壓傳感器制作的大氣壓強、溫度、海拔高度測量儀(含詳細源代碼)_第2頁
基于bmp085氣壓傳感器制作的大氣壓強、溫度、海拔高度測量儀(含詳細源代碼)_第3頁
基于bmp085氣壓傳感器制作的大氣壓強、溫度、海拔高度測量儀(含詳細源代碼)_第4頁
基于bmp085氣壓傳感器制作的大氣壓強、溫度、海拔高度測量儀(含詳細源代碼)_第5頁
已閱讀5頁,還剩20頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

前一段時間看到一網(wǎng)店盡然有大氣壓強傳感器銷售,抓緊搞了一塊回來試試,花了兩天的時間最終把它搞定了,其中部分代碼借鑒與一網(wǎng)友的的代碼。廢話不多說先上傳測量效果照另外本項目的源代碼是模塊編程,源代碼便于閱讀,便于移植,也是一個不錯的模塊化編程例程,假如對這些代碼有任何看法或者建議的都可以提出來,感謝源代碼:/******************************************************** 項目名稱:BMP085模塊硬件功能測試 目地:BMP085模塊硬件功能測試 模塊:基本組件,12864驅(qū)動,顯示驅(qū)動,iic驅(qū)動,bmp085驅(qū)動 功能: v0.0 讀取eeprom里面11個數(shù)據(jù),并且讀取大氣壓的值以2進制形式顯示出來 v0.1 讀取出當前氣壓值、氣溫、海拔高度,并且顯示出來 硬件要求: 主控芯片:STC89c52 測試電路板————普中科技51開發(fā)板 晶振:12.000mhz 作者 日期 備注 熊夢杰 2012/08/31 新增 熊孟杰 2012/09/01 修改 *********************************************************/#include"config.h"voidmain(){ LCD_Init(); DisplayLoading(); Init_BMP085(); for(;;) { Show_BMP085_Result(); }}/********************************************** 此頭文件干脆包含全部基本組件,便于管理、調(diào)用**********************************************/#ifndef__CONFIG_H#define__CONFIG_H#include<stc12c5a60s2.h>#include<intrins.h>#include<math.h> #include"LCD12864drive.h"#include"displaydrive.h"#include"components.h"#include"i2cdrive.h"#include"bmp085drive.h"http://typedefunsignedcharuchar;//typedefunsignedintuint;#endif/************************************************************************ 文件名:BMP085driver.c 函數(shù)功能:BMP085的基本操作函數(shù) 備注: 限制流程: 初始化(干脆讀取內(nèi)部11位eeprom數(shù)據(jù)) (1) 獲得大氣壓強未補償數(shù)據(jù)(發(fā)送限制指令-讀取數(shù)據(jù)) (2) 獲得當前氣溫值(發(fā)送限制指令-讀取數(shù)據(jù)) (3) 獲得海拔高度值(依據(jù)(2)(3)兩步得到的數(shù)據(jù)計算出結(jié)果) (4) 獲得海拔高度平均值(將(4)得到的數(shù)據(jù)分別放到10位數(shù)組中計算出平均值, 由于采納了1進1出的計算方式,因此該數(shù)據(jù)具有較好的實時性及線性效果(5) 顯示結(jié)果(通過lcd12864顯示測量結(jié)果) (6) 重復執(zhí)行步驟(2)(3)(4)(5)(6) ************************************************************************/#include"config.h" //定義傳感器內(nèi)部EEPROM存儲單元里面11個值intidataAC1,AC2,AC3,B1,B2,MC,MD;unsignedintidataAC4,AC5,AC6;unsignedcharidataAltitudeTempFlag; //計算海拔高度運用到的數(shù)據(jù)標記intidataAltitudeTemp[10]={0,0,0,0,0,0,0,0,0,0}; //海拔高度的10個臨時值,取平均值unsignedcharcodePressureTitle[16]={"氣壓溫度測量"};unsignedcharidataShowPressure[16]={"氣壓:pa"};unsignedcharidataShowTemperature[16]={"溫度:.℃"};unsignedcharidataShowAltitude[16]={"海拔:.米"};/****************************************************************函數(shù)名稱:BMP085_Read_2Byte函數(shù)功能:從BMP085讀出2字節(jié)數(shù)據(jù)入口參數(shù):add //寄存器地址出口參數(shù):讀取的數(shù)據(jù)備注:*****************************************************************/ intBMP085_Read_2Byte(ucharadd){ ucharmsb,lsb; intdat;Start_I2c(); //起始信號Send_Byte(BMP085_ADDWR); //發(fā)送設(shè)備地址+寫信號 if(ack==0)return(0);Send_Byte(add); //發(fā)送存儲單元地址 if(ack==0)return(0); Start_I2c(); //重復起始信號Send_Byte(BMP085_ADDWR+1); //發(fā)送設(shè)備地址+讀信號 if(ack==0)return(0);msb=RcvByte();Ack_I2c(0); //主機發(fā)送應答信號lsb=RcvByte(); Ack_I2c(1); //主機收到最終一張字節(jié)數(shù)據(jù)后發(fā)送非應答信號Stop_I2c(); //停止信號DelayMs(5);dat=msb<<8; dat|=lsb; returndat; //返回接受到的兩字節(jié)數(shù)據(jù)}/****************************************************************函數(shù)名稱:BMP085_Get_UT函數(shù)功能:讀出未補償?shù)臏囟戎等肟趨?shù):無出口參數(shù):未補償?shù)臏囟戎祩渥ⅲ?****************************************************************/longBMP085_Get_UT(void){Start_I2c(); //起始信號Send_Byte(BMP085_ADDWR); //發(fā)送設(shè)備地址+寫信號Send_Byte(CTRL_REG_ADD); //writeregisteraddressSend_Byte(0X2E); //writeregisterdatafortempStop_I2c(); //發(fā)送停止信號 DelayMs(CONVERSION_TIME); //AD轉(zhuǎn)換時間,溫度最大轉(zhuǎn)換時間為4.5ms return(long)BMP085_Read_2Byte(0xF6);}/****************************************************************函數(shù)名稱:BMP085_Get_UP函數(shù)功能:讀出未補償?shù)臍鈮褐等肟趨?shù):無出口參數(shù):未補償?shù)臍鈮褐祩渥ⅲ?****************************************************************/longBMP085_Get_UP(void){ longpressure=0;Start_I2c(); //起始信號Send_Byte(BMP085_ADDWR); //發(fā)送設(shè)備地址+寫信號Send_Byte(CTRL_REG_ADD); //writeregisteraddressSend_Byte(0X34); //低功耗模式指令Stop_I2c(); //發(fā)送停止信號 DelayMs(CONVERSION_TIME); //低功耗模式下氣壓最大轉(zhuǎn)換時間為4.5ms pressure=BMP085_Read_2Byte(0xF6); pressure&=0x00FFFF; returnpressure; }/****************************************************************函數(shù)名稱:Init_BMP085函數(shù)功能:初始化BMP085,讀出內(nèi)部標定參數(shù)入口參數(shù):無出口參數(shù):無備注: *****************************************************************/voidInit_BMP085(){ AC1=BMP085_Read_2Byte(0xAA); AC2=BMP085_Read_2Byte(0xAC); AC3=BMP085_Read_2Byte(0xAE); AC4=BMP085_Read_2Byte(0xB0); AC5=BMP085_Read_2Byte(0xB2); AC6=BMP085_Read_2Byte(0xB4); B1=BMP085_Read_2Byte(0xB6); B2=BMP085_Read_2Byte(0xB8);// MB=BMP085_Read_2Byte(0xBA); MC=BMP085_Read_2Byte(0xBC); MD=BMP085_Read_2Byte(0xBE);}/****************************************************************函數(shù)名稱:BMP085_Get_Param函數(shù)功能:從BMP085讀出轉(zhuǎn)換后的溫度或氣壓值入口參數(shù):choice//bit選擇讀取溫度或氣壓,當choice=0時,返回溫度 當choice=1時,返回氣壓出口參數(shù):temperature或pressure//long類型4字節(jié)備注:返回的溫度值為0.1℃,調(diào)用時轉(zhuǎn)換成1℃。氣壓值為Pa,調(diào)用時轉(zhuǎn)換為hPa*****************************************************************/longBMP085_Get_Param(bitchoice){ longUT; longUP; longX1,X2,B5,B6,X3,B3,p; unsignedlongB4,B7; longtemperature; longpressure; UT=BMP085_Get_UT(); //讀取未補償?shù)臏囟?UP=BMP085_Get_UP(); //讀取未補償?shù)膲簭? X1=((long)UT-AC6)*AC5>>15; //依據(jù)芯片手冊供應的公式計算補償后的溫度值 X2=((long)MC<<11)/(X1+MD); B5=X1+X2; temperature=(B5+8)>>4; if(choice==0) return(long)temperature; //返回溫度值,0.1℃ B6=B5-4000; //依據(jù)芯片手冊供應的公式計算補償后的氣壓值 X1=(B2*(B6*B6>>12))>>11; X2=AC2*B6>>11; X3=X1+X2; B3=(((long)AC1*4+X3)+2)/4; X1=AC3*B6>>13; X2=(B1*(B6*B6>>12))>>16; X3=((X1+X2)+2)>>2; B4=(AC4*(unsignedlong)(X3+32768))>>15; B7=((unsignedlong)UP-B3)*(50000); if(B7<0x80000000) p=(B7*2)/B4; else p=(B7/B4)*2; X1=(p>>8)*(p>>8); X1=(X1*3038)>>16; X2=(-7357*p)>>16; pressure=p+((X1+X2+3791)>>4); return(long)pressure; //返回氣壓值,Pa}/****************************************************************函數(shù)名稱:BMP085_Get_Altitude 函數(shù)功能:獲得海拔高度值入口參數(shù):無出口參數(shù):altitude//int型2字節(jié),當前海拔高度值備注: 返回的高度值單位為厘米,調(diào)用時再換算成帶小數(shù)的以米為單位的高度值*****************************************************************/intBMP085_Get_Altitude(){ floatpressure; floataltitude; pressure=(float)BMP085_Get_Param(1); //獲得氣壓值 altitude=44330*(1-pow(pressure/101325,1/5.255)); //依據(jù)芯片手冊供應的公式計算海拔高度 altitude*=100; //轉(zhuǎn)換成厘米單位的高度值,調(diào)用時再換算成帶小數(shù)的高度值,提高精度 return(int)altitude;}/****************************************************************函數(shù)名稱:ConvPressure() 函數(shù)功能:轉(zhuǎn)換氣壓入口參數(shù):無出口參數(shù):無備注:將得到數(shù)據(jù)轉(zhuǎn)化成lcd的數(shù)據(jù),便于顯示 *****************************************************************/voidConvPressure(){ longPressure; Pressure=BMP085_Get_Param(1); if(Pressure>=0)ShowPressure[5]='+'; else //假如海拔高度是一個負數(shù),要先取反 { ShowPressure[5]='-'; Pressure=~Pressure; } ShowPressure[6]=Pressure/1000000+0x30; ShowPressure[7]=Pressure%1000000/100000+0x30; ShowPressure[8]=Pressure%100000/10000+0x30; ShowPressure[9]=Pressure%10000/1000+0x30; ShowPressure[11]=Pressure%1000/100+0x30; ShowPressure[12]=Pressure%100/10+0x30; ShowPressure[13]=Pressure%10+0x30;}/****************************************************************函數(shù)名稱:ConvTemperature() 函數(shù)功能:轉(zhuǎn)換氣溫入口參數(shù):無出口參數(shù):無備注:將得到數(shù)據(jù)轉(zhuǎn)化成lcd的數(shù)據(jù),便于顯示 *****************************************************************/voidConvTemperature(){ intTemperature; Temperature=(int)BMP085_Get_Param(0); if(Temperature>=0)ShowTemperature[6]='+'; else //假如海拔高度是一個負數(shù),要先取反 { ShowTemperature[6]='-'; Temperature=~Temperature; } ShowTemperature[8]=Temperature/10000+0x30; ShowTemperature[9]=Temperature%10000/1000+0x30; ShowTemperature[10]=Temperature%1000/100+0x30; ShowTemperature[11]=Temperature%100/10+0x30; ShowTemperature[13]=Temperature%10+0x30;}/****************************************************************函數(shù)名稱:ConvAltitude() 函數(shù)功能:轉(zhuǎn)換海拔高度入口參數(shù):無出口參數(shù):無備注:將得到數(shù)據(jù)轉(zhuǎn)化成lcd的數(shù)據(jù),便于顯示 *****************************************************************/voidConvAltitude(){ longAltitude; //海拔高度 unsignedcharTempnum; //臨時值 Altitude=BMP085_Get_Altitude(); if(Altitude>=0)ShowAltitude[6]='+'; else //假如海拔高度是一個負數(shù),要先取反 { ShowAltitude[6]='-'; Altitude=~Altitude; }/**************取10次測量值的平均值作為測量結(jié)果,此算法存在記憶效果*************/ AltitudeTempFlag++; //標記自加 if(AltitudeTempFlag>=10)AltitudeTempFlag=0; AltitudeTemp[AltitudeTempFlag]=Altitude; //依據(jù)標記保存數(shù)據(jù)到數(shù)組 for(Tempnum=0;Tempnum<10;Tempnum++)Altitude+=AltitudeTemp[Tempnum]; //由于Altitude的值還保留著, //所以相加10個數(shù)之后應當除以11 Altitude/=11; //計算出平均值/*********************************************************************/ ShowAltitude[8]=Altitude/10000+0x30; ShowAltitude[9]=Altitude%10000/1000+0x30; ShowAltitude[10]=Altitude%1000/100+0x30; ShowAltitude[12]=Altitude%100/10+0x30; ShowAltitude[13]=Altitude%10+0x30;}/****************************************************************函數(shù)名稱:Show_BMP085_Result() 函數(shù)功能:顯示測量結(jié)果入口參數(shù):無出口參數(shù):備注: *****************************************************************/voidShow_BMP085_Result(){ ConvPressure(); //氣壓轉(zhuǎn)換 ConvTemperature(); //氣溫轉(zhuǎn)換 ConvAltitude(); //海拔轉(zhuǎn)換 WordDisplay(1,0,PressureTitle,12); //氣壓溫度測量 WordDisplay(0,1,ShowPressure,16); //氣壓 pa WordDisplay(0,2,ShowTemperature,16); //溫度 C WordDisplay(0,3,ShowAltitude,16); //海拔 米}/******************************************************** 文件名:BMP085driver.h 函數(shù)功能:BMP085的基本操作函數(shù) 入口參數(shù):iicdriver全部外部接口函數(shù) (由于將顯示結(jié)果函數(shù)也放在了該文件里面,所以還調(diào)用了WordDisplay(X,X,X,X)函數(shù)) 出口參數(shù): Init_BMP085(); 傳感器初始化 Show_BMP085_Result();顯示測量結(jié)果 備注:*****************************************************************/#ifndef__BMP085_H__#define__BMP085_H__#defineucharunsignedchar#defineuintunsignedint#defineCONVERSION_TIME5 //定義最大轉(zhuǎn)換時間為5ms#define BMP085_ADDWR0xee //定義傳感器硬件寫地址#defineCTRL_REG_ADD0xf4 //定義內(nèi)部限制寄存器地址externvoidInit_BMP085(); //BMP085的初始化函數(shù)作為外部函數(shù)運用externvoidShow_BMP085_Result();#endif/**************************************** 本文件包含基本組件函數(shù)******************/#include"config.h"unsignedcharTaskFlag;/**************************************************** 功能:毫秒級別的延時函數(shù) 輸入:延時毫秒的數(shù)值 輸出:無*****************************************************///voidDelayMs(unsignedintms) //stc12c5a60s222.1184mhz//{ // unsignedinta,b,c;//for(c=ms;c>0;c--)//for(b=170;b>0;b--)//for(a=31;a>0;a--);//}voidDelayMs(unsignedintms)//stc89c5212.000mhz誤差-0.651041666667us{unsignedinta,b; for(b=4*ms;b>0;b--) for(a=113;a>0;a--);}/**************************************************** 功能:多個任務(wù)之間相互交換 輸入:微秒延時的數(shù)值 輸出:無*****************************************************///voidDelay2Us(unsignedintus) //stc12c5a60s222.1184mhz//{//unsignedinta;//for(a=8*us;a>0;a--); //}voidDelay8Us(unsignedintus) //stc89c5212.000mhz{unsignedchara;for(a=us;a>0;a--);_nop_();//ifKeil,requireuseintrins.h }/********************************************************** 文件名:components.h 系統(tǒng)組件程序 功能說明:包含了常用的基本函數(shù)以及基本的輸入輸出接口 應用層次:底層系統(tǒng)組件**********************************************************//*****************編譯預處理******************************/#ifndef__COMPONENTS_H#define__COMPONENTS_H/******************基本輸入輸出接口***********************/sbitKEY0=P1^5;/******************全局變量聲明**********************//******************外部函數(shù)聲明**********************/externvoidDelayMs(unsignedintms); //僅僅適用于stc12c5a60s222.1184mhz晶振externvoidDelay8Us(unsignedintus); //僅僅適用于stc12c5a60s222.1184mhz晶振#endif/*********************************************** 顯示驅(qū)動文件************************************************/#include"config.h"unsignedcharcodeOnePiece[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x12,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x7F,0x07,0x80,0x00,0x00,0x00,0x00,0x00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7,0xF0,0x0F,0x80,0x00,0x00,0x1C,0xDF,0xDF,0xC9,0xFB,0xFF,0xF9,0xF3,0x73,0xFF,0xE3,0xE0,0x1F,0xC0,0x00,0x00,0x20,0x9E,0x7B,0xE4,0x20,0x3F,0x00,0x0F,0x80,0x03,0xE0,0x00,0x1D,0x00,0x00,0x00,0x11,0xFF,0x07,0xFE,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x05,0xE0,0x00,0x1F,0xF8,0x00,0xFE,0x00,0x7F,0x00,0x3E,0x01,0xF0,0x00,0x00,0x00,0x07,0xE0,0x00,0x03,0xF0,0x00,0x7C,0x00,0x3F,0x00,0x0F,0x87,0xC0,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x18,0x00,0x0C,0x00,0x07,0xFF,0x80,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*D:\Documents\MyPictures\logoico\monochrome\onepiece12864.bmp*/};/********************************************************************************************************/unsignedcharcodeHaiZeiWang0[10]={"我是要成為"};unsignedcharcodeHaiZeiWang1[12]={"海賊王的男人"};unsignedcharcodeBlank[16]={""};/******************************************************************************************************/voidPictureDisplay(unsignedchar*Bmp){ unsignedchari,j; LCD_WCMD(Expand); //選擇限制指令集為擴展指令 LCD_WCMD(0x34); //擴展指令集關(guān)閉顯示 for(i=0;i<32;i++) { LCD_WCMD(0x80+i); LCD_WCMD(0x80); for(j=0;j<16;j++) LCD_WData(*Bmp++); } for(i=0;i<32;i++) { LCD_WCMD(0x80+i); LCD_WCMD(0x88); for(j=0;j<16;j++) LCD_WData(*Bmp++); } LCD_WCMD(0x36); //擴展指令集打開顯示}/*********************************************** 功能:文字顯示函數(shù) 形式參數(shù)格式規(guī)定: x軸位置,從左到右,以兩個字符或一個漢字作為一格取值范圍(0~7) y軸位置,從上倒下,以一個漢字作為一格,取值范圍(0~3) 數(shù)組名稱,將數(shù)組的值以指針形式訪問 顯示數(shù)量,將數(shù)組里面的指定數(shù)量的內(nèi)容顯示出來,取值范圍(0~15)(事實上在程序內(nèi)部已經(jīng)防止了數(shù)據(jù)溢出,此處可以不上限)************************************************/voidWordDisplay(unsignedcharX,unsignedcharY,unsignedchar*Word,unsignedcharQuantity){ unsignedcharPos,i; LCD_WCMD(Normal); //選擇限制指令為基本指令集 if(Quantity+2*X>=16)Quantity=16-2*X; if(Y==0)Y=0x80; elseif(Y==1)Y=0x90; elseif(Y==2)Y=0x88; elseif(Y==3)Y=0x98; Pos=X+Y; LCD_WCMD(Pos); for(i=0;i<Quantity;i++) { LCD_WData(*Word++); Delay8Us(50); }}voidDisplayLoading() //開機時候加載的一些小廣告{ PictureDisplay(OnePiece); DelayMs(400); LCD_ClrPicture(); WordDisplay(1,1,HaiZeiWang0,10); WordDisplay(1,2,HaiZeiWang1,12); DelayMs(400); LCD_ClrWords();}#ifndef__DISPLAYDRIVE_H#define__DISPLAYDRIVE_H#ifdef__cplusplusextern"C"{#endifvoidPictureDisplay(unsignedchar*Bmp);externunsignedcharcodeOnePiece[];externunsignedcharcodeHaiZeiWang0[10];externunsignedcharcodeHaiZeiWang1[12];externunsignedcharcodeBlank[16];voidWordDisplay(unsignedcharX,unsignedcharY,unsignedchar*Word,unsignedcharQuantity);voidDisplayLoading();//voidGeneralMode();#ifdef__cplusplus}#endif#endif#include"config.h"bitack;/****************************************************************函數(shù)名稱:Start_I2c函數(shù)功能:向I2c總線發(fā)出起始信號入口參數(shù):無出口參數(shù):備注:*****************************************************************/voidStart_I2c(){ SDA=1; _nop_(); SCL=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); SDA=0; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); SCL=0; _nop_(); _nop_();}/****************************************************************函數(shù)名稱:Stop_I2c函數(shù)功能:向I2c總線發(fā)出終止信號入口參數(shù):無出口參數(shù):備注:*****************************************************************/voidStop_I2c(){ SDA=0;/*發(fā)送結(jié)束條件的數(shù)據(jù)信號*/ _nop_();/*發(fā)送結(jié)束條件的時鐘信號*/ SCL=1;/*結(jié)束條件建立時間大于4μs*/ _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); SDA=1;/*發(fā)送I2C總線結(jié)束信號*/ _nop_(); _nop_(); _nop_(); _nop_(); SCL=0;}/****************************************************************函數(shù)名稱:Ack_I2c函數(shù)功能:向I2c總線發(fā)出應答信號入口參數(shù):無出口參數(shù):備注: 輸入0則表示應答,輸入1則表示非應答*****************************************************************/voidAck_I2c(bita){ if(a==0)SDA=0;/*在此發(fā)出應答或非應答信號*/ elseSDA=1; _nop_(); _nop_(); _nop_(); SCL=1; _nop_(); _nop_();/*時鐘低電平周期大于4μs*/ _nop_(); _nop_(); _nop_(); SCL=0;/*清時鐘線,鉗住I2C總線以便接著接收*/ _nop_(); _nop_(); if(a==0)SDA=1;/*在此發(fā)出應答或非應答信號*/ elseSDA=0;}/****************************************************************函數(shù)名稱:Send_Byte函數(shù)功能:發(fā)送一字節(jié)數(shù)據(jù)入口參數(shù):dat//要發(fā)送的8位數(shù)據(jù)出口參數(shù):ack//應答信號備注:*****************************************************************/unsignedcharSend_Byte(unsignedcharData){ unsignedcharBitLong; for(BitLong=0;BitLong<8;BitLong++)/*要傳送的數(shù)據(jù)長度為8位*/{ SDA=(bit)(Data&0x80); _nop_(); SCL=1;/*置時鐘線為高,通知被控器起先接收數(shù)據(jù)位*/ _nop_(); _nop_();/*保證時鐘高電平周期大于4μs*/ _nop_(); _nop_(); _nop_(); SCL=0; Data<<=1; } _nop_();_nop_();SDA=1;/*8位發(fā)送完后釋放數(shù)據(jù)線,打算接收應答位*/_nop_();_nop_();SCL=1;_nop_();_nop_();_nop_();if(SDA==1)ack=0; elseack=1;/*推斷是否接收到應答信號*/SCL=0;_nop_();_nop_(); returnack;}/****************************************************************函數(shù)名稱:Rcv_Byte函數(shù)功能:接收一字節(jié)數(shù)據(jù)入口參數(shù):無出口參數(shù):dat//將接收到出來的一字節(jié)數(shù)據(jù)賦給dat變量,并返回dat備注:*****************************************************************/unsignedcharRcvByte(){ unsignedcharData; unsignedcharBitLong; Data=0; SDA=1;/*置數(shù)據(jù)線為輸入方式*/ for(BitLong=0;BitLong<8;BitLong++) {SCL=1;/*置時鐘線為高使數(shù)據(jù)線上數(shù)據(jù)有效*/_nop_();_nop_();Data<<=1; Data|=SDA;//if(SDA==1)Data=Data+1;/*讀數(shù)據(jù)位,接收的數(shù)據(jù)位放入Data中*/_nop_(); _nop_(); SCL=0; _nop_(); _nop_(); } SCL=0; _nop_(); _nop_(); return(Data);}#ifndef__I2CDRIVE_H__#define__I2CDRIVE_H__sbitSCL=P1^0;sbitSDA=P1^1;externbitack;voidStart_I2c();voidStop_I2c();voidAck_I2c(bita); //輸入0則表示應答,輸入1則表示非應答voidNoAck_I2c();unsignedcharSend_Byte(unsignedchardat);unsignedcharRcvByte();#endif#include"config.h"/******************************************** 功能:液晶的繁忙狀態(tài)監(jiān)測,假如液晶處于繁忙,則無法操作 輸入:無 輸出:位型的繁忙標記信息********************************************/bitLCD_BusyTest(){ bitResult; LCD_RS=Choose_CMD; LCD_RW=Read; LCD_EN=Active; Delay8Us(1); Result=(bit)(LCD_DataPort&0x80); LCD_EN=Inactive; return(Result);}/********************************************** 功能:液晶的寫指令操作函數(shù) 輸入:液晶的限制指令 輸出:無*********************************

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論