单片机学习应中的六大重要部分
一、总线:我们知道,一个电路总是由元器件通过电线连接而成的,在模拟电路中,连线并不成为一个问题,因为各器件间一般是串行关系,各器件之间的连线并不很多,但计算机电路却不一样,它是以微处理器为核心,各器件都要与微处理器相连,各器件之间的工作必须相互协调,所以就需要的连线就很多了,如果仍如同模拟电路一样,在各微处理器和各器件间单独连线,则线的数量将多得惊人,所以在微处理机中引入了总线的概念,各个器件共同享用连线,所有器件的8根数据线全部接到8根公用的线上,即相当于各个器件并联起来,但仅这样还不行,如果有两个器件同时送出数据,一个为0,一个为1,那么,接收方接收到的究竟是什么呢?这种情况是不允许的,所以要通过控制线进行控制,使器件分时工作,任何时候只能有一个器件发送数据(可以有多个器件同时接收)。器件的数据线也就被称为数据总线,器件所有的控制线被称为控制总线。在单片机内部或者外部存储器及其它器件中有存储单元,这些存储单元要被分配地址,才能使用,分配地址当然也是以电信号的形式给出的,由于存储单元比较多,所以,用于地址分配的线也较多,这些线被称为地址总线。
二、数据、地址、指令:之所以将这三者放在一起,是因为这三者的本质都是一样的——数字,或者说都是一串‘0’和‘1’组成的序列。换言之,地址、指令也都是数据。指令:由单片机芯片的设计者规定的一种数字,它与我们常用的指令助记符有着严格的一一对应关系,不可以由单片机的开发者更改。地址:是寻找单片机内部、外部的存储单元、输入输出口的依据,内部单元的地址值已由芯片设计者规定好,不可更改,外部的单元可以由单片机开发者自行决定,但有一些地址单元是一定要有的(详见程序的执行过程)。数据:这是由微处理机处理的对象,在各种不同的应用电路中各不相同,一般而言,被处理的数据可能有这么几种情况:
1•地址(如MOV DPTR,#1000H),即地址1000H送入DPTR。
2•方式字或控制字(如MOV TMOD,#3),3即是控制字。
3•常数(如MOV TH0,#10H)10H即定时常数。
4•实际输出值(如P1口接彩灯,要灯全亮,则执行指令:MOV P1,#0FFH,要灯全暗,则执行指令:MOV P1,#00H)这里0FFH和00H都是实际输出值。又如用于LED的字形码,也是实际输出的值。
理解了地址、指令的本质,就不难理解程序运行过程中为什么会跑飞,会把数据当成指令来执行了。
三、P0口、P2口和P3的第二功能用法:初学时往往对P0口、P2口和P3口的第二功能用法迷惑不解,认为第二功能和原功能之间要有一个切换的过程,或者说要有一条指令,事实上,各端口的第二功能完全是自动的,不需要用指令来转换。如P3.6、P3.7分别是WR、RD信号,当微片理机外接RAM或有外部I/O口时,它们被用作第二功能,不能作为通用I/O口使用,只要一微处理机一执行到MOVX指令,就会有相应的信号从P3.6或P3.7送出,不需要事先用指令说明。事实上‘不能作为通用I/O口使用’也并不是‘不能’而是(使用者)‘不会’将其作为通用I/O口使用。你完全可以在指令中按排一条SETB P3.7的指令,并且当单片机执行到这条指令时,也会使P3.7变为高电平,但使用者不会这么去做,因为这通常这会导致系统的崩溃。
四、程序的执行过程: 单片机在通电复位后8051内的程序计数器(PC)中的值为‘0000’,所以程序总是从‘0000’单元开始执行,也就是说:在系统的ROM中一定要存在‘0000’这个单元,并且在‘0000’单元中存放的一定是一条指令。
五、堆栈: 堆栈是一个区域,是用来存放数据的,这个区域本身没有任何特殊之处,就是内部RAM的一部份,特殊的是它存放和取用数据的方式,即所谓的‘先进后出,后进先出’,并且堆栈有特殊的数据传输指令,即‘PUSH’和‘POP’,有一个特殊的专为其服务的单元,即堆栈指针SP,每当执一次PUSH指令时,SP就(在原来值的基础上)自动加1,每当执行一次POP指令,SP就(在原来值的基础上)自动减1。由于SP中的值可以用指令加以改变,所以只要在程序开始阶段更改了SP的值,就可以把堆栈设置在规定的内存单元中,如在程序开始时,用一条MOV SP,#5FH指令,就时把堆栈设置在从内存单元60H开始的单元中。一般程序的开头总有这么一条设置堆栈指针的指令,因为开机时,SP的初始值为07H,这样就使堆栈从08H单元开始往后,而08H到1FH这个区域正是8031的第二、三、四工作寄存器区,经常要被使用,这会造成数据的混乱。不同作者编写程序时,初始化堆栈指令也不完全相同,这是作者的习惯问题。当设置好堆栈区后,并不意味着该区域成为一种专用内存,它还是可以象普通内存区域一样使用,只是一般情况下编程者不会把它当成普通内存用了。
六、单片机的开发过程: 这里所说的开发过程并不是一般书中所说的从任务分析开始,我们假设已设计并制作好硬件,下面就是编写软件的工作。在编写软件之前,首先要确定一些常数、地址,事实上这些常数、地址在设计阶段已被直接或间接地确定下来了。如当某器件的连线设计好后,其地址也就被确定了,当器件的功能被确定下来后,其控制字也就被确定了。然后用文本编辑器(如EDIT、CCED等)编写软件,编写好后,用编译器对源程序文件编译,查错,直到没有语法错误,除了极简单的程序外,一般应用仿真机对软件进行调试,直到程序运行正确为止。运行正确后,就可以写片(将程序固化在EPROM中)。在源程序被编译后,生成了扩展名为HEX的目标文件,一般编程器能够识别这种格式的文件,只要将此文件调入即可写片
Singlechip study should be an important part in the six
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.
Friday, 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
论文下载大学生论坛有,中英文对照的