2012“TI”杯電子設(shè)計競賽D題聲音定位系統(tǒng)設(shè)計報告_第1頁
2012“TI”杯電子設(shè)計競賽D題聲音定位系統(tǒng)設(shè)計報告_第2頁
2012“TI”杯電子設(shè)計競賽D題聲音定位系統(tǒng)設(shè)計報告_第3頁
2012“TI”杯電子設(shè)計競賽D題聲音定位系統(tǒng)設(shè)計報告_第4頁
2012“TI”杯電子設(shè)計競賽D題聲音定位系統(tǒng)設(shè)計報告_第5頁
已閱讀5頁,還剩65頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

70聲音定位系統(tǒng)設(shè)計報告2012年“TI”杯四川省電子設(shè)計競賽聲音定位系統(tǒng)(D題)競賽選題:聲音定位系統(tǒng)(D題)學(xué)校:西南石油大學(xué)參賽隊員:楊杰劉德雄康敏

摘要本設(shè)計采用TI公司生產(chǎn)的超低功耗單片機MSP430G2452和G2553分別作為定位系統(tǒng)的聲源產(chǎn)生模塊和信息處理模塊,實現(xiàn)了聲音信號的發(fā)生、信號收集處理和屏幕顯示以及語音提示等功能。該設(shè)計采用2節(jié)家用1.5V電池供電,實現(xiàn)了低功耗狀況下的聲音定位系。聲源接收單元信號反應(yīng)靈敏,能較準(zhǔn)確的得到信號并及時傳送到信號處理單元。以MSP430為主的Launchpad也符合了低功耗的標(biāo)準(zhǔn),并且可以實現(xiàn)信號的運算處理以及控制LCD液晶屏幕顯示測試數(shù)據(jù)。在定位算法上采用的是歸一正方形算法。通過調(diào)試修正以后,能實現(xiàn)基本的聲源定位并顯示。關(guān)鍵詞:聲音定位低功耗MSP430目錄一.引言……………31.1主要任務(wù)………………………31.2設(shè)計要求………………………4二.方案設(shè)計與論證………………42.1方案對比………………………42.1.1聲源模塊……………………52.1.2接收模塊放大芯片…………52.1.3單片機MCU…………………62.1.4顯示模塊……………………72.1.5定位算法選擇………………8三.硬件電路設(shè)計…………………93.1系統(tǒng)框圖………………………93.2聲響模塊………………………103.3從單片機最小系統(tǒng)……………103.4聲音接收模塊…………………113.5信號處理模塊…………………123.6語音模塊………………………12四.軟件設(shè)計………………………124.1軟件流程圖……………………13五.測試結(jié)果與分析………………145.1測試方法與儀器………………155.2測試數(shù)據(jù)………………………155.3測試結(jié)果分析…………………155.4測試結(jié)果………………………15參考文獻(xiàn)……………16附錄一:……………17附錄二:……………18附錄三:……………19一、引言1.1主要任務(wù)設(shè)計一套聲音定位系統(tǒng)。在一塊不大于1m2的平板上貼一張500mm×350mm的坐標(biāo)紙,在其四角外側(cè)分別固定安裝一個聲音接收模塊,聲音接收模塊通過導(dǎo)線將聲音信號傳輸?shù)叫畔⑻幚砟K,聲音定位系統(tǒng)根據(jù)聲響模塊通過空氣傳播到各聲音接收模塊的聲音信號,判定聲響模塊所在的位置坐標(biāo)。系統(tǒng)結(jié)構(gòu)示意圖如圖1圖1聲音定位系統(tǒng)結(jié)構(gòu)示意圖1.2設(shè)計要求【1】.基本要求(1)設(shè)計制作一個聲響模塊,含信號產(chǎn)生電路、放大電路和微型揚聲器等,每按鍵一次發(fā)聲一次,聲音信號的基波頻率為500Hz左右,聲音持續(xù)時間約為1s。要求聲響模塊采用3V以下電池供電,功耗不大于200mW。(2)設(shè)計制作四路聲音接收模塊,由麥克風(fēng)、放大電路等組成,并分別與信息處理模塊相連接,以便將頻率為500Hz左右的信號傳送至信息處理模塊。(3)設(shè)計制作一個信息處理模塊,要求該模塊能根據(jù)從聲音接收模塊傳來的信號判斷聲響模塊所在位置的x、y坐標(biāo),并以數(shù)字形式顯示x、y坐標(biāo)值,位置坐標(biāo)值誤差的絕對值不大于30mm。【2】.發(fā)揮部分(1)改善接收信號的放大電路性能,改進算法,進一步提高定位精度。(2)控制聲響模塊以不間斷的連續(xù)周期波的形式發(fā)出聲音信號,其基波頻率為500Hz左右。當(dāng)聲響模塊在坐標(biāo)紙上移動時,聲音定位系統(tǒng)能連續(xù)跟蹤顯示聲響模塊的x、y坐標(biāo)值,隨機停止聲響模塊的移動,能立即穩(wěn)定地顯示聲響模塊的x、y坐標(biāo)值,誤差的絕對值不大于10(3)具有顯示聲響模塊移動軌跡的功能。當(dāng)聲響模塊在坐標(biāo)紙上按指定路徑移動時,液晶顯示屏能動態(tài)顯示聲響模塊移動的軌跡,顯示的軌跡與聲響模塊移動的路徑一致。(4)其它。方案設(shè)計與論證2.1方案對比本設(shè)計分以下幾個模塊組成:聲響模塊、聲音接受模塊、信號處理模塊?,F(xiàn)對模塊的選用方案進行論證。2.1.1聲源模塊設(shè)計要求聲響模塊采用3V以下電池供電,功耗不大于200mW。方案一:有源蜂鳴器蜂鳴器是一種一體化結(jié)構(gòu)的電子訊響器,采用直流電壓供電,廣泛應(yīng)用于計算機、打印機、復(fù)印機、報警器、電子玩具、汽車電子設(shè)備、電話機、定時器等電子產(chǎn)品中作發(fā)聲器件。方案二:無源蜂鳴器有源和無源的區(qū)別:這里的“源”不是指電源。而是指震蕩源。也就是說,有源蜂鳴器內(nèi)部帶震蕩源,所以只要一通電就會叫。而無源內(nèi)部不帶震蕩源,所以如果用直流信號無法令其鳴叫。必須用2K~5K的方波去驅(qū)動它。有源蜂鳴器往往比無源的貴,就是因為里面多個震蕩電路。方案三:喇叭8歐0.5瓦喇叭價格實惠,聲音響亮,聲音純度較高,并且完全滿足本次設(shè)計的需求,故本次采用的是喇叭作為發(fā)聲源。綜上所述,選取便宜可控的喇叭更符合設(shè)計需要。2.1.2接收模塊放大芯片方案一:LM358LM358內(nèi)部包括有兩個獨立的、高增益、內(nèi)部頻率補償?shù)碾p運算放大器,適合于電源電壓范圍很寬的單電源使用,也適用于雙電源工作模式,在推薦的工作條件下,電源電流與電源電壓無關(guān)。它的使用范圍包括傳感放大器、直流增益模塊和其他所有可用單電源供電的使用運算放大器的場合。圖2lm358結(jié)構(gòu)圖方案二:LM368LM386是美國國家半導(dǎo)體公司生產(chǎn)的音頻功率放大器,主要應(yīng)用于低電壓消費類產(chǎn)品。為使外圍元件最少,電壓增益內(nèi)置為20。但在1腳和8腳之間增加一只外接電阻和電容,便可將電壓增益調(diào)為任意值,直至200。輸入端以地為參考,同時輸出端被自動偏置到電源電壓的一半,在6V電源電壓下,它的靜態(tài)功耗僅為24mW,使得LM386特別適用于電池供電的場合。圖3lm386管腳圖方案三:LM393LM393是高增益,寬頻帶器件,象大多數(shù)比較器一樣,如果輸出端到輸入端有寄生電容而產(chǎn)生耦合,則很容易產(chǎn)生振蕩。這種現(xiàn)象僅僅出現(xiàn)在當(dāng)比較器改變狀態(tài)時,輸出電壓過渡的間隙,電源加旁路濾波并不能解決這個問題,標(biāo)準(zhǔn)PC板的設(shè)計對減小輸入—輸出寄生電容耦合是有助的。減小輸入電阻至小于10K將減小反饋信號,而且增加甚至很小的正反饋量(滯回1.0~10mV)能導(dǎo)致快速轉(zhuǎn)換,使得不可能產(chǎn)生由于寄生電容引起的振蕩,除非利用滯后,否則直接插入IC并在引腳上加上電阻將引起輸入—輸出在很短的轉(zhuǎn)換周期內(nèi)振蕩,如果輸入信號時脈沖波形,并且上升和下降時間相當(dāng)快,則滯回將不需要。圖4lm393管腳圖由于接收信號微弱,要得到更精準(zhǔn)的聲源信號,選取了工作電源范圍更寬、輸入失調(diào)電壓更小的LM393。2.1.3單片機MCU方案一:MSP430MSP430系列單片機是美國德州儀器公司(TI)1996年開始推向市場的一種16位超低功耗、具有精簡指令集的混合信號處理器。稱之為混合信號處理器,是由于其針對實際應(yīng)用需求,將多個不同功能的模擬電路、數(shù)字電路模塊和微處理器集成在一個芯片上,以提供“單片機”解決方案。該系列單片機多應(yīng)用于需要電池供電的便攜式儀器儀表中。方案二:AT89C51AT89C51是一種帶4K字節(jié)FLASH存儲器的低電壓、高性能CMOS8位微處理器,俗稱單片機。AT89C2051是一種帶2K字節(jié)閃存可編程可擦除只讀存儲器的單片機。單片機的可擦除只讀存儲器可以反復(fù)擦除1000次。該器件采用ATMEL高密度非易失存儲器制造技術(shù)制造,與工業(yè)標(biāo)準(zhǔn)的MCS-51指令集和輸出管腳相兼容。由于將多功能8位CPU和閃爍存儲器組合在單個芯片中,ATMEL的AT89C51是一種高效微控制器,AT89C2051是它的一種精簡版本。AT89C51單片機為很多嵌入式控制系統(tǒng)提供了一種靈活性高且價廉的方案。設(shè)計需要2片MCU,都采用TI公司提供的MSP430G2xxx系列芯片。其中聲源產(chǎn)生模塊選用以MSP430G2452為核心的單片機最小系統(tǒng);信息處理系統(tǒng)采用MSP430G2553為主的Launchpad作為數(shù)據(jù)處理和顯示模塊控制。2.1.4顯示模塊方案一:LCD12864LCD12864為帶中文字庫的128X64是一種具有4位/8位并行、2線或3線串行多種接口方式,內(nèi)部含有國標(biāo)一級、二級簡體中文字庫的點陣圖形液晶顯示模塊。其顯示分辨率為128×64,內(nèi)置8192個16*16點漢字,和128個16*8點ASCII字符集.利用該模塊靈活的接口方式和簡單方便的操作指令,可構(gòu)成全中文人機交互圖形界面??梢燥@示8×4行16×16點陣的漢字.也可完成圖形顯示.低電壓低功耗是其又一顯著特點。由該模塊構(gòu)成的液晶顯示方案與同類型的圖形點陣液晶顯示模塊相比,不論硬件電路結(jié)構(gòu)或顯示程序都要簡潔得多,且該模塊的價格也略低于相同點陣的圖形液晶模塊。方案二:LED顯示屏LED顯示屏:又稱電子顯示屏或者飄字屏幕。是由LED點陣列和ledpc面板組成,通過紅色,藍(lán)色,綠色LED燈的亮滅來顯示文字、圖片、動畫、視頻,內(nèi)容可以隨時更換,各部分組件都是模塊化結(jié)構(gòu)的顯示器件。傳統(tǒng)LED顯示屏通常由顯示模塊、控制系統(tǒng)及電源系統(tǒng)組成。顯示模塊由LED燈組成的點陣構(gòu)成,負(fù)責(zé)發(fā)光顯示;控制系統(tǒng)通過控制相應(yīng)區(qū)域的亮滅,可以讓屏幕顯示文字、圖片、視頻等內(nèi)容,單色、雙色屏主要用來播放文字的,全彩屏主要是播放動畫的;電源系統(tǒng)負(fù)責(zé)將輸入電壓電流轉(zhuǎn)為顯示屏需要的電壓電流。本次大賽要求的是128*64以上分辨率的顯示屏,所以選擇LCD12864就能滿足設(shè)計要求。并且自帶字庫,簡單方便。故本設(shè)計采用LCD顯示屏。2.1.5定位算法選擇方案一:直角坐標(biāo)系法直接采用三個點定位的方法,利用函數(shù)關(guān)系式算出坐標(biāo)。如圖:圖5直角坐標(biāo)系法測距根據(jù)距離不同,接收聲源就會產(chǎn)生時間差,兩個時間差,兩個變量,故可以求出(x,y)的坐標(biāo)值。x√((x其中c=340m/s。這種方法雖然思路簡單,但是運算量大,將會影響單片機運算速度,增加我們的運算難度,故不采用。方案二:歸一化正方形陣圖6歸一化正方形歸一化正方形算法如圖,傳感器陣列采用正方形,傳感器的位置坐標(biāo)為(L,L),(-L,L),(-L,-L),(L,-L)。則聲源位置(x,y)可由下式算出(式中2L為正方陣的邊長,Δt1,Δt2,Δt3分別為傳感器2,3,4相對于1的時差,c是傳播速度):

三.硬件電路設(shè)計3.1系統(tǒng)框圖聲響模塊從單片機聲響模塊從單片機聲音接收聲音接收LCD顯示LCD顯示主單片機主單片機語音播報控制語音播報控制圖7系統(tǒng)總框圖系統(tǒng)主要由三大模塊組成:聲響模塊、聲音接收模塊、信號處理模塊。聲響模塊產(chǎn)生聲音信號,由聲音接收模塊接收信號并產(chǎn)生電流脈沖,經(jīng)總線系統(tǒng)傳送到信號處理模塊進行運算處理,將測試數(shù)據(jù)顯示在LCD顯示屏上。系統(tǒng)總電路圖見附錄二。3.2聲響模塊圖8聲響模塊電路圖通過單片機產(chǎn)生500Hz的方波信號,利用單管放大后給喇叭發(fā)聲。其中電位器可對音量進行調(diào)節(jié)。3.3從單片機最小系統(tǒng)圖9從單片機最小系統(tǒng)單片機最小系統(tǒng)采用的是TI公司生產(chǎn)的超低功耗的MSP430G2452單片機為核心,其中9號端口為P2.1,實際電路中需和聲源模塊相連接。3.4聲音接收模塊圖10接收系統(tǒng)模塊電路3.5信號處理模塊信號處理模塊由總線控制單元,MSP430G2553為核的Launchpad以及LCD顯示屏共同組成。單片機內(nèi)部運算處理后將結(jié)果送入LCD顯示。圖11主單片機及顯示3.6語音模塊采用ISD4004語音錄放芯片制作成語音播報模塊。利用lm386語音功放芯片放大。四.軟件設(shè)計4.1軟件流程圖設(shè)計采用MSP430G2553為核心的Launchpad負(fù)責(zé)信號的處理并控制LCD顯示屏顯示相應(yīng)數(shù)據(jù)。主程序流程圖如下:開始開始初始化初始化MCU初始化初始化LCD接收信號接收信號進入中斷進入中斷數(shù)據(jù)處理數(shù)據(jù)處理退出中斷退出中斷LCDLCD顯示數(shù)據(jù)結(jié)束結(jié)束中斷流程圖:進入中斷進入中斷判斷先后判斷先后xyzj顯示數(shù)據(jù)顯示數(shù)據(jù)讀取坐標(biāo)讀取坐標(biāo)退出中斷退出中斷中斷程序開始后,系統(tǒng)首先對聲音接收模塊采集到的信息進行判斷,找到距離聲源最近的接收器,再按時間差分別得出其它3個接收器的距離差,再通過單片機就可以計算出聲源所在位置,發(fā)出屏幕顯示數(shù)據(jù)后退出中斷。額外加入了語音播報裝置,在每次采集測試數(shù)據(jù)開始和結(jié)束都會進行一次自動語音播報。五.測試結(jié)果與分析5.1測試方法與儀器先測試4個定點(分別為(10,10)(45,10)(10,25)(45,25))來標(biāo)定4個聲音接收模塊的精度等級,然后采取隨機取點方式得到測試數(shù)據(jù)。測試中主要用到的儀器有直流穩(wěn)壓電源,示波器等。5.2測試數(shù)據(jù)選中坐標(biāo)接收時間差測試坐標(biāo)誤差(cm)xyzj(35,15)3611383471(39,15)4(25,1023,12)3(40,20)564135210(39,20)1(15,15)13775295(21,17)5(25,1523,12)3測試數(shù)據(jù)5.3測試結(jié)果分析測試平均誤差在5cm以內(nèi),部分坐標(biāo)點能達(dá)到3cm標(biāo)準(zhǔn),符合設(shè)計要求。5.4測試結(jié)果本設(shè)計制作完成了題目要求的基本部分的全部要求和發(fā)揮部分的大部分要求,達(dá)到設(shè)計要求。個別指標(biāo)由于時間有限只完成相應(yīng)的軟件和硬件設(shè)計,整體調(diào)試還未能全部完成。參考文獻(xiàn)[1]范紅剛,魏學(xué)海,陳和.51單片機自學(xué)筆記;北京,北京航空航天大學(xué)出版社2010年1月第1版[2]王宜懷,曹金華.嵌入式系統(tǒng)設(shè)計實戰(zhàn);北京,北京航空航天大學(xué)出版社2011年5月第1版[3]聞怡洋.無線設(shè)備編程指南;北京,北京大學(xué)出版社2004年7月第1版[4]李玉柏.最小系統(tǒng)設(shè)計與應(yīng)用;四川,電子科技大學(xué)出版社2012年4月第1版[5]鐘洪聲.電子電路設(shè)計技術(shù)基礎(chǔ);四川,電子科技大學(xué)出版社2012年4月第1版[6]王昊,李昕.集成運放應(yīng)用電路設(shè)計360例;北京,電子工業(yè)出版社2007年1月[7]喻金錢,喻斌.短距離無線通信詳解—基于單片機控制;北京,北京航空航天大學(xué)出版社2009年4月附錄一:元器件清單元器件名數(shù)量MSP430G25531片MSP430G24521片LP2950-33LPRE31片LM2577S1片LM3934片MIC4個BUZZER1個穩(wěn)壓管78051個LCD128641個電位器若干電阻若干電容若干電池2節(jié)電感2個附錄二:系統(tǒng)總電路圖附錄三:程序#include"msp430g2553.h"#include"math.h"#defineCS12864_SETP2OUT|=BIT0#defineCS12864_CLRP2OUT&=~BIT0#defineSID12864_SETP2OUT|=BIT1#defineSID12864_CLRP2OUT&=~BIT1#defineSCLK12864_SETP2OUT|=BIT2#defineSCLK12864_CLRP2OUT&=~BIT2signedints_1=0;signedints_2=0;unsignedcharss;unsignedchartank=0;unsignedcharstate=0;//4004unsignedinttime=0;unsignedchari;unsignedinttemp;#defineISD_SS_SET(P2OUT|=BIT4)#defineISD_SS_CLR(P2OUT&=~BIT4)#defineISD_SCK_SET(P2OUT|=BIT3)#defineISD_SCK_CLR(P2OUT&=~BIT3)#defineISD_MOSI_SET(P2OUT|=BIT5)#defineISD_MOSI_CLR(P2OUT&=~BIT5)//************************************//ISD4002spi串行發(fā)送子程序,8位數(shù)據(jù)//************************************voidspi_send(unsignedcharisdx){ unsignedcharisx_counter; ISD_SS_CLR;//ss=0,打開spi通信端 ISD_SCK_CLR; for(isx_counter=0;isx_counter<8;isx_counter++)//先發(fā)低位再發(fā)高位,依次發(fā)送。 { if((isdx&0x01)==1) ISD_MOSI_SET; else ISD_MOSI_CLR; isdx=isdx>>1; ISD_SCK_SET; __delay_cycles(6); ISD_SCK_CLR; __delay_cycles(6); }}//********發(fā)送掉電指令,并延遲50msvoidisd_pd(void)//4004{ __delay_cycles(10000);spi_send(0x20);ISD_SS_SET;__delay_cycles(60000);spi_send(0x20);ISD_SS_SET;__delay_cycles(120000);}voidisd_stop()//4004{__delay_cycles(1000);/*spi_send(0);//發(fā)送放音起始地址低位__delay_cycles(3);spi_send(0);//發(fā)送放音起始地址高位__delay_cycles(3);*/spi_send(0x10);//發(fā)送setplay指令字節(jié)ISD_SS_SET;}voidisd_setplay(unsignedcharadl,unsignedcharadh)//4004{__delay_cycles(10000);spi_send(0x20);ISD_SS_SET;__delay_cycles(25000); __delay_cycles(1000); spi_send(adl);//發(fā)送放音起始地址低位 //__delay_cycles(3); spi_send(adh);//發(fā)送放音起始地址高位//__delay_cycles(3); spi_send(0xE0);//發(fā)送setplay指令字節(jié) ISD_SS_SET;__delay_cycles(20);spi_send(0xF0);//發(fā)送setplay指令字節(jié)ISD_SS_SET;}voidisd_rec(unsignedcharadl,unsignedcharadh)//4004//4004{__delay_cycles(10000);spi_send(0x20);ISD_SS_SET;__delay_cycles(25000);isd_stop();spi_send(0x20);ISD_SS_SET;__delay_cycles(50000); __delay_cycles(1000); spi_send(adl);//發(fā)送放音起始地址低位 spi_send(adh);//發(fā)送放音起始地址高位 spi_send(0xa0);//發(fā)送setplay指令字節(jié) ISD_SS_SET;__delay_cycles(20);spi_send(0xb0);//發(fā)送setplay指令字節(jié)ISD_SS_SET;}constunsignedchars1[51][36]={108,108,107,106,105,105,104,103,103,102,101,101,100,99,99,98,97,97,96,95,95,94,94,93,93,92,92,91,91,90,90,89,89,89,88,88,106,106,105,105,104,103,103,102,101,101,100,99,99,98,97,97,96,96,95,94,94,93,93,92,92,91,91,90,90,89,89,88,88,88,87,87,105,104,104,103,102,102,101,100,100,99,99,98,97,97,96,95,95,94,94,93,93,92,92,91,91,90,90,89,89,88,88,87,87,87,86,86,103,102,102,101,101,100,100,99,98,98,97,97,96,95,95,94,94,93,93,92,91,91,90,90,89,89,89,88,88,87,87,86,86,86,85,85,101,101,100,100,99,99,98,97,97,96,96,95,95,94,93,93,92,92,91,91,90,90,89,89,88,88,87,87,87,86,86,85,85,85,84,84,99,99,98,98,97,97,96,96,95,95,94,94,93,93,92,91,91,90,90,89,89,88,88,88,87,87,86,86,85,85,85,84,84,84,83,83,97,97,96,96,96,95,95,94,94,93,93,92,92,91,91,90,90,89,89,88,88,87,87,86,86,86,85,85,84,84,84,83,83,82,82,82,95,95,95,94,94,93,93,93,92,92,91,91,90,90,89,89,88,88,87,87,86,86,86,85,85,84,84,84,83,83,82,82,82,81,81,81,93,93,93,92,92,92,91,91,90,90,89,89,89,88,88,87,87,86,86,85,85,85,84,84,83,83,83,82,82,82,81,81,81,80,80,80,91,91,91,91,90,90,89,89,89,88,88,87,87,87,86,86,85,85,85,84,84,83,83,83,82,82,81,81,81,80,80,80,79,79,79,79,89,89,89,89,88,88,88,87,87,87,86,86,85,85,85,84,84,83,83,83,82,82,82,81,81,81,80,80,80,79,79,79,78,78,78,77,88,87,87,87,87,86,86,86,85,85,85,84,84,83,83,83,82,82,82,81,81,81,80,80,80,79,79,79,78,78,78,77,77,77,77,76,86,85,85,85,85,84,84,84,84,83,83,83,82,82,82,81,81,80,80,80,80,79,79,79,78,78,78,77,77,77,77,76,76,76,76,75,84,83,83,83,83,83,82,82,82,81,81,81,81,80,80,80,79,79,79,78,78,78,77,77,77,77,76,76,76,76,75,75,75,75,74,74,82,82,81,81,81,81,80,80,80,80,79,79,79,79,78,78,78,77,77,77,77,76,76,76,76,75,75,75,75,74,74,74,74,73,73,73,80,80,79,79,79,79,79,78,78,78,78,77,77,77,77,76,76,76,76,75,75,75,75,74,74,74,74,73,73,73,73,73,72,72,72,72,78,78,77,77,77,77,77,77,76,76,76,76,76,75,75,75,75,74,74,74,74,73,73,73,73,73,72,72,72,72,72,71,71,71,71,71,76,76,76,75,75,75,75,75,75,74,74,74,74,74,73,73,73,73,73,72,72,72,72,72,71,71,71,71,71,70,70,70,70,70,70,70,74,74,74,74,73,73,73,73,73,73,72,72,72,72,72,72,71,71,71,71,71,71,70,70,70,70,70,70,69,69,69,69,69,69,68,68,72,72,72,72,71,71,71,71,71,71,71,71,70,70,70,70,70,70,69,69,69,69,69,69,69,68,68,68,68,68,68,68,68,67,67,67,70,70,70,70,70,69,69,69,69,69,69,69,69,69,68,68,68,68,68,68,68,68,67,67,67,67,67,67,67,67,66,66,66,66,66,66,68,68,68,68,68,68,68,67,67,67,67,67,67,67,67,67,67,66,66,66,66,66,66,66,66,66,66,65,65,65,65,65,65,65,65,65,66,66,66,66,66,66,66,66,66,65,65,65,65,65,65,65,65,65,65,65,65,65,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,61,61,61,61,61,61,61,61,61,61,61,61,61,61,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,59,59,59,59,59,59,59,59,59,59,59,59,59,59,56,56,56,56,56,56,56,56,56,56,56,56,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,58,58,58,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,55,55,55,55,56,56,56,56,56,56,56,56,56,56,56,56,56,56,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,53,53,54,54,54,54,54,54,54,54,54,54,55,55,55,55,55,55,55,55,55,50,50,50,50,50,51,51,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,53,53,53,53,53,53,53,53,54,54,54,54,54,54,48,48,48,48,49,49,49,49,49,49,49,49,50,50,50,50,50,50,51,51,51,51,51,51,51,52,52,52,52,52,52,52,52,53,53,53,46,46,46,46,47,47,47,47,47,47,48,48,48,48,48,48,49,49,49,49,49,49,50,50,50,50,50,50,51,51,51,51,51,51,52,52,44,44,44,45,45,45,45,45,45,46,46,46,46,46,47,47,47,47,47,48,48,48,48,48,49,49,49,49,49,50,50,50,50,50,50,50,42,42,43,43,43,43,43,43,44,44,44,44,44,45,45,45,45,46,46,46,46,47,47,47,47,47,48,48,48,48,48,49,49,49,49,49,40,40,41,41,41,41,41,42,42,42,42,43,43,43,43,44,44,44,44,45,45,45,45,46,46,46,46,47,47,47,47,47,48,48,48,48,38,38,39,39,39,39,40,40,40,40,41,41,41,41,42,42,42,43,43,43,43,44,44,44,44,45,45,45,45,46,46,46,46,47,47,47,36,37,37,37,37,37,38,38,38,39,39,39,39,40,40,40,41,41,41,42,42,42,43,43,43,43,44,44,44,44,45,45,45,45,46,46,34,35,35,35,35,36,36,36,36,37,37,37,38,38,38,39,39,40,40,40,40,41,41,41,42,42,42,43,43,43,43,44,44,44,44,45,32,33,33,33,33,34,34,34,35,35,35,36,36,37,37,37,38,38,38,39,39,39,40,40,40,41,41,41,42,42,42,43,43,43,43,44,31,31,31,31,32,32,32,33,33,33,34,34,35,35,35,36,36,37,37,37,38,38,38,39,39,39,40,40,40,41,41,41,42,42,42,43,29,29,29,29,30,30,31,31,31,32,32,33,33,33,34,34,35,35,35,36,36,37,37,37,38,38,39,39,39,40,40,40,41,41,41,41,27,27,27,28,28,28,29,29,30,30,31,31,31,32,32,33,33,34,34,35,35,35,36,36,37,37,37,38,38,38,39,39,39,40,40,40,25,25,25,26,26,27,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,34,35,35,36,36,36,37,37,38,38,38,39,39,39,23,23,24,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,34,35,35,36,36,36,37,37,38,38,38,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,29,29,30,30,31,31,32,32,32,33,33,34,34,35,35,35,36,36,36,37,37,19,19,20,20,21,21,22,23,23,24,24,25,25,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,33,34,34,35,35,35,36,36,17,18,18,19,19,20,20,21,22,22,23,23,24,25,25,26,26,27,27,28,29,29,30,30,31,31,31,32,32,33,33,34,34,34,35,35,15,16,16,17,18,18,19,20,20,21,21,22,23,23,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,33,34,34,14,14,15,15,16,17,17,18,19,19,20,21,21,22,23,23,24,24,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,32,33,33,12,12,13,14,15,15,16,17,17,18,19,19,20,21,21,22,23,23,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,31,32,32,};constunsignedchars2[51][36]={93,92,90,88,86,84,82,80,78,77,75,73,71,69,67,65,63,61,59,57,55,53,51,49,47,45,43,42,40,38,36,34,32,30,28,27,93,91,89,87,86,84,82,80,78,76,74,73,71,69,67,65,63,61,59,57,55,53,51,49,47,46,44,42,40,38,36,34,33,31,29,27,92,90,89,87,85,83,82,80,78,76,74,72,70,69,67,65,63,61,59,57,55,53,51,50,48,46,44,42,40,38,37,35,33,31,30,28,91,90,88,87,85,83,81,80,78,76,74,72,70,68,67,65,63,61,59,57,55,53,52,50,48,46,44,42,40,39,37,35,33,32,30,29,91,89,88,86,84,83,81,79,77,76,74,72,70,68,66,65,63,61,59,57,55,54,52,50,48,46,44,43,41,39,37,36,34,32,31,29,90,89,87,86,84,82,81,79,77,75,74,72,70,68,66,65,63,61,59,57,55,54,52,50,48,46,45,43,41,39,38,36,34,33,31,30,89,88,87,85,83,82,80,79,77,75,73,72,70,68,66,64,63,61,59,57,56,54,52,50,48,47,45,43,41,40,38,37,35,33,32,31,89,87,86,84,83,81,80,78,76,75,73,71,70,68,66,64,63,61,59,57,56,54,52,50,49,47,45,44,42,40,39,37,36,34,33,31,88,87,85,84,82,81,79,78,76,75,73,71,69,68,66,64,63,61,59,57,56,54,52,51,49,47,45,44,42,41,39,38,36,35,33,32,88,86,85,83,82,80,79,77,76,74,73,71,69,68,66,64,63,61,59,57,56,54,52,51,49,47,46,44,43,41,40,38,37,35,34,32,87,86,84,83,82,80,79,77,75,74,72,71,69,67,66,64,62,61,59,58,56,54,53,51,49,48,46,45,43,41,40,38,37,36,34,33,86,85,84,82,81,80,78,77,75,74,72,70,69,67,66,64,62,61,59,58,56,54,53,51,50,48,46,45,43,42,40,39,38,36,35,34,86,85,83,82,81,79,78,76,75,73,72,70,69,67,66,64,62,61,59,58,56,54,53,51,50,48,47,45,44,42,41,39,38,37,35,34,85,84,83,81,80,79,77,76,75,73,72,70,69,67,65,64,62,61,59,58,56,55,53,51,50,48,47,45,44,43,41,40,39,37,36,35,85,83,82,81,80,78,77,76,74,73,71,70,68,67,65,64,62,61,59,58,56,55,53,52,50,49,47,46,44,43,42,40,39,38,37,35,84,83,82,81,79,78,77,75,74,72,71,70,68,67,65,64,62,61,59,58,56,55,53,52,50,49,48,46,45,43,42,41,39,38,37,36,84,82,81,80,79,78,76,75,74,72,71,69,68,67,65,64,62,61,59,58,56,55,53,52,51,49,48,46,45,44,42,41,40,39,38,36,83,82,81,80,78,77,76,75,73,72,71,69,68,66,65,64,62,61,59,58,56,55,54,52,51,49,48,47,45,44,43,42,40,39,38,37,83,82,80,79,78,77,76,74,73,72,70,69,68,66,65,63,62,61,59,58,57,55,54,52,51,50,48,47,46,44,43,42,41,40,38,37,82,81,80,79,78,76,75,74,73,71,70,69,67,66,65,63,62,61,59,58,57,55,54,53,51,50,49,47,46,45,44,42,41,40,39,38,82,81,80,78,77,76,75,74,72,71,70,69,67,66,65,63,62,61,59,58,57,55,54,53,51,50,49,48,46,45,44,43,42,40,39,38,81,80,79,78,77,76,75,73,72,71,70,68,67,66,65,63,62,61,59,58,57,55,54,53,52,50,49,48,47,45,44,43,42,41,40,39,81,80,79,78,77,75,74,73,72,71,69,68,67,66,64,63,62,61,59,58,57,56,54,53,52,51,49,48,47,46,45,43,42,41,40,39,80,79,78,77,76,75,74,73,72,70,69,68,67,66,64,63,62,61,59,58,57,56,54,53,52,51,50,48,47,46,45,44,43,42,41,40,80,79,78,77,76,75,74,73,71,70,69,68,67,65,64,63,62,61,59,58,57,56,55,53,52,51,50,49,47,46,45,44,43,42,41,40,80,79,78,77,76,74,73,72,71,70,69,68,67,65,64,63,62,61,59,58,57,56,55,53,52,51,50,49,48,47,46,44,43,42,41,40,79,78,77,76,75,74,73,72,71,70,69,68,66,65,64,63,62,61,59,58,57,56,55,54,52,51,50,49,48,47,46,45,44,43,42,41,79,78,77,76,75,74,73,72,71,70,69,67,66,65,64,63,62,61,59,58,57,56,55,54,53,51,50,49,48,47,46,45,44,43,42,41,78,78,77,76,75,74,73,72,70,69,68,67,66,65,64,63,62,61,59,58,57,56,55,54,53,52,51,50,48,47,46,45,44,43,42,42,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,77,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,43,77,76,75,74,74,73,72,71,70,69,68,67,66,65,64,63,62,61,59,58,57,56,55,54,53,52,51,50,49,48,47,46,46,45,44,43,77,76,75,74,73,72,71,70,70,69,68,67,66,65,64,63,62,61,59,58,57,56,55,54,53,52,51,50,50,49,48,47,46,45,44,43,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,76,75,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,45,44,76,75,74,73,73,72,71,70,69,68,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,52,51,50,49,48,47,47,46,45,44,76,75,74,73,72,71,71,70,69,68,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,52,51,50,49,49,48,47,46,45,44,75,75,74,73,72,71,70,70,69,68,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,52,51,50,50,49,48,47,46,45,45,75,74,74,73,72,71,70,69,69,68,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,52,51,51,50,49,48,47,46,46,45,75,74,73,73,72,71,70,69,68,68,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,52,52,51,50,49,48,47,47,46,45,75,74,73,72,72,71,70,69,68,67,67,66,65,64,63,62,61,60,60,59,58,57,56,55,54,53,53,52,51,50,49,48,48,47,46,45,74,74,73,72,71,71,70,69,68,67,66,66,65,64,63,62,61,60,60,59,58,57,56,55,54,54,53,52,51,50,49,49,48,47,46,46,74,73,73,72,71,70,70,69,68,67,66,65,65,64,63,62,61,60,60,59,58,57,56,55,55,54,53,52,51,50,50,49,48,47,47,46,74,73,73,72,71,70,69,69,68,67,66,65,65,64,63,62,61,60,60,59,58,57,56,55,55,54,53,52,51,51,50,49,48,47,47,46,74,73,72,72,71,70,69,68,68,67,66,65,64,64,63,62,61,60,60,59,58,57,56,56,55,54,53,52,52,51,50,49,48,48,47,46,74,73,72,71,71,70,69,68,68,67,66,65,64,64,63,62,61,60,60,59,58,57,56,56,55,54,53,52,52,51,50,49,49,48,47,46,73,73,72,71,70,70,69,68,67,67,66,65,64,64,63,62,61,60,60,59,58,57,56,56,55,54,53,53,52,51,50,50,49,48,47,47,73,72,72,71,70,70,69,68,67,67,66,65,64,64,63,62,61,60,60,59,58,57,56,56,55,54,53,53,52,51,50,50,49,48,48,47,73,72,72,71,70,69,69,68,67,66,66,65,64,63,63,62,61,60,60,59,58,57,57,56,55,54,54,53,52,51,51,50,49,48,48,47,73,72,71,71,70,69,69,68,67,66,66,65,64,63,63,62,61,60,60,59,58,57,57,56,55,54,54,53,52,51,51,50,49,49,48,47,};unsignedcharx_char[8],data[5][20];unsignedcharlcd_x,lcd_y;unsignedinty=0,x=0,y1,y2,z=0,j=0;unsignedchars_x,s_y;unsignedchartime0,v0=0,v1=0,v2=0,v3=0,v4=0,s;unsignedinta,b,c;signedintT[4][4];voidserial_write_byte(unsignedchardat){unsignedcharss;for(ss=0;ss<8;ss++){ if(dat&0x80) SID12864_SET; else SID12864_CLR; SCLK12864_CLR;//一個時鐘周期 __delay_cycles(40);SCLK12864_SET;__delay_cycles(40);SCLK12864_CLR;dat=dat<<1;__delay_cycles(30);SID12864_CLR;//}}/***********************************************************函數(shù)名稱:LCD_write_byte函數(shù)功能:寫一個字節(jié)的數(shù)據(jù)到12864液晶,包括指令或數(shù)據(jù)入口參數(shù):RW、RS、W_data出口參數(shù):無備注:RW=1,從液晶讀數(shù)據(jù)到MCU;RW=0,寫一個數(shù)據(jù)到液晶;(一般RW都設(shè)為0,即只向液晶寫數(shù)據(jù),不讀數(shù)據(jù))RS=1,寫入的是數(shù)據(jù);RS=0,寫入的是指令;一般模式:RW=0,RS=1;寫數(shù)據(jù)RW="0",RS=0;寫指令***********************************************************/voidLCD_write_byte(unsignedcharRW,unsignedcharRS,unsignedcharW_data){ unsignedintH_data,L_data,S_ID=0xf8;//11111RWRS0 if(RW==0)//RW=0,MCU寫一個數(shù)據(jù)到液晶; { S_ID&=~0x04; } else//RW=1,從液晶讀數(shù)據(jù)到MCU { S_ID|=0X04; } if(RS==0)//RS=1,寫入的是數(shù)據(jù) { S_ID&=~0x02; } else//RS=0,寫入的是指令; { S_ID|=0X02; } H_data=W_data; H_data&=0xf0;//屏蔽低4位的數(shù)據(jù) L_data=W_data;//xxxx0000格式 L_data&=0x0f;//屏蔽高4位的數(shù)據(jù) L_data<<=4;//xxxx0000格式 CS12864_SET; serial_write_byte(S_ID);//發(fā)送S_ID serial_write_byte(H_data);//發(fā)送H_data serial_write_byte(L_data);//發(fā)送L_data CS12864_CLR; __delay_cycles(12);}/***********************************************************函數(shù)名稱:LCD_init函數(shù)功能:12864液晶初始化入口參數(shù):dat8bit出口參數(shù):無備注:***********************************************************/voidLCD_Init(void){ __delay_cycles(12); LCD_write_byte(0,0,0x30);//功能設(shè)置8位數(shù)據(jù),基本指令 __delay_cycles(12); LCD_write_byte(0,0,0x04);//點設(shè)定:顯示字符/光標(biāo)從左到右移位,DDRAM地址加1 __delay_cycles(12); LCD_write_byte(0,0,0x0C);//顯示設(shè)定:開顯示,顯示光標(biāo),當(dāng)前顯示位反白閃動 __delay_cycles(12); LCD_write_byte(0,0,0x01);//寫指令:清除顯示,清DDRAM __delay_cycles(12); LCD_write_byte(0,0,0x02);//寫指令:DDRAM地址歸位 __delay_cycles(12); LCD_write_byte(0,0,0x80);//寫指令:設(shè)置DDRAM地址,把顯示地址設(shè)為0X80,即為第一行的首位 __delay_cycles(12);}/***********************************************************函數(shù)名稱:LCD_setxy函數(shù)功能:設(shè)置顯示漢字位置X(1~16),Y(1~4)入口參數(shù):X(1~16),Y(1~4)出口參數(shù):無備注:x坐標(biāo)Line1|80H81H82H83H84H85H86H87HLine2|90H91H92H93H94H95H96H97HLine3|88H89H8AH8BH8CH8DH8EH8FHLine4|98H99H9AH9BH9CH9DH9EH9FH***********************************************************/voidLCD_setxy(unsignedcharx,unsignedchary){ switch(y) { case1: LCD_write_byte(0,0,0X7F+x);break;//Line1 case2: LCD_write_byte(0,0,0X8F+x);break;

溫馨提示

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

評論

0/150

提交評論