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

下載本文檔

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

文檔簡(jiǎn)介

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

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

三.硬件電路設(shè)計(jì)3.1系統(tǒng)框圖聲響模塊從單片機(jī)聲響模塊從單片機(jī)聲音接收聲音接收LCD顯示LCD顯示主單片機(jī)主單片機(jī)語(yǔ)音播報(bào)控制語(yǔ)音播報(bào)控制圖7系統(tǒng)總框圖系統(tǒng)主要由三大模塊組成:聲響模塊、聲音接收模塊、信號(hào)處理模塊。聲響模塊產(chǎn)生聲音信號(hào),由聲音接收模塊接收信號(hào)并產(chǎn)生電流脈沖,經(jīng)總線系統(tǒng)傳送到信號(hào)處理模塊進(jìn)行運(yùn)算處理,將測(cè)試數(shù)據(jù)顯示在LCD顯示屏上。系統(tǒng)總電路圖見附錄二。3.2聲響模塊圖8聲響模塊電路圖通過單片機(jī)產(chǎn)生500Hz的方波信號(hào),利用單管放大后給喇叭發(fā)聲。其中電位器可對(duì)音量進(jìn)行調(diào)節(jié)。3.3從單片機(jī)最小系統(tǒng)圖9從單片機(jī)最小系統(tǒng)單片機(jī)最小系統(tǒng)采用的是TI公司生產(chǎn)的超低功耗的MSP430G2452單片機(jī)為核心,其中9號(hào)端口為P2.1,實(shí)際電路中需和聲源模塊相連接。3.4聲音接收模塊圖10接收系統(tǒng)模塊電路3.5信號(hào)處理模塊信號(hào)處理模塊由總線控制單元,MSP430G2553為核的Launchpad以及LCD顯示屏共同組成。單片機(jī)內(nèi)部運(yùn)算處理后將結(jié)果送入LCD顯示。圖11主單片機(jī)及顯示3.6語(yǔ)音模塊采用ISD4004語(yǔ)音錄放芯片制作成語(yǔ)音播報(bào)模塊。利用lm386語(yǔ)音功放芯片放大。四.軟件設(shè)計(jì)4.1軟件流程圖設(shè)計(jì)采用MSP430G2553為核心的Launchpad負(fù)責(zé)信號(hào)的處理并控制LCD顯示屏顯示相應(yīng)數(shù)據(jù)。主程序流程圖如下:開始開始初始化初始化MCU初始化初始化LCD接收信號(hào)接收信號(hào)進(jìn)入中斷進(jìn)入中斷數(shù)據(jù)處理數(shù)據(jù)處理退出中斷退出中斷LCDLCD顯示數(shù)據(jù)結(jié)束結(jié)束中斷流程圖:進(jìn)入中斷進(jìn)入中斷判斷先后判斷先后xyzj顯示數(shù)據(jù)顯示數(shù)據(jù)讀取坐標(biāo)讀取坐標(biāo)退出中斷退出中斷中斷程序開始后,系統(tǒng)首先對(duì)聲音接收模塊采集到的信息進(jìn)行判斷,找到距離聲源最近的接收器,再按時(shí)間差分別得出其它3個(gè)接收器的距離差,再通過單片機(jī)就可以計(jì)算出聲源所在位置,發(fā)出屏幕顯示數(shù)據(jù)后退出中斷。額外加入了語(yǔ)音播報(bào)裝置,在每次采集測(cè)試數(shù)據(jù)開始和結(jié)束都會(huì)進(jìn)行一次自動(dòng)語(yǔ)音播報(bào)。五.測(cè)試結(jié)果與分析5.1測(cè)試方法與儀器先測(cè)試4個(gè)定點(diǎn)(分別為(10,10)(45,10)(10,25)(45,25))來(lái)標(biāo)定4個(gè)聲音接收模塊的精度等級(jí),然后采取隨機(jī)取點(diǎn)方式得到測(cè)試數(shù)據(jù)。測(cè)試中主要用到的儀器有直流穩(wěn)壓電源,示波器等。5.2測(cè)試數(shù)據(jù)選中坐標(biāo)接收時(shí)間差測(cè)試坐標(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測(cè)試數(shù)據(jù)5.3測(cè)試結(jié)果分析測(cè)試平均誤差在5cm以內(nèi),部分坐標(biāo)點(diǎn)能達(dá)到3cm標(biāo)準(zhǔn),符合設(shè)計(jì)要求。5.4測(cè)試結(jié)果本設(shè)計(jì)制作完成了題目要求的基本部分的全部要求和發(fā)揮部分的大部分要求,達(dá)到設(shè)計(jì)要求。個(gè)別指標(biāo)由于時(shí)間有限只完成相應(yīng)的軟件和硬件設(shè)計(jì),整體調(diào)試還未能全部完成。參考文獻(xiàn)[1]范紅剛,魏學(xué)海,陳和.51單片機(jī)自學(xué)筆記;北京,北京航空航天大學(xué)出版社2010年1月第1版[2]王宜懷,曹金華.嵌入式系統(tǒng)設(shè)計(jì)實(shí)戰(zhàn);北京,北京航空航天大學(xué)出版社2011年5月第1版[3]聞怡洋.無(wú)線設(shè)備編程指南;北京,北京大學(xué)出版社2004年7月第1版[4]李玉柏.最小系統(tǒng)設(shè)計(jì)與應(yīng)用;四川,電子科技大學(xué)出版社2012年4月第1版[5]鐘洪聲.電子電路設(shè)計(jì)技術(shù)基礎(chǔ);四川,電子科技大學(xué)出版社2012年4月第1版[6]王昊,李昕.集成運(yùn)放應(yīng)用電路設(shè)計(jì)360例;北京,電子工業(yè)出版社2007年1月[7]喻金錢,喻斌.短距離無(wú)線通信詳解—基于單片機(jī)控制;北京,北京航空航天大學(xué)出版社2009年4月附錄一:元器件清單元器件名數(shù)量MSP430G25531片MSP430G24521片LP2950-33LPRE31片LM2577S1片LM3934片MIC4個(gè)BUZZER1個(gè)穩(wěn)壓管78051個(gè)LCD128641個(gè)電位器若干電阻若干電容若干電池2節(jié)電感2個(gè)附錄二:系統(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;//一個(gè)時(shí)鐘周期 __delay_cycles(40);SCLK12864_SET;__delay_cycles(40);SCLK12864_CLR;dat=dat<<1;__delay_cycles(30);SID12864_CLR;//}}/***********************************************************函數(shù)名稱:LCD_write_byte函數(shù)功能:寫一個(gè)字節(jié)的數(shù)據(jù)到12864液晶,包括指令或數(shù)據(jù)入口參數(shù):RW、RS、W_data出口參數(shù):無(wú)備注:RW=1,從液晶讀數(shù)據(jù)到MCU;RW=0,寫一個(gè)數(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寫一個(gè)數(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ù):無(wú)備注:***********************************************************/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);//點(diǎn)設(shè)定:顯示字符/光標(biāo)從左到右移位,DDRAM地址加1 __delay_cycles(12); LCD_write_byte(0,0,0x0C);//顯示設(shè)定:開顯示,顯示光標(biāo),當(dāng)前顯示位反白閃動(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ù):無(wú)備注: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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論