版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、 電子信息工程專業(yè) 單片機(jī)課程設(shè)計(jì)報(bào)告題 目 簡(jiǎn)易波形發(fā)生器 姓 名 學(xué) 號(hào) 班 級(jí) 指導(dǎo)教師 2013年 7 月 4 日要求:1指導(dǎo)教師按照課程設(shè)計(jì)大綱要求完成學(xué)生課程設(shè)計(jì)指導(dǎo)工作。2課程設(shè)計(jì)任務(wù)書由指導(dǎo)教師照大綱要求填寫,內(nèi)容要全面。3課程設(shè)計(jì)報(bào)告由參加本學(xué)生填寫。課程設(shè)計(jì)結(jié)束時(shí)交指導(dǎo)教師。4指導(dǎo)教師要根據(jù)每一位學(xué)生課程設(shè)計(jì)任務(wù)完成情況,認(rèn)真審核設(shè)計(jì)報(bào)告,并在課程設(shè)計(jì)結(jié)束時(shí),給出客觀、準(zhǔn)確的評(píng)語(yǔ)和成績(jī)。5課程設(shè)計(jì)任務(wù)書和報(bào)告要語(yǔ)言流暢,圖表正確規(guī)范。6本表要用鋼筆、圓柱筆填寫或打印,字跡工整。 圖1.1 顯示電路圖課程設(shè)計(jì)報(bào)告1 設(shè)計(jì)原理與技術(shù)方法:11 電路工作原理分析 本次單片機(jī)實(shí)習(xí)采
2、用的是單片機(jī)STC89C52,對(duì)于簡(jiǎn)易波形發(fā)生器設(shè)計(jì)的硬件電路主要為三個(gè)部分,為顯示部分、鍵盤部分、D/A轉(zhuǎn)換電路,以下對(duì)三個(gè)部分分別介紹。1.1.1 顯示電路原理圖1.1 顯示電路圖如圖1.1所示八位八段數(shù)碼管為共陰極數(shù)碼管,通過(guò)兩個(gè)74HC573鎖存器與單片機(jī)連接,一片573的LE為位選信號(hào)另一片的LE為段選信號(hào),分別由單片機(jī)的P2.7和P2.6控制,高電平有效。當(dāng)P2.7=1、P2.6=0時(shí),位選有效,分別控制01-08八位數(shù)碼管選通,低有效,即通過(guò)P0口送出數(shù)據(jù),哪一位為0則哪一位數(shù)碼管有顯示;當(dāng)P2.6=1、P2.7=0時(shí),段選有效,此時(shí)分別控制每一位八段數(shù)碼管的每一段a b c d
3、 e f g dp的亮滅,高有效,從而使數(shù)碼管顯示數(shù)字0-9。顯示段碼如表1.1所示。表1.1 共陰極數(shù)碼管顯示段碼顯示字符012345678顯示段碼3FH06H5BH4FH66H6DH7DH07H7FH顯示字符9AbCDEF滅顯示段碼6FH77H7CH39H5EH79H71H00H1.1.2 鍵盤電路原理如圖1.2所示為4×4的矩陣式鍵盤與單片機(jī)的P3口相連,行連接,列連接。用掃描法對(duì)按鍵進(jìn)行掃描,先將所有行置0,所有列置1,當(dāng)有按鍵按下時(shí),通過(guò)對(duì)P3口的狀態(tài)查詢則按下的按鍵所在列將為0,其余仍未1,通過(guò)延時(shí)去抖動(dòng)判斷是否真有按鍵按下,若有,則逐行掃描,判斷按鍵所在行,最后返回按鍵
4、鍵碼,并去執(zhí)行相應(yīng)按鍵的程序。返回鍵碼如表1.2所示。按鍵01234567返回鍵碼EEHDEHBEH7EHEDHDDHBDH7DH按鍵89ABCDEF返回鍵碼EBHDBHBBH7BHE7HD7HB7H77H圖1.3 D/A轉(zhuǎn)換電路表1.2 鍵盤掃描返回鍵碼1.1.3 D/A轉(zhuǎn)換電路原理圖1.2 鍵盤電路圖如圖1.3所示為AD/DA轉(zhuǎn)換芯片PCF8591與單片機(jī)相連的電路,其中4路D/A,一路A/D,簡(jiǎn)易波形發(fā)生器用到的為D/A轉(zhuǎn)換,單片機(jī)的P2.0及P2.1口與PCF8591的時(shí)鐘線SCL、數(shù)據(jù)線SDA相連,通過(guò)I2C串行總線向PCF8591發(fā)送數(shù)據(jù)并進(jìn)行數(shù)字量轉(zhuǎn)換成模擬量后輸出。1.2 元器
5、件選擇及說(shuō)明 簡(jiǎn)易波形發(fā)生器是由單片機(jī)向D/A轉(zhuǎn)換器中輸入數(shù)字量,通過(guò)D/A轉(zhuǎn)換成模擬量從而輸出波形,因此用到的器件主要有單片機(jī)STC89C51,AD/DA轉(zhuǎn)換芯片PCF8591,四位共陰極數(shù)碼管,4×4的矩陣式鍵盤。下面對(duì)兩種芯片進(jìn)行說(shuō)明。1.2.1 單片機(jī)STC89C51 單片機(jī)的引腳可分為電源、外接晶振、控制和可編程輸入/輸出引腳。(1)電源引腳(2根) VCC:電源輸入,接5V電源 GND:接地線(2)外接晶振引腳(2根) XTAL1:片內(nèi)振蕩電路的輸入端 XTAL2:片內(nèi)振蕩電路的輸出端(3)控制引腳(4根) RST:復(fù)位引腳,引腳上出現(xiàn)2個(gè)機(jī)器周期的高
6、電平將使單片機(jī)復(fù)位。ALE/PROG:地址鎖存允許信號(hào)/片內(nèi)EPROM編程脈沖 PSEN:外部存儲(chǔ)器讀選通信號(hào) EA/VPP:程序存儲(chǔ)器的內(nèi)外部選通,接低電平從外部程序存儲(chǔ)器讀指令,如果接高電平則從內(nèi)部程序存儲(chǔ)器讀指令。(4)可編程輸入/輸出引腳(32根) STC89C52單片機(jī)有4組8位的可編程I/O口,分別位P0、P1、P2、P3口,每個(gè)口有8位(8根引腳),共32根。 P0口(P0.0P0.7):8位雙向I/O口線;P1口(P1.0P1.7):8位準(zhǔn)雙向I/O口線;P2口(P2.0P2.7):8位準(zhǔn)雙向I/O口線;P3口(P3.0P3.7):8位準(zhǔn)雙向I/O
7、口線。1.2.2 AD/DA轉(zhuǎn)換芯片PCF8951PCF8591是單片、單電源低功耗8位CMOS數(shù)據(jù)采集器件,具有4個(gè)模擬輸入、一個(gè)輸出和一個(gè)串行I2C總線接口。3個(gè)地址引腳A0、A1和A2用于編程硬件地址,允許將最多8個(gè)器件連接至I2C總線而不需要額外硬件。器件的地址、控制和數(shù)據(jù)通過(guò)兩線雙向I2C總線傳輸。其引腳如下:AIN0AIN3:模擬信號(hào)輸入端。A0A3:引腳地址端。VDD、VSS:電源端(2.56V)。SDA、SCL:I2C 總線的數(shù)據(jù)線、時(shí)鐘線。OSC:外部時(shí)鐘輸入端,內(nèi)部時(shí)鐘輸出端。EXT:內(nèi)部、外部時(shí)鐘選擇線,使用內(nèi)部時(shí)鐘時(shí)EXT 接地。
8、0;AGND:模擬信號(hào)地。器件功能包括多路復(fù)用模擬輸入、片上跟蹤和保持功能、8位模數(shù)轉(zhuǎn)換和8位數(shù)模轉(zhuǎn)換。最大轉(zhuǎn)換速率取決于I2C總線的最高速率。具體功能描述如下:(1)地址圖1.3 地址I2C總線系統(tǒng)中的每一片PCF8591通過(guò)發(fā)送有效地址到該器件來(lái)激活。該地址包括固定部分和可編程部分??删幊滩糠直仨毟鶕?jù)地址引腳A0、A1和A2來(lái)設(shè)置。在I2C總線協(xié)議中地址必須是起始條件后作為第一個(gè)字節(jié)發(fā)送。地址字節(jié)的最后一位是用于設(shè)置以后數(shù)據(jù)傳輸方向的讀/寫位。地址如圖1.4所示。(2)控制字圖1.4 控制字發(fā)送到 PCF8591 的第二個(gè)字節(jié)將被存儲(chǔ)在控制寄存器,用于控制器件功能。控制寄存器的高半字節(jié)用于
9、允許模擬輸出,和將模擬輸入編程為單端或差分輸入。低半字節(jié)選擇一個(gè)由高半字節(jié)定義的模擬輸入通道??刂谱秩鐖D1.4所示。(3)D/A轉(zhuǎn)換發(fā)送給 PCF8591 的第三個(gè)字節(jié)被存儲(chǔ)到DAC 數(shù)據(jù)寄存器,并使用片上D/A 轉(zhuǎn)換器轉(zhuǎn)換成對(duì)應(yīng)的模擬電壓。這個(gè)D/A 轉(zhuǎn)換器由連接至外部參考電壓的具有256個(gè)接頭的電阻分壓電路和選擇開(kāi)關(guān)組成。接頭譯碼器切換一個(gè)接頭至DAC 輸出線。D/A轉(zhuǎn)換順序的波形如圖1.5。1.3 程序設(shè)計(jì)及流程圖本次優(yōu)秀的設(shè)計(jì)為當(dāng)輸入任意頻率,數(shù)碼管顯示出頻率并輸出相應(yīng)頻率的方波,此次設(shè)計(jì)是由定時(shí)時(shí)間決定,頻率范圍為30Hz500Hz,當(dāng)由按鍵輸入次頻率范圍內(nèi)任意頻率時(shí),對(duì)應(yīng)數(shù)碼管顯示
10、出來(lái)并在示波器上輸出方波,流程圖如圖1.6所示。程序見(jiàn)附錄。圖1.6 優(yōu)秀設(shè)計(jì)流程圖圖1.5 D/A轉(zhuǎn)換順序2 課程設(shè)計(jì)工作記錄2.1 設(shè)計(jì)步驟與時(shí)間安排6月17日至6月18日,選課題,查閱資料。6月19日至6月21日,研究電路圖。6月22日至7月1日,根據(jù)課題要求,編寫程序,從及格開(kāi)始,然后中,良,優(yōu)秀依次展開(kāi)。并進(jìn)行仿真,糾正程序的功能錯(cuò)誤,不斷完善程序。7月2日,進(jìn)行答辯。7月4日,交實(shí)習(xí)報(bào)告。2.2 課題完成結(jié)果說(shuō)明(1)此次簡(jiǎn)易波形發(fā)生器實(shí)現(xiàn)了以下功能: 及格:上電之后,數(shù)碼管最后四位將顯示1234,當(dāng)按鍵1按下時(shí),顯示1234滅亮閃爍一次,時(shí)間間隔為0.5s;當(dāng)按鍵2按下時(shí),顯示1
11、234滅亮閃爍兩次,當(dāng)按鍵3按下時(shí),顯示1234滅亮閃爍三次;當(dāng)按鍵4按下時(shí),顯示1234滅亮閃爍四次。 中等:上電之后,示波器顯示100Hz方波,數(shù)碼管顯示頻率100。當(dāng)有“頻率加”按鍵按下時(shí),頻率加100Hz;當(dāng)有“頻率減”按鍵按下時(shí),頻率減100Hz;當(dāng)有“幅值加”按鍵按下時(shí),幅值加0.1V;當(dāng)由“幅值減”按鍵按下時(shí),幅值減0.1V。 良好:上電之后,數(shù)碼管無(wú)顯示,示波器無(wú)波形。當(dāng)有按鍵1按下時(shí),示波器出現(xiàn)方波,數(shù)碼管顯示對(duì)應(yīng)頻率,此時(shí)若有頻率加減按鍵按下,方波頻率加減100Hz,若有幅值加減按鍵按下時(shí),方波幅值加減0.1V;當(dāng)有按鍵2按下時(shí),示波器出現(xiàn)三角波,數(shù)碼管顯示對(duì)應(yīng)頻率,此時(shí)若
12、有頻率加減按鍵按下,三角波頻率加減100Hz;當(dāng)有按鍵3按下時(shí),示波器出現(xiàn)正弦波,數(shù)碼管顯示對(duì)應(yīng)頻率,此時(shí)若有頻率加減按鍵按下,正弦波頻率加減100Hz。 優(yōu)秀:上電之后示波器無(wú)波形,數(shù)碼無(wú)顯示,當(dāng)輸入030Hz500Hz內(nèi)的任意頻率后,數(shù)碼管顯示所輸頻率,示波器顯示相應(yīng)頻率的波形。、 (2)實(shí)驗(yàn)中遇到的問(wèn)題: 1.由于是用I2C總線串行輸入數(shù)據(jù),延時(shí)時(shí)間較長(zhǎng),定時(shí)時(shí)間不準(zhǔn)確,方波頻率顯示只能到700Hz,三角波和正弦波頻率只能顯示到400Hz。 2.由于顯示部分占用了延時(shí)時(shí)間,為了增大頻率,將顯示部分的延時(shí)減小里許多,導(dǎo)致了數(shù)碼管后兩位顯示較暗。 3.由于定時(shí)不是很準(zhǔn)確,優(yōu)秀中的各個(gè)頻率所輸
13、出的波形也不是特別精確。 (3)總結(jié)通過(guò)這三周的實(shí)習(xí),感覺(jué)時(shí)間很緊迫,我認(rèn)為想要真正做好一次設(shè)計(jì)三周的時(shí)間真的不夠用,覺(jué)得還有很多不足的地方需要改進(jìn),但卻已經(jīng)沒(méi)有時(shí)間。在之前學(xué)習(xí)單片機(jī)感覺(jué)還能駕馭,即使在平時(shí)實(shí)驗(yàn)中也還能湊合應(yīng)付。但當(dāng)自己真正做一個(gè)模塊時(shí),有種無(wú)從下手的感覺(jué)。并且這次設(shè)計(jì)我們用的是C語(yǔ)言編程,對(duì)于單片機(jī)的C語(yǔ)言編程我們還不太了解,后來(lái)通過(guò)去圖書館借書和查閱資料慢慢的了解了許多C語(yǔ)言程序,之后便開(kāi)始研究電路圖并開(kāi)始編程,剛開(kāi)始比較困難,問(wèn)題很多,但在不斷的失敗與解決問(wèn)題的過(guò)程中,我一點(diǎn)點(diǎn)進(jìn)步,最終完成了這次設(shè)計(jì)任務(wù)。這次課程實(shí)習(xí)是我受益匪淺,讓我對(duì)單片機(jī)的原理和功能有了進(jìn)一步的了
14、解,學(xué)到了更多的電路知識(shí),在對(duì)單片機(jī)編程過(guò)程中,認(rèn)識(shí)了解了IIC總線輸入方式,了解了PCF8591類芯片的使用方法。從這次實(shí)習(xí),我也發(fā)現(xiàn)了自己的許多不足,并更加完善了自我,鍛煉了動(dòng)手能力,而且學(xué)會(huì)了將理論知識(shí)與實(shí)際相結(jié)合。課程設(shè)計(jì)驗(yàn)收指導(dǎo)教師評(píng)語(yǔ)及成績(jī):成績(jī)指導(dǎo)教師簽字 年 月 日教研室主任意見(jiàn)教研室主任簽字年 月 日附錄簡(jiǎn)易波形發(fā)生器優(yōu)秀設(shè)計(jì)程序:#include<reg52.h>#include<stdio.h>#include<string.h>#include<intrins.h> #define uint unsigned int /宏
15、定義#define uchar unsigned charsbit SCL=P20; /時(shí)鐘位sbit SDA=P21; /數(shù)據(jù)位sbit dula=P26; /數(shù)碼管段選鎖存端sbit wela=P27; /數(shù)碼管位選鎖存端uchar code duanma=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f; /數(shù)碼管段碼uchar code weima=0xdf,0xbf,0x7f;uchar code plth_tab=0xc4,0xc6,0xc8,0xca,0xcc,0xce,0xcf,0xd1,0xd2,0xd3,0xd4,0xd6,
16、0xd7,0xd8,0xd9,0xda,0xdb,0xdb,0xdc,0xdd,0xde,0xdf,0xdf,0xe0,0xe0,0xe1,0xe2,0xe3,0xe3,0xe4,0xe4,0xe5,0xe5,0xe6,0xe6,0xe7,0xe7,0xe7,0xe8,0xe8,0xe9,0xe9,0xe9,0xea,0xea,0xea,0xeb,0xeb,0xeb,0xeb,0xec,0xec,0xec,0xed,0xed,0xed,0xee,0xee,0xee,0xee,0xee,0xef,0xef,0xef,0xef,0xf0,0xf0,0xf0,0xf0,0xf0,0xf1,0xf1,
17、0xf1,0xf1,0xf1,0xf1,0xf2,0xf2,0xf2,0xf2,0xf2,0xf2,0xf3,0xf3,0xf3,0xf3,0xf3,0xf3,0xf4,0xf4,0xf4,0xf4,0xf4,0xf4,0xf4,0xf4,0xf5,0xf5,0xf5,0xf5,0xf5,0xf5,0xf5,0xf5,0xf5,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf6,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf8,0xf8,0xf8,
18、0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfa,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,
19、0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,
20、0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
21、0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
22、0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
23、0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff;uchar code pltl_tab=0xf0,0xf0,0xf0,0xf0,0xe0,0x20,0xf0,0x00,0x20,0x40,0xf0,0x50,0x50,0x60,0x30,0x20,0x00,
24、0xf0,0x90,0x40,0x20,0x00,0xa0,0x1a,0x50,0xd0,0x60,0x20,0xb0,0x05,0x95,0x25,0xb5,0x15,0xa5,0x05,0x95,0xf5,0x4a,0xaa,0x0a,0x6a,0xca,0x20,0x80,0xe0,0x0a,0x6a,0xca,0xfa,0x5a,0xba,0xea,0x4a,0x7a,0xaa,0x0a,0x3a,0x6a,0xca,0xfa,0x2a,0x5a,0x8a,0xea,0x1a,0x4a,0x7a,0xaa,0xda,0x0a,0x3a,0x60,0x90,0xc0,0xf0,0x20,
25、0x55,0x7f,0x9f,0xcf,0xf0,0x3f,0x6f,0x87,0x9f,0xcf,0xed,0x0b,0x2a,0x5a,0x72,0x8a,0xba,0xd2,0xea,0x15,0x2d,0x45,0x5d,0x75,0xa5,0xbd,0xd5,0xeb,0x00,0x18,0x30,0x48,0x60,0x78,0x90,0xa8,0xc0,0xd8,0xf0,0x04,0x18,0x30,0x48,0x60,0x78,0x88,0x98,0xa8,0xc0,0xd8,0xe8,0xf8,0x08,0x20,0x38,0x45,0x52,0x60,0x78,0x90,
26、0xa0,0xb0,0xc0,0xd0,0xe0,0xf0,0x00,0x10,0x20,0x30,0x40,0x50,0x5c,0x69,0x75,0x80,0x90,0xa0,0xb0,0xbc,0xc9,0xd5,0xe0,0xf0,0x00,0x10,0x1c,0x29,0x35,0x40,0x4c,0x59,0x65,0x70,0x7c,0x89,0x95,0xa0,0xac,0xb9,0xc5,0xd0,0xda,0xe3,0xed,0xf6,0x00,0x0d,0x1a,0x27,0x35,0x40,0x4a,0x55,0x5f,0x6a,0x74,0x7d,0x87,0x90,
27、0x9a,0xa4,0xad,0xb7,0xc0,0xca,0xd2,0xda,0xe2,0xea,0xf2,0xfa,0x02,0x0a,0x12,0x1a,0x22,0x2a,0x32,0x3a,0x42,0x4a,0x52,0x5a,0x62,0x6a,0x72,0x7a,0x82,0x8a,0x91,0x98,0x9e,0xa5,0xac,0xb3,0xba,0xc1,0xc8,0xce,0xd5,0xdc,0xd3,0xea,0xf0,0xf6,0xfc,0x02,0x08,0x0e,0x14,0x1a,0x20,0x26,0x2c,0x32,0x38,0x3e,0x44,0x4a,
28、0x50,0x56,0x5c,0x62,0x68,0x6e,0x74,0x7a,0x80,0x85,0x8a,0x8f,0x94,0x9a,0x9f,0xa4,0xaa,0xb0,0xb5,0xba,0xc0,0xc5,0xca,0xcf,0xd4,0xda,0xdf,0xe4,0xe8,0xed,0xf2,0xf6,0xfb,0x00,0x05,0x0a,0x0f,0x13,0x17,0x1b,0x20,0x24,0x28,0x2c,0x30,0x35,0x3a,0x3e,0x41,0x44,0x48,0x4b,0x4e,0x52,0x56,0x5a,0x5d,0x61,0x65,0x69,
29、0x6c,0x6f,0x72,0x76,0x79,0x7d,0x80,0x83,0x86,0x8a,0x8e,0x93,0x97,0x9b,0x9f,0xa3,0xa8,0xac,0xb0,0xb4,0xb8,0xbc,0xc0,0xc5,0xc9,0xcc,0xcf,0xd2,0xd5,0xd8,0xdc,0xdf,0xe2,0xe5,0xe8,0xeb,0xee,0xf1,0xf5,0xf8,0xfb,0xfe,0x01,0x03,0x06,0x08,0x0b,0x0e,0x10,0x13,0x15,0x18,0x1b,0x20,0x23,0x25,0x28,0x2b,0x2d,0x30,
30、0x32,0x35,0x37,0x3a,0x3d,0x3f,0x42,0x44,0x47,0x4a,0x4f,0x52,0x55,0x58,0x5b,0x5f,0x62,0x64,0x68,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7b,0x7d,0x80,0x82,0x85,0x88,0x8a,0x8c,0x8e,0x91,0x93,0x96,0x99,0x9b,0x9d,0x9f,0xa3,0xa6,0xa8,0xaa,0xad,0xae,0xb0,0xb2,0xb4,0xb6,0xb8,0xba,0xbc,0xbe,0xbf,0xc1,0xc3,0xc5,0xc6,
31、0xc8,0xca,0xcc,0xce,0xd0,0xd2,0xd4,0xd6,0xd8,0xda,0xdc,0xdd,0xdf,0xe0,0xe2,0xe3,0xe4,0xe6,0xe8,0xe9,0xea,0xec,0xee,0xf0,0xf2,0xf4,0xf5,0xf6,0xf8,0xfa,0xfb,0xfc,0xfe,0xff;uchar code fz_tab=0x05,0x0a,0x0f,0x14,0x1a,0x1f,0x24,0x29,0x2e,0x33,0x38,0x3d,0x43,0x48,0x4d,0x52,0x57,0x5c,0x61,0x66,0x6c,0x71,0x
32、76,0x7b,0x80,0x85,0x8a,0x8f,0x94,0x9a,0x9f,0xa4,0xa9,0xae,0xb3,0xb8,0xbd,0xc3,0xc8,0xcd,0xd2,0xd7,0xdc,0xe1,0xe6,0xeb,0xf0,0xf5,0xfa,0xff; /方波幅值void delay(uchar i);void delayNOP();void display();void iic_start();void iic_Init();void check_ack();void iic_sendbyte(uchar indata);void DAC_fangbo(uchar d
33、at);void time(uchar th0,uchar tl0);uchar jianzhi();uchar kbscan();void xsfb();void plfzxs(); uint n=0;uint t;uchar a3=0,0,0;uint shu;uint m=0;uint f=49; /幅值變量uint flag=0;uint flag_fb;/* 主程序*/void main() iic_Init(); /I2C總線初始化 while(1) xsfb(); if(n=3) DAC_fangbo(fz_tabf); /發(fā)送高位數(shù)據(jù) /* 定時(shí)子程序*/void time(u
34、char th0,uchar tl0) TMOD=0x01; /設(shè)置定時(shí)計(jì)數(shù)器T0,方式1定時(shí) TH0=th0; /定時(shí)初值 TL0=tl0; EA=1; /開(kāi)總中斷 ET0=1; /開(kāi)T0中斷 TR0=1; /啟動(dòng)T0 while(EA=1); /等待中斷/* 中斷子程序*/void timer0() interrupt 1 using 1 EA=0; /定時(shí)時(shí)間到,關(guān)總中斷/* us延時(shí)函數(shù)(約2us)*/void delayNOP() _nop_(); _nop_();/* 延時(shí)子函數(shù)*/void delay(uchar i) /延時(shí)函數(shù)1 for(;i>0;i-);/* 啟動(dòng)I2
35、C總線子程序 時(shí)鐘保持高,數(shù)據(jù)線從高到低一次跳變,I2C通信開(kāi)始*/void iic_start() SDA=1; SCL=1; delayNOP(); / 延時(shí)2us SDA=0; delayNOP(); SCL=0;/* 初始化I2C總線子程序*/void iic_Init() SCL=1; delayNOP(); SDA=1; delayNOP();/* 主機(jī)應(yīng)答位檢查子程序,迫使數(shù)據(jù)傳輸過(guò)程結(jié)束*/void check_ack() SDA=1; /置成輸入 SCL=1; F0=0; delayNOP(); if(SDA=1) /若SDA=1表明非應(yīng)答 F0=1; /置位非應(yīng)答標(biāo)志F0
36、SCL=0;/* 發(fā)送一字節(jié)子程序*/void iic_sendbyte(uchar indata) uchar n=8; /發(fā)送一字節(jié)數(shù)據(jù),共八位 while(n-) SDA=(bit)(indata&0x80); /發(fā)送最高位 SCL=1; delayNOP(); SCL=0; indata=indata<<1; /數(shù)據(jù)左移一位 /* 發(fā)送數(shù)據(jù)子程序*/void DAC_fangbo(uchar dat) flag_fb=1; iic_start(); /啟動(dòng)I2C delayNOP(); iic_sendbyte(0x90); /發(fā)送地址位 check_ack();
37、/檢查應(yīng)答位 iic_sendbyte(0x40); /發(fā)送控制位 check_ack(); /檢查應(yīng)答位 while(flag_fb) iic_sendbyte(dat); /發(fā)送數(shù)據(jù) check_ack(); /檢查應(yīng)答位 time(plth_tabshu-30,pltl_tabshu-30); /定時(shí)延時(shí)delay(90);iic_sendbyte(0x00); /發(fā)送地位數(shù)據(jù) check_ack(); /檢查應(yīng)答位 time(plth_tabshu-30,pltl_tabshu-30); /定時(shí)延時(shí) plfzxs();dat=fz_tabf;xsfb(); /* 顯示子程序*/void display() uchar j;for(j=0;j<n;j+) dula=1; P0=duanmaaj; dula=0; P0=0xff; wela=1; P0=weimaj; wela=0; delay(10); /* 返回鍵值子程序*/uchar jianzhi() uchar key; ke
溫馨提示
- 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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年度年福建省高校教師資格證之高等教育心理學(xué)通關(guān)試題庫(kù)(有答案)
- 2024年熟食制品項(xiàng)目資金籌措計(jì)劃書代可行性研究報(bào)告
- 2024年造紙完成工段智能裝備項(xiàng)目資金申請(qǐng)報(bào)告代可行性研究報(bào)告
- 2024常年采購(gòu)協(xié)議條款與條件示例
- 2024年度建材銷售協(xié)議格式
- 2024年專業(yè)門窗安裝服務(wù)協(xié)議模板
- 2024公司B棟生產(chǎn)車間租賃協(xié)議
- 員工基本行為準(zhǔn)則
- 銀行外匯便利化政策落實(shí)情況總結(jié)
- 2024年規(guī)范二手公寓房產(chǎn)交易協(xié)議書
- 影響世界的工業(yè)革命 2023屆高三統(tǒng)編版歷史一輪復(fù)習(xí)
- 職業(yè)學(xué)院教師教學(xué)創(chuàng)新團(tuán)隊(duì)建設(shè)管理辦法
- 微型計(jì)算機(jī)原理與應(yīng)用習(xí)題集及答案
- 河北省唐山市藥品零售藥店企業(yè)藥房名單目錄
- 喵喵老師制作 電子百拼的黑白電路圖
- DB34-T 4010-2021 水利工程外觀質(zhì)量評(píng)定規(guī)程-高清現(xiàn)行
- 《整改報(bào)告》模板
- 送達(dá)地址確認(rèn)書(樣本)
- 江蘇省歷屆中學(xué)生與社會(huì)作文大賽決賽試題及獲獎(jiǎng)范文(完整版)資料
- 六年級(jí)數(shù)學(xué)上冊(cè)教案-分?jǐn)?shù)乘法整理與練習(xí) 蘇教版
- 《民航服務(wù)禮儀》項(xiàng)目五 地面服務(wù)禮儀
評(píng)論
0/150
提交評(píng)論