【正文】
最后,我還要感謝韓建民老師和電子 071 的張琦同學(xué),他們曾多次不厭其煩地為我解答了不少疑惑,使我在對指令系統(tǒng)的理解上少走了不少彎路。我覺得單片機(jī)作為微型計(jì)算機(jī)的一種,必然和計(jì)算機(jī)有一定的共性。 DW 2702H,2502H,2402H,2021H,2208H 。==== 計(jì)數(shù)器初值表 == 武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 25 TABLE1: DW 64021,64103,64260,64400 DW 64524,64580,64684,64777 DW 64820,64898,64968,65030 DW 65058,65110,65157,65178 預(yù)存歌曲表 。=== 發(fā)聲子程序 === SOUND: SETB SPK 武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 23 ACALL SDELAY CLR SPK ACALL SDELAY RET 延時子程序 。送入高字節(jié) MOV TH0,A INC TEMP MOV A,TEMP MOVC A,A+DPTR MOV STL0,A 。屏蔽高四位,高四位為行,低四位為列 XRL A,0FH JZ NOKEY1 。 武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 11 圖 28 “毛刺”現(xiàn)象 發(fā)音電路 電子琴發(fā)音電路見圖 29。時鐘頻率越高,單片機(jī)控制器的控制節(jié)拍就越快,運(yùn)算速度也就越快。 C1,C2 的典型值為30PF。 低功耗空閑和掉電模式 3 個 16 位可編程定時 /計(jì)數(shù)器中斷 2 系統(tǒng)的主要硬件電路的設(shè) 計(jì) 單片機(jī)控制系統(tǒng)原理 芯片選用 在本次課程設(shè)計(jì)中我采用 Atmel 公司的 AT89C52 單片機(jī)。 1= G43 的節(jié)拍示意圖,見圖 12 在圖中,總共有三拍: 2 為一拍, 5 為一拍, 6 為一拍。 以標(biāo)準(zhǔn)音高 A為例: 標(biāo)準(zhǔn)音高 A 的頻率 f=440Hz,其對應(yīng)的周期為: usfT 2272/1 ?? ( 11) 因此需要在單片機(jī) I/O 口輸出周期為 T=2272us 的方波脈沖,如圖 11 所示 圖 11單片機(jī)控制音調(diào)示意圖 武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 3 由上圖可知: 單片機(jī)輸出高電平和低電平信號均為: usTt 11362/ ?? ( 12) 也就是說,單片機(jī)上定時器的中斷觸發(fā)時間為 1136us。在一個八度音里,有 12 個半音。 一般說來,單片機(jī)不像其他專業(yè) 樂器那樣能奏出多種音色的聲音,即不包含相應(yīng)幅度的諧波頻率。而一些簡易的電子樂器價格相對便宜,學(xué)習(xí)上手快,價格相對便宜,一般人容易負(fù)擔(dān)的起,能夠滿足一般愛好者的需求。故簡易電子樂器的研制具有一定的社會意義。單片機(jī)演奏的音樂基本都是單音頻率。以 1ⅰ八音區(qū)為例。如果單片機(jī)采用定時器工作方式 1,它以振蕩器的十二分頻信號為計(jì)數(shù)脈沖。從時長角度看, 2 的時長為四分音的一半,即為八分音符長; 4 的時長為八分音符的一半,即為十六分音符長; 5 的時長為四分音符的一半,即為八分音符長; 6的時長為四分音符長。 AT89C52 是美國Atmel 公司生產(chǎn)的低電壓、高性能 CMOS 8 位單片機(jī),片內(nèi)含 8KB 的可反復(fù)檫寫的程序存儲器和 12B 的隨機(jī)存取數(shù)據(jù)存儲器( RAM),器件采用 Atmel 公司的高密度、非易失性存儲技術(shù)生產(chǎn),兼容標(biāo)準(zhǔn) MCS51 指令系統(tǒng),片內(nèi)配置通用 8 位中央處理器( CPU)和 Flash 存儲單元,功能強(qiáng)大的 AT89C52 單片機(jī)可靈活應(yīng)用于各種控制領(lǐng)域。 時鐘頻率 024MHz 軟件設(shè)置睡眠和喚醒功能 簡易電子琴的組成框圖 武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 7 圖 22 電子琴系統(tǒng)原理框圖 簡易電子琴的 proteus 總體仿真圖 電子琴的 proteus 總體仿真圖見圖 23。 單片機(jī)在 工作時,由內(nèi)部振蕩器產(chǎn)生或由外直接輸入的送至內(nèi)部控制邏輯單元的時鐘信號的周期稱為時鐘周期。 一般來說單片機(jī)內(nèi)部有一個帶反饋的線性反相放大器,外界晶振(或接陶瓷振蕩器)和電容就可組成振蕩器,如圖 24 所示。 圖 29 電子琴發(fā)音電路 供電及復(fù)位電路 電子琴的供電電路和復(fù)位電路見圖 210。判斷是否有鍵按下,沒有就跳轉(zhuǎn) LCALL DELY10MS MOV A,P2 。送入低字節(jié) MOV TL0,A SETB TR0 DK1A:MOV A,P2 。=== 延時子程序 === SDELAY: MOV A,R4 。=== 預(yù)存歌曲表 === TABLE2: DW 2202H,2902H,2902H,2902H,2906H,2702H 。 DW 0000H 。后來有一段時間,我在課余的時間去旁聽了幾堂韓建民老師的《計(jì)算機(jī)組成原理》,對計(jì)算機(jī)的指令系統(tǒng)和尋址方式有了點(diǎn)認(rèn)識,再回過頭來看單片機(jī)的指令系統(tǒng)的時武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 26 候覺得慢慢的有頭緒了,不再像原先那樣摸不著頭腦。 參考文獻(xiàn) [1] 張鑫 ,華臻 ,陳書謙 .單片機(jī)原理與應(yīng)用 .[M].電子工業(yè)出版社, [2] 肖婧 .單片入門與趣味實(shí)驗(yàn)設(shè)計(jì) [M].北京航空航天大學(xué)出版社, [3] 陳明熒 .8051 單片機(jī)課程設(shè)計(jì)實(shí)訓(xùn)教材 [M].清華大學(xué)出版社, [4] 趙建領(lǐng) .51 系列單片機(jī)開發(fā)寶典 [M].電子工業(yè)出版社, [5] 求是科技 .8051 系列單片機(jī) C 程序設(shè)計(jì)完全手冊 [M].人民郵電出版社, [6] 樓然苗 ,李光飛 .51 系列單片機(jī)設(shè)計(jì)實(shí)例 [M].北京航空航天大學(xué)出版武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 27 社 , [7] 侯媛彬等,凌陽單片機(jī)原理及其畢業(yè)設(shè)計(jì)精選 2021 年,科學(xué)出版社 [8] 羅亞非,凌陽十六位單片機(jī)應(yīng)用基礎(chǔ) 2021 年 北京航空航天大學(xué)出版社 [9] 北京北 陽電子有限公司, 061A 凌陽單片機(jī)及其附帶光盤 2021 年 [10]張毅剛等, MCS51 單片機(jī)應(yīng)用設(shè)計(jì),哈工大出版社, 2021 年第 2 版 [11]霍孟友等,單片機(jī)原理與應(yīng)用,機(jī)械工業(yè)出版社, [12]霍孟友等,單片機(jī)原理與應(yīng)用學(xué)習(xí)概要及題解,機(jī)械工業(yè)出版社, [13]許泳龍等,單片機(jī)原理及應(yīng)用,機(jī)械工業(yè)出版社, 外文資料 Description The AT89C51 is a lowpower, highperformance CMOS 8bit microputer with 4K bytes of Flash programmable and erasable read only memory (PEROM). The device is manufactured using Atmel’s highdensity nonvolatile memory technology and is patible with the industrystandard MCS51 instruction set and pinout. The onchip Flash allows the program memory to be reprogrammed insystem or by a conventional nonvolatile memory programmer. By bining a versatile 8bit CPU 武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 28 with Flash on a monolithic chip, the Atmel AT89C51 is a powerful microputer which provides a highlyflexible and costeffective solution to many embedded control applications. Function characteristic The AT89C51 provides the following standard features: 4K bytes of Flash, 128 bytes of RAM, 32 I/O lines, two 16bit timer/counters, a five vector twolevel interrupt architecture, a full duplex serial port, onchip oscillator and clock circuitry. In addition, the AT89C51 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The Powerdown Mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset. Pin Description VCC: Supply voltage. GND: Ground. Port 0: Port 0 is an 8bit opendrain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance 0 may also be configured to be the multiplexed loworder address/data bus during accesses to external program and data memory. In this mode P0 has internal 0 also receives the code bytes during Flash programming,and outputs the code bytes during programverification. External pullups are required during programverification. Port 1 Port 1 is an 8bit bidirectional I/O port with internal Port 1 output buffers can sink/source four TTL 1s are written to Port 1 pins they are 武漢紡織大學(xué) 2021 屆畢業(yè)設(shè)計(jì)論文 29 pulled high by the internal pullups and can be used as inputs. As inputs,Port 1 pins that are externally being pulled low will source current (IIL) because of the internal 1 also receives the loworder address bytes during Flash programming and verification. Port 2 Port 2 is an 8bit bidirectional I/O port with internal Port 2 output buffers can sink/source four TTL 1s are written to Port 2 pins they are pulled high by the internal pullups and can be used as inputs. As inputs,Port 2 pins that are externally bei