購買設(shè)計請充值后下載,,資源目錄下的文件所見即所得,都可以點開預覽,,資料完整,充值下載可得到資源目錄里的所有文件。。?!咀ⅰ浚篸wg后綴為CAD圖紙,doc,docx為WORD文檔,原稿無水印,可編輯。。。具體請見文件預覽,有不明白之處,可咨詢QQ:12401814
單片機
單片機即單片微型計算機,是把中央處理器、存儲器、定時/計數(shù)器、輸入輸出接口都集成在一塊集成電路芯片上的微型計算機。與應用在個人電腦中的通用型微處理器相比,它更強調(diào)自供應(不用外接硬件)和節(jié)約成本。它的最大優(yōu)點是體積小,可放在儀表內(nèi)部,但存儲量小,輸入輸出接口簡單,功能較低。由于其發(fā)展非常迅速,舊的單片機的定義已不能滿足,所以在很多應用場合被稱為范圍更廣的微控制器,但是目前在中國大陸仍多沿用“單片機”的稱呼。
絕大多數(shù)現(xiàn)在的單片機都是基于馮·諾伊曼結(jié)構(gòu)的,這種結(jié)構(gòu)清楚地定義了嵌入式系統(tǒng)所必需的四個基本部分:一個中央處理器核心,程序存儲器(只讀存儲器或者閃存)、數(shù)據(jù)存儲器(隨機存儲器),一個或者更多的定時/計時器,還有用來與外圍設(shè)備以及擴展資源進行通信的輸入/輸出端口——所有這些都被集成在單個集成電路芯片上。說單片機與通用型中央處理單元芯片不同是因為前者一般很容易配合最小型的外部支持芯片制成工作計算機。這樣就可以很容易的把單片機系統(tǒng)植入裝置內(nèi)部來控制裝置了。近年來為了在指令和數(shù)據(jù)上使用不同的字寬,并提高處理器流水線速度,哈佛結(jié)構(gòu)在微控制器和DSP也逐漸得到了廣泛的應用。
傳統(tǒng)的微處理器是不允許這么做的。它要完成單片機的工作,就必須連接一些其他芯片。比如說,因為片上沒有數(shù)據(jù)存儲器,就必須要添加一些RAM的存儲芯片,雖然所添加存儲器的容量很靈活,但是至少還是要添加,另外還需要添加很多連線來傳遞芯片之間的數(shù)據(jù)。 比如,一個典型的微控制器只需要一個時鐘發(fā)生器和很少的RAM和ROM(或者EPROM, E2PROM)就可以在軟件和晶振下工作了。同時,微控制器具有豐富的輸入輸出設(shè)備,像是模擬數(shù)字轉(zhuǎn)換(ADC),定時器,串口或者其他串行通訊接口(比如I2C,串行外圍接口(SPI),控制器局域網(wǎng))。通常,這些繼承在內(nèi)部的設(shè)備可以通過特殊的指令來操作。
一些現(xiàn)代的微控制器支持一些內(nèi)建的高級編程語言,比如BASIC語言。
早期的單片機都是8位或4位的。其中最成功的是INTEL的8031,因為簡單可靠而性能不錯獲得了很大的好評。此后在8031上發(fā)展出了MCS51系列單片機系統(tǒng)。基于這一系統(tǒng)的單片機系統(tǒng)直到現(xiàn)在還在廣泛使用。隨著工業(yè)控制領(lǐng)域要求的提高,開始出現(xiàn)了16位單片機,但因為性價比不理想并未得到很廣泛的應用。90年代后隨著消費電子產(chǎn)品大發(fā)展,單片機技術(shù)得到了巨大的提高。隨著INTEL i960系列特別是后來的ARM系列的廣泛應用,32位單片機迅速取代16位單片機的高端地位,并且進入主流市場。而傳統(tǒng)的8位單片機的性能也得到了飛速提高,處理能力比起80年代提高了數(shù)百倍。目前,高端的32位單片機主頻已經(jīng)超過300MHz,性能直追90年代中期的專用處理器,而普通的型
號出廠價格跌落至1美元,最高端的型號也只有10美元。當代單片機系統(tǒng)已經(jīng)不再只在裸機環(huán)境下開發(fā)和使用,大量專用的嵌入式操作系統(tǒng)被廣泛應用在全系列的單片機上。而在作為掌上電腦和手機核心處理的高端單片機甚至可以直接使用專用的Windows和Linux操作系統(tǒng)。
單片機比專用處理器最適合應用于嵌入式系統(tǒng),因此它得到了最多的應用。事實上單片機是世界上數(shù)量最多的計算機?,F(xiàn)代人類生活中所用的幾乎每件電子和機械產(chǎn)品中都會集成有單片機。手機、電話、計算器、家用電器、電子玩具、掌上電腦以及鼠標等電腦配件中都配有1-2部單片機。而個人電腦中也會有為數(shù)不少的單片機在工作。汽車上一般配備40多部單片機,復雜的工業(yè)控制系統(tǒng)上甚至可能有數(shù)百臺單片機在同時工作!單片機的數(shù)量不僅遠超過PC機和其他計算的綜合,甚至比人類的數(shù)量還要多。
單片機學習應中的五大重要部分:
一、總線:我們知道,一個電路總是由元器件通過電線連接而成的,在模擬電路中,連線并不成為一個問題,因為各器件間一般是串行關(guān)系,各器件之間的連線并不很多,但計算機電路卻不一樣,它是以微處理器為核心,各器件都要與微處理器相連,各器件之間的工作必須相互協(xié)調(diào),所以就需要的連線就很多了,如果仍如同模擬電路一樣,在各微處理器和各器件間單獨連線,則線的數(shù)量將多得驚人,所以在微處理機中引入了總線的概念,各個器件共同享用連線,所有器件的8根數(shù)據(jù)線全部接到8根公用的線上,即相當于各個器件并聯(lián)起來,但僅這樣還不行,如果有兩個器件同時送出數(shù)據(jù),一個為0,一個為1,那么,接收方接收到的究竟是什么呢?這種情況是不允許的,所以要通過控制線進行控制,使器件分時工作,任何時候只能有一個器件發(fā)送數(shù)據(jù)(可以有多個器件同時接收)。器件的數(shù)據(jù)線也就被稱為數(shù)據(jù)總線,器件所有的控制線被稱為控制總線。在單片機內(nèi)部或者外部存儲器及其它器件中有存儲單元,這些存儲單元要被分配地址,才能使用,分配地址當然也是以電信號的形式給出的,由于存儲單元比較多,所以,用于地址分配的線也較多,這些線被稱為地址總線。
二、數(shù)據(jù)、地址、指令:之所以將這三者放在一起,是因為這三者的本質(zhì)都是一樣的——數(shù)字,或者說都是一串‘0’和‘1’組成的序列。換言之,地址、指令也都是數(shù)據(jù)。指令:由單片機芯片的設(shè)計者規(guī)定的一種數(shù)字,它與我們常用的指令助記符有著嚴格的一一對應關(guān)系,不可以由單片機的開發(fā)者更改。地址:是尋找單片機內(nèi)部、外部的存儲單元、輸入輸出口的依據(jù),內(nèi)部單元的地址值已由芯片設(shè)計者規(guī)定好,不可更改,外部的單元可以由單片機開發(fā)者自行決定,但有一些地址單元是一定要有的(詳見程序的執(zhí)行過程)。數(shù)據(jù):這是由微處理機處理的對象,在各種不同的應用電路中各不相同,一般而言,被處理的數(shù)據(jù)可能有這么
幾種情況:
1、地址(如MOV DPTR,#1000H),即地址1000H送入DPTR。
2、方式字或控制字(如MOV TMOD,#3),3即是控制字。
3、常數(shù)(如MOV TH0,#10H)10H即定時常數(shù)。
4、實際輸出值(如P1口接彩燈,要燈全亮,則執(zhí)行指令:MOV P1,#0FFH,要燈全暗,則執(zhí)行指令:MOV P1,#00H)這里0FFH和00H都是實際輸出值。又如用于LED的字形碼,也是實際輸出的值。
理解了地址、指令的本質(zhì),就不難理解程序運行過程中為什么會跑飛,會把數(shù)據(jù)當成指令來執(zhí)行了。
三、P0口、P2口和P3的第二功能用法:初學時往往對P0口、P2口和P3口的第二功能用法迷惑不解,認為第二功能和原功能之間要有一個切換的過程,或者說要有一條指令,事實上,各端口的第二功能完全是自動的,不需要用指令來轉(zhuǎn)換。如P3.6、P3.7分別是WR、RD信號,當微片理機外接RAM或有外部I/O口時,它們被用作第二功能,不能作為通用I/O口使用,只要一微處理機一執(zhí)行到MOVX指令,就會有相應的信號從P3.6或P3.7送出,不需要事先用指令說明。事實上‘不能作為通用I/O口使用’也并不是‘不能’而是(使用者)‘不會’將其作為通用I/O口使用。你完全可以在指令中按排一條SETB P3.7的指令,并且當單片機執(zhí)行到這條指令時,也會使P3.7變?yōu)楦唠娖剑褂谜卟粫@么去做,因為這通常這會導致系統(tǒng)的崩潰。
四、程序的執(zhí)行過程: 單片機在通電復位后8051內(nèi)的程序計數(shù)器(PC)中的值為‘0000’,所以程序總是從‘0000’單元開始執(zhí)行,也就是說:在系統(tǒng)的ROM中一定要存在‘0000’這個單元,并且在‘0000’單元中存放的一定是一條指令。
五、堆棧:堆棧是一個區(qū)域,是用來存放數(shù)據(jù)的,這個區(qū)域本身沒有任何特殊之處,就是內(nèi)部RAM的一部份,特殊的是它存放和取用數(shù)據(jù)的方式,即所謂的‘先進后出,后進先出’,并且堆棧有特殊的數(shù)據(jù)傳輸指令,即‘PUSH’和‘POP’,有一個特殊的專為其服務的單元,即堆棧指針SP,每當執(zhí)一次PUSH指令時,SP就(在原值的基礎(chǔ)上)自動加1,每當執(zhí)行一次POP指令,SP就(在原值的基礎(chǔ)上)自動減1。由于SP中的值可以用指令加以改變,所以只要在程序開始階段更改了SP的值,就可以把堆棧設(shè)置在規(guī)定的內(nèi)存單元中,如在程序開始時,用一條MOV SP,#5FH指令,就時把堆棧設(shè)置在從內(nèi)存單元60H開始的單元中。一般程序的開頭總有這么一條設(shè)置堆棧指針的指令,因為開機時,SP的初始值為07H,這樣就使堆棧從08H單元開始往后,而08H到1FH這個區(qū)域正是8031的第二、三、四工作寄存器區(qū),經(jīng)常要被使用,這會造成數(shù)據(jù)的混亂。不同作者編寫程序時,初始化堆棧指令也不完全相同,這是作者的習慣問題。當設(shè)置好堆
棧區(qū)后,并不意味著該區(qū)域成為一種專用內(nèi)存,它還是可以象普通內(nèi)存區(qū)域一樣使用,只是一般情況下編程者不會把它當成普通內(nèi)存用。
Single Chip Microcomputer A microcontroller (or MCU) is a computer-on-a-chip. It is a type of microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC). The majority of computer systems in use today are embedded in other machinery, such as telephones, clocks, appliances, vehicles, and infrastructure. An embedded system usually has minimal requirements for memory and program length and may require simple but unusual input/output systems. For example, most embedded systems lack keyboards, screens, disks, printers, or other recognizable I/O devices of a personal computer. They may control electric motors, relays or voltages, and read switches, variable resistors or other electronic devices. Often, the only I/O device readable by a human is a single light-emitting diode, and severe cost or power constraints can even eliminate that. In contrast to general-purpose CPUs, microcontrollers do not have an address bus or a data bus, because they integrate all the RAM and non-volatile memory on the same chip as the CPU. Because they need fewer pins, the chip can be placed in a much smaller, cheaper package. Integrating the memory and other peripherals on a single chip and testing them as a unit increases the cost of that chip, but often results in decreased net cost of the embedded system as a whole. (Even if the cost of a CPU that has integrated peripherals is slightly more than the cost of a CPU + external peripherals, having fewer chips typically allows a smaller and cheaper circuit board, and reduces the labor required to assemble and test the circuit board). This trend leads to design. A microcontroller is a single integrated circuit, commonly with the following features: central processing unit - ranging from small and simple 4-bit processors to sophisticated 32- or 64-bit processors input/output interfaces such as serial ports (UARTs) other serial communications interfaces like I2C, Serial Peripheral Interface and Controller Area Network for system interconnect peripherals such as timers and watchdog RAM for data storage ROM, EPROM, EEPROM or Flash memory for program storage clock generator - often an oscillator for a quartz timing crystal, resonator or RC circuit many include analog-to-digital converters This integration drastically reduces the number of chips and the amount of wiring and PCB space that would be needed to produce equivalent systems using separate chips and have proved to be highly popular in embedded systems since their introduction in the 1970s. Some microcontrollers can afford to use a Harvard architecture: separate memory buses for instructions and data, allowing accesses to take place concurrently. The single slice of the earlier period all of machines are 8 or 4.Among them, the INTEL is most successful of 8031, because of in brief dependable but the function was quite good to acquire very big good opinion.Henceforth at 8031 up developed MCS51 serieses a single slice machine system.According to the single slice of this system machine system is still in the extensive usage till now.Because the industry controls the exaltation of[with] realm request, starting appearing 16 single slice machine, but because sex price wanted to don't get a very extensive application than the disregard.Develop greatly along with the consumption electronics product after 90's, the single slice machine technique got a huge exaltation.Along with the extensive application of INTEL i 960 serieses especially later ARM series, the 32 single slice machine replaces 16 single slice the high level position of the machine quickly, and gets into an essential market.And traditional of 8 single slice the function of the machine also got to fly to raise soon, handling an ability to compare with to raise few a hundredfolds in 80's.Currently, 32 single slice of the high level with main machine already over 300 MHzs, the function keeps appropriation processor of making track for the mid 90's, and the common model number factory price drop into to USD 1, tallest carry of model number also only USD 10.The contemporary and single slice machine system has already no longer developed and used just under the naked machine environment, the in great quantities appropriative built-in operate system is applied extensively in the whole serieseses of the single slice is on board.But Be ising the high level of handheld PC and cellular phone core processing single slice the machine even can use appropriative Windows and the Linux operate system directly. Single slice the machine ratio appropriation processor is the most suitable to match to apply in the built-in system, so it got the most applications.In fact the single slice machine is an amount the most calculators are in the world.The modern mankind are living medium use of.assemble in almost each electronics and machine product have a single slice machine.All have 1-2 single slice machine in the computer accessorieses such as cellular phone, telephone, calculator, home appliances, electronics toy, handheld PC and mouse etc..And personal computer in would also capable number not a few single slice the machine be working.Provide with more than 40 departments a single slice machine generally on the car, complicated industry's controling the top of the system even may has single several hundred pedestalses slices machine to work in the meantime!Single slice the amount of the machine not only far above the PC machine and other calculations of comprehensive, even than the mankind's amount still want have another Singlechip study should be an important part in the five: First, the bus: we know that a circuit is always from the components through wires connected, and in analog circuits, the connection does not become a problem, because the devices are generally serial inter-relationship between the various devices connection is not much, but not the same as computer circuits, which is based on the microprocessor as the core, the device must be connected with the microprocessor, the device must be between the mutual coordination and so on need to connect on a lot of If still the same as analog circuits, in the microprocessor and a separate connection between the devices, the quantity line will be many alarmingly so in the microprocessor introduced the concept of bus, all devices share the connection All devices of all eight data lines from eight public online, which is equivalent to all devices in parallel, but only this is not enough, if there is two devices send data simultaneously, a 0, a 1, then , the receiving party received what is it? This situation is not allowed, so to pass the line of control to control the device time job, any time there can be only one device to send data (which may have multiple devices simultaneously receiving). Device's data lines will be referred to as data bus, all the line of control devices known as control bus. Singlechip at internal or external memory and other devices have memory cells, these memory cells to be assigned addresses to use, the allocation of addresses is of course to give the form of electrical signals, and because memory cells are more so for address the allocation of more lines, these lines were known as the address bus. Second, data, address, command: The reason why these three together, because these three are the essence is the same - figure, or are a string of'0 'and'1', composed of sequence . In other words, addresses, instructions are also data. Command: from single-chip chip designer provides a figure, it is consistent with our mnemonic commonly used commands have a strict one-to-one relationship, not by the developer to change the MCU. Address: Singlechip are looking for internal, external storage units, input and output port based on the value of the internal unit's address has been provided for the chip designers, and can not be changed, the external unit can be single-chip developers to decide, but Yes there is some address must be the unit (see procedures for the implementation process). Data: This is the object of treatment by the microprocessor, in a variety of different applications in different circuits, in general, the data may be processed so have several situations: 1 .address (such as MOV DPTR, # 1000H), that address 1000h into the DPTR. 2. the way the words or control characters (such as MOV TMOD, # 3), 3 which controls the characters. 3. constants (such as MOV TH0, # 10H) 10H that is constant from time to time. 4 .The actual output value (such as the mouth then P1 lantern light to light the whole, then the implementation of instruction: MOV P1, # 0FFH, to light the whole dark, then the implementation of instruction: MOV P1, # 00H) and 00H are here 0FFH actual output value. Another example is the font code for the LED, is the actual output value. Understanding of the address, the nature of instructions, running is not difficult to understand why the process of running fly, the data will be implemented as instructions. Three, P0 mouth, P2 and P3 the mouth of the second function Usage: often on P0 beginner I, P2 and P3 mouth I use the second function puzzled think the second function and the original features have a switch between the process, or that there have to be a directive, in fact, the port's second feature is completely automatic, no need to use command to convert. Such as P3.6, P3.7, respectively, are WR, RD signal, when the micro-chip RAM or external justifications machine has an external I / O port, they were used as the second function, can not be used as general-purpose I / O port to use, as long as one microprocessor implementation of the MOVX instruction 1, there will be a corresponding signal sent from the P3.6 or P3.7, no prior use instructions indicate. In fact 'can not be used as general-purpose I / O port use' is not 'should not' but (user) 'not' as a general-purpose I / O port to use. At command you can arrange a Medium of Instruction SETB P3.7, and when the single-chip implementation of this Article directions, P3.7 will also become high, but users will not do so, because This usually will lead to the collapse of the system. Four, the program implementation process: single-chip power-on reset in 8051 after the program counter (PC) in the value of'0000 ', so the procedure always'0000' unit begin implementation of, that is to say: the system's ROM must exist in the'0000 'in this unit, and'0000' in the storage unit must be a command. Five, the stack: the stack is a region, are used to store data, the region does not have any unique position, that is a part of internal RAM, special is its data storage and access methods, namely, the so-called 'advanced after that last-in first-out ', and the stack has a special data transmission command, ie' PUSH 'and' POP ', there is a special unit specifically for its services, that is, the stack pointer SP, when they first PUSH instruction, the SP on (at the original value of the foundation on) automatically add one, whenever the implementation of a POP instruction, SP on (at the original value basis) minus one automatically. Because of the value of SP can be used to change directions, so as long as the stage at the beginning of the proceedings to change the value of the SP, you can put the stack set up the required memory units, such as at the beginning of the proceedings, with a MOV SP, # 5FH instructions when put on the stack from the memory modules installed in the unit 60H start. The normal procedure at the beginning of the total that there is a stack pointer of the instruction set, because at startup, SP initial value of 07H, thus the stack from the beginning the next unit 08h, and 08h to 1Fh in the region 8031 is the second, Three, four working registers area, often used, this will lead to data chaos. The author has prepared a different program, not exactly the same instructions to initialize the stack, which is the author's customary problem. When set up the stack area, does not mean that the region as a dedicated memory, it can be as common as the use of memory region, but under normal circumstances programming will not put it as an ordinary memory use.