V EM78 series single-chip - Tan Zhenwen EM78 Series Single Chip - Tan Zhenwen EM78 Series Single Chip - Tan Zhenwen Tan Zhenwen shares the author's leisure time, I always like a soldering iron in the room, welding circuit board, go upstream Seeing the favorite DIY must be carefully connected. Even if the construction can also get a lot of fun, I believe that people who love this way should be a lot, and in addition to watching others' works, I can use each other. Who can use each other? There are few parts, who provides a strong function, who is the fastest, so it is often easy to collect some nice circuits, and the days are like stacked wood, I can use a square one, I joked the name Building block design. The many useful circuits are combined together and is a new thing. This way is indeed fast and economical, in line with the concept of modern people. Not only the hardware can be collected like a small wood, but the software can certainly apply to the building blocks, so in many people's efforts, the author also collects some good link library of the EM78 series single-chip, so says that the sparrow is Small, fifty-in-law. Also because these link libraries have a reference value, the author does not tolerate alone, so decided to re-organize the disturbance of the discharge, share with friends who love this series of single-chip. Em78xxx Single Chip has been launched in more than ten different levels of single-chip since the advent, the 78p152, the 78p152 of the 8PIN is 68p860, and the assembly language instructions are the same, only 57, so repeated practice several times It will be familiar with the usage of the instruction. The assembly language is very easy to use in I / O control. It is also very efficient, so most of the books in the work is obvious, and there is a small number of software skills. In fact, the older is known, regarding chip control Turn over the Data Book with you, pay attention to Timing, then prepare a oscilloscope, you can get it in three or two. Instead, the algorithm is good, it will greatly affect the stability of the product, so experienced programming designers usually have their own set of sunflowers, so we must upgrade your skills. In addition to more practice, see Others' procedures will make you progress very quickly. BCD converted into binary because EM78XXX is 8-bit microcontrollers, so in order to save memory, our example is only a BYTE to store two BCD numbers, between 0 ~ 99, and after conversion ACC, if you need more bits, I believe that you should not be able to modify it after reading. A total of 13 instructions in this example program takes a total of 13 instructions, requires two variable spaces, which will affect the content of the original BCD after execution. MOV A, BCDMOV TMP, AMOV A, @ 0x0fand TMP, ASWAP BCDAND, ABC PSW, 0RLC BCD; * 2MOV A, BCDADD TMP, Arlc Bcdrlca BCD; * 8Add A, TMP Description In the program first mode should be considered The most people know the way, is also the most intuitive way, first saved the BCD bit number, because ten digits must be multiplied by 10, so using the shift skill multiplied by 10 plus a bit number, the result The answer is placed in the ACC. The shortcomings of the program II in the program is that after executing the program, the content of the original BCD has been destroyed during shift. In order to improve this missing, we change to a way. Below this program, we try to improve the lack of front, take 11 instructions CYCLE, still need two variable space, but will not destroy the original BCD after execution.
Swapa Bcdmov TMP, AMOV A, @ 0x0fand BCD, AAND TMP, ABC PSW, 0RLCA TMPSWAP TMPRC TMPADD A, TMPADD A, BCD Program III We are still unsatisfied, it seems a little complicated, although the speed has improved, However, there is still room for memory allocation, so we will improve the type of procedure three. The conversion process only costs 10 instructions Cycle, and only one variable space is required, and the contents of the original BCD will not change after execution. Mov A, @ 0x0fand A, BCDJBC BCD, 4Add A, @ 10JBC BCD, 5Add A, @ 20JBC BCD, 6ADD A, @ 40JBC BCD, 7ADD A, @ 80 Description Over the above three examples, do you feel that the program is the most Simple and easy to understand? The writing process is indeed a challenging work, and you can find a lot of inspiration and fun, you can't think of it! The sample program in which binary converted into the BCD code will convert the binary number in the ACC to the compacted bcd code, and the maximum BCD code is 99. CLR BCDDIGIT_HI: Add A, @ 256-10JBS PSW, Fcjmp Digit_LOINC BCDJMP DIGIT_HIDIGIT_LO: Add A, @ 10Swap Bcdor BCD, A subtractive trap EM78 series assembly language subtract command is Sub, you have to pay special attention to the use of this instruction, because ACC Always reduce, not for ulnight. The syntax of the SUB instruction has the following: SUB A, R (Ra → a) SUB R, A (Ra → r) SUB A, K (KA → A) that is, if we want to calculate the value of A-2, if Writing: Sub A, @ 2 is actually executing 2-a, the solution is as follows: add A, @ 256-2 or add A, @ 254 exchange two sets of buffers content If you think that you want to exchange two groups of memory must be Borrowing the third set of variables, then you can refer to the following way, just use some mathematical skills to become fast and simple. Mov A, Reg1Sub A, Reg2Add Reg1, ASUB REG2, A = REG1A = reg2-reg1REG1 = Reg1 a = reg1 (reg2-reg1) = reg2REG2 = reg2- (reg2-reg1) = reg1 If x> y Exchange ... Continue the previous example, this method is used in the Bubble Sort special tube. Mov A, XSUB A, YJBC PSW, FCJMP NO_CHANGEADD X, ASUB Y, A2 complement 2 complement additions often replace subtraction, traditional practice is to first take 1 complement, and then add 1. COM Reginc REG or can be obtained in another way, and the second method will affect the PSW buffer. Add A, Regsub A, REG If the number you require is already in the ACC, you can solve it. SUB A, @ 0 Rotating byte operation In the 8051 instruction, there is RLC and RL two instructions, and the RLC rotates the CY with the ACC left-handed, while RL only screws the MSB of the ACC to the LSB. The EM78XXX instruction only has RLC, then how can we do without CY rotation? The answer is twice: rlca reg1rlc reg1 As shown in Figure 1, the first bit rotation does not really change the content of REG1, the purpose is to put REG1 The MSB first placed in the FC, and the second bit rotation will screw the MSB just placed in the FC into the LSB. Similarly, the two BYtes are also the same principle without the bit rotation of the FC.
RLCA HI_BYTERLC LO_BYTERLC HI_BYTE Range Determines the write programs that will not encounter if..then .., some people think that the EM78xxx's conditional judgment is too cumbersome, so the author also summarizes them. Conditional judgment can be discussed in the open interval conditional type and closed interval conditions to be discussed in Figure 2. The open condition is to start with N point as the starting point. When the measured value is greater than n or when it is less than or equal to N, it is described as follows: IF (Number> n) ... / * Number is greater than n * / else ... / * Number is less than or equal to N * / EM78XXX assembly language is written as follows: MOV A, @ n 1SUB A, NumberJBC PSW, Fcjmp Label_1; greater than NJMP Label_2; less than or equal to N-closed conditional judgment is whether the measurement value is Within X and Y, if description is described in C: IF ((Number> = x) && (Number <= Y)) ... / * in Range * / Else ... / * false * / How to do it in EM78 assembly language? The general practice is to determine the conditions after subtraction, the procedures are as follows: Mov A, @ 2SUB A, Numberjbs PSW, Fcjmp Falsemov A, @ y 1SUB A, SiJBC PSW, Fcjmp Falsein_Range :; .... False :;. ... this IF condition is cost 8 instructions Cycle, it is not too complicated. However, there is a more concise method. The following uses the additional PSW (R3) to determine, a total of 5 lines will be cleaned. Mov A, Numberadd A, @ 255-yadd A, @ Y-X 1JBC PSW, Fcjmp In_Rangefalse :; .... in_range :; .... Description Key is in the top three lines, x represents the lower limit of conditional Value, y indicates the upper limit value of the condition, can be seen that the effects of using the CY flag manufacturing are not only streamlined and a little smart, many old hands are love, this is also one of the secret weapons in their pockets. If you feel good, you may also revenue in the kit, you can draw a gourd according to the season. ACC and buffer content exchange This reason We must introduce a fast logic algorithm, only 3 instructions cycle, you can exchange the contents of the ACC and the buffer content, not dragging water, Very Cute! Xor Number, Axor A, Numberxor Number, a Please reader to calculate it on the paper once, know the answer. Exchange multi-group buffer content utilizes the method described above, can be extended to multiple sets of buffer exchange, the following program shifts 5 sets of DATA content, the data of the first buffer is transmitted to the second buffer The data of the second buckler is then transmitted into the third buffer, and the last data is transmitted to the first buffer to form a byte data rotation. Mov A, @ 5Mov Count, Amov A, @ Data1Mov RSR, AMOV A, DATA5NEXT: XOR Indir, Axor A, Indirxor Indir, AINC RSRDJZ Countjmp Next calculation mod 2N If you just need to calculate the ACC MOD X, and X just 2 N times, using ACC AND (X-1) is the fastest way. For example, if you want to judge whether Year is a leap year, there is a simple way to exclude some non-leap years, as long as you can't be 4 more people, it is not a leap year. So you can solve it with Year and 3.
Mov A, @ 4-1and A, YearJBS PSW, FZJMP Noleap Clear a continuous memory for a continuous memory to read and write the best way is to use indirect addressing methods, but pay attention to some of the M78447 / 811/860 contour Ordered MCU, memory 20H ~ 3FH can also be divided into 4 groups of Bank, if it is not switched to the correct Bank caused read and write errors. The following example program will clear all 32 Bytes in Bank1 to 0. INDIR == 0x00RSR == 0x04COUNT == 0x10REG == 0x20BANK1 == 0x40BANK2 == 0x80BANK3 == 0xC0MOV A, @ 32MOV COUNT, AMOV A, @ REG | BANK1MOV RSR, ANEXT: CLR INDIRINC RSRDJZ COUNTJMP NEXT calculate how much of a BYTE This applet can check that there are several 1 in a BYTE, and the process of algorithms may be used, and the calculated results are placed on the ACC. RRCA Dataand A, @ 0x55sub data, amov a, dataAnd a, @ 0x33add data, Arrc DataAdd Data, Arrc Dataswapa DataAdd A, Dataand A, @ 0x0f Save NOP Directive Method Are you not squeezing? The NOP instruction is sometimes useful in the delay instruction time. If you have two consecutive NOP instructions, you can replace it with JMP to the next instruction, because this can reduce one instruction Byte, but also achieve the same effect. For example: nopnop can be written: jmp next_instnext_inst:; .... Because a NOP costs a directive Cycle, a JMP instruction requires 2 instructions Cycle, although it is sometimes complaining that the JMP instruction will spend more time, but you can't think of it. Such a wonderful. Label too much? One of the most striking problems in writing the language is that there are two disadvantages in the program, which is two disadvantages. The first is that it will cause the Label repetition problem, and the second is to think about the appropriate Label name. If you have already bordered the problem of Label, give you a small method, if you use "$" in the program, you can represent the address of the PC, and in present, "$ 2" means PC 2, "$ - 4 "Represents PC-4, look at the example below you immediately understand: Mov R, RJBS PSW, FZJMP $ 2JMP $-4; .... But you have to give you a suggestion, Label has an important meaning is Features with annotation, especially those who are more important for some lazy write annotations. So this method is only suitable for program blocks with high repetitiveness. Switch ... case description In the process of programming, it is unable to encounter multiple options. Try to find out with EM78XXX checklist, so that TBL can be used as a multi-critical judgment in addition to the general chart instruction. Use. MOV A, CASETBLJMP EVENT1; CASE = 0jmp Event2; Case = 1jmp Event3; Case = 2JMP Event4; Case = 3 Multi-byte incremental and decreasing operations Because EM78XXX is 8-bit single-chip, if you want to perform more than 8 calculations, Multiple bytes must be viewed as a variable. Here us explain how to add a set of 24-bit variables to increment and decrement.
Increment Mov A, @ 1Add Int24, AJBC Status, Fcadd INT24 1, AJBC Status, Fcadd INT24 2, A Decremen (Decrement) MOV A, @ 1Sub Int24, AJBS Status, FCSUB INT24 1, AJBS Status, FCSUB INT24 2, A judges whether multiple-byte variables are zero-use simple logical operation instructions, together multibly byte OR, and then determine if the multi-byte variable is zero according to the z flag. Mov A, INT24OR A, INT24 1OR A, INT24 2JBS PSW, FZ; ... Copy some bits sometimes we need to copy some specific bits by a buffer to another set of buffers, due to Not completely replicating the contents of the buffer, so there will be some steps to extract, now we find a method, you can copy the specified bits into another set of buffers as long as four steps, exemplary, prior to copying (SOURGE) = 44h, (target) = 5ah, if we want to copy the SOURCE's bit0 ~ bit2 to the target, then execute the program (SOURGET) = 5CH. Mov A, SourceXor A, Targetand A, @ 00000111bxor Target, A Will you want to copy which bit, just ask the third line program Mask. The odd-oriented doctrine is designed according to Dmitry Kiryashov's algorithm, assuming that all bits in the original ACC are abcdefgh. After the exchange, the ACC order turns into Badcfehg, and the program is only five lines, which is quite intriguing. Mov REG, AAND A, @ 0x55add reg, Arrc Regadd A, and REG interrupt programs do not need to keep ACC and PSW method interrupt programs must keep ACC and PSW? That is not necessarily! Especially if you are using mini-level MCUs such as EM78P152 / 156, Ram Size is particularly small. If you only need to make TCC interrupt to make a simple count job, you can avoid interrupt programs to destroy ACC and PSW. The reason is that some instructions do not affect the PSW, and some instructions do not need to pass through the ACC. First set a pre-ex-deposit and make TCC Free Run. The following example is completely useless ACC and PSW. ORG 0JMP INITORG 8TCCINT: BC RF, TCIF Manager, according to the specified time, the specified Task service, the Task that is not assigned to time can be executed.