"I. summary of single chip microcomputer programming
1. We should form the good habit of summarizing. Summarizing is not only a summary of our own learning, but also a review and deepening of the learning process. It can also avoid making mistakes for the second time.
2. Before writing the program, you should have a familiar understanding of the project, know it well, and list a general framework. This step is very important to carefully consider how to layout and how to make the most reasonable layout. It is necessary to analyze which module to do first, the specific steps of the module, how to name each function, the connection with other modules, etc. You'd better take a piece of paper and write down the important process.
3. For the modular programming of C language, we should first divide each module, program one module by one module, determine a sequence, and write the next module after the module is successful. For the header file, write the header file of the module after the module is written.
4. Don't ignore the warning, which means that there must be irrationality in the procedure. Find out its source and find a solution. When looking for sources, you should be targeted. You can search the information on the Internet or ask others for advice. For example, the main function in another project is added to this project. There are also duplicate function names. In addition, the reasons are analyzed according to the experimental phenomena, which are progressive layer by layer. In addition, the wrong interface was selected during port definition. Sometimes, if you can't solve it, take a break. It's also good to think about it. No matter how simple it is, we should also pay attention to it. There may be mistakes.
2、 Simple summary of chip operation
The operation of the chip is mainly the operation of the on-chip registers. The on-chip registers mapped on the memory have their own unique address, which is the operation of the corresponding address. Look at the chip, first look at the sequence diagram, then understand the corresponding registers, understand how to operate, define the required ports (the program can identify), and write and read operation programs.
How to write data into the chip, how to read data, and through which port to input or read (the most important place).
When connecting chips through a bus, we must first understand the protocol of the bus. The chip connected by I2C bus mainly controls the chip through the bus.
1. One 74HC595 of the lattice is used for column selection, and the other two are used for color selection. The lattice is equivalent to a collection of diodes. Only when one end is given a high level and the other end is given a low level, can the diodes be on. Just choose different colors at one end.
Selection of timer working mode: the high four bits set timer T1 and the low four bits set t0. Then, the last two bits of each mode set the working mode. When setting two timers, pay attention to using or (|). When using an interrupt, note that after entering the interrupt, the reset should be cleared.
2. Serial port transceiver: baud rate is generally set in mode 2 (automatic reload initial value). Because different devices have different data processing capabilities, baud rate is set mainly to take care of low-speed devices and communication between them. The interrupt flag bit shall be cleared by software. When setting the serial port interrupt, no matter which generation of transceiver can enter the interrupt function, so pay attention to setting the interrupt function( Self perception is generally set as a function (upper computer or lower computer).
When sending an interrupt, you should solve how to enter the interrupt for the first time, so you should send it first, and then you can enter the interrupt. Only one byte can be sent at a time, and the next bit can be sent only after Ti is set to one.
3. Pcf8591ad conversion has four channel inputs. When reading pcf8591, select which channel and read the input voltage of that channel. The converted data is stored in the chip and then read out. When reading, first write the address of the chip, then write the sub address of the device (0x40 | channel number), and then the read data.
4. DA conversion is to first write the device address into the chip, write the sub address (0x40) and write the digital quantity to be converted.
Device address chip information is introduced.
5. For the LCD, after writing the data display, it will always display without continuous refresh. If you want to change, you have to re-enter.
6. For the DS1302 clock chip, when reading data, the first bit of data is read out at the falling edge of the eighth clock when writing data, and then prepare for the next output. Pay attention to the writing method of the program and the position of the return value.
7. DS1302 indicates the register first, and then writes data to it. The register on the chip data indicates the address( I don't understand the write protection program yet. Isn't it always written? Why is write protection turned on?)
(according to the previous great Xia, you can set a flag after the initialization time. With this flag, you don't need to initialize the time again. However, if the ram of MCU cannot save this flag after power failure, the ram of DS1302 can be used to save this flag and read it after power on. I am also a beginner. I also plan to use DS1302 recently. I don't know if the statement is correct. I haven't implemented it yet. Communicate more)
8. It's better to write about initialization in case you forget it later. Sometimes, when reading or writing, the first operation is the lowest bit or the highest bit, which can be determined according to the timing diagram.
9. For infrared transceiver, when receiving, it determines whether it is high level or low level according to the time between the two falling edges. When writing a program, first use a timer to determine the time, save it, and then convert it into binary (see more about the writing method of the program, which is very good).
10. Stepping motor: it is mainly used for switching. The torque of stepping motor decreases with the increase of speed. It is mainly used for automatic feeding of parts processing on machine tools. It can also be used in control places with high precision.
Stepper motor is an open-loop control element stepper motor that converts electric pulse signal into angular displacement or linear displacement. In the case of non overload, the speed and stop position of the motor only depend on the frequency and number of pulses of the pulse signal, and are not affected by the load change. When the stepping driver receives a pulse signal, it drives the stepping motor to rotate a fixed angle in the set direction, called "step angle", and its rotation runs step by step at a fixed angle. The angular displacement can be controlled by controlling the number of pulses, so as to achieve the purpose of accurate positioning; At the same time, the speed and acceleration of motor rotation can be controlled by controlling the pulse frequency, so as to achieve the purpose of speed regulation.
11. Servo motor: (servo motor) refers to the engine that controls the operation of mechanical components in the servo system. It is an indirect speed change device of auxiliary motor. The servo motor can control the speed and position accuracy very accurately, and can convert the voltage signal into torque and speed to drive the control object. The rotor speed of the servo motor is controlled by the input signal and can respond quickly. In the automatic control system, it is used as an actuator, and has the characteristics of small electromechanical time constant, high linearity and starting voltage. It can convert the received electrical signal into angular displacement or angular speed output on the motor shaft. It is divided into DC and AC servo motors. Its main feature is that when the signal voltage is zero, there is no rotation, and the speed decreases at a uniform speed with the increase of torque.
DC motor: large range, all on the trolley.
12. Overview of Chinese characters:
In order to output Chinese characters on the display or printer, the Chinese characters are designed into a dot matrix according to the graphic symbols, and the corresponding dot matrix code (font code) is obtained.
Chinese characters encoding Chinese characters (ID number) is the same as encoding Chinese characters in computers. The Chinese character code formed for the convenience of Chinese character input is the input code, which belongs to the external code of Chinese characters. The input code is diverse due to different coding methods. The Chinese character code formed to display and print out Chinese characters is font code. The computer finds out the font code of Chinese characters in the font library through the internal code of Chinese characters and realizes its conversion.
Internal code
According to the provisions of the national standard code, each Chinese character has a certain binary code, but this code will conflict with the ASCII code when processed in the computer. In order to solve this problem, add 1 to the first byte of the national standard code. Because the ASCII code only has 7 bits, the "1" in the first place can be used as a sign to identify the Chinese character code. When the computer processes the code with "1" in the first place, it is understood as the information of Chinese characters, and when it processes the code with "0" in the first place, it is understood as ASCII code. After such processing, the national standard code (internal code) is the internal code.
If we replace the "." of the "mouth" figure with "0", we can get the font code of "mouth" vividly: 0000H 0004h 3ffah 2004h 2004h 2004h 2004h 2004h 2004h 2004h2004h2004h 3ffah 2004h 0000H 0000H. When the computer wants to output the "port", first find the first address of the display font, calculate according to the internal code of the "port", then find the font code of the "port", and then scan the screen successively according to the font code (binary) through the control of the character generator. The place where "0" in the binary code is empty and the place where "1" is bright, So you can get the character graphics of "mouth".
The Chinese character font is arranged in the order of the national standard code and stored in the memory in the form of binary files to form the Chinese character font library, also known as the Chinese character font library
Two coding methods, see header file
GB1616.h
1 / / - ------------------ data structure definition of Chinese font------------------------//
2 struct typFNT_ Gb16 / / Chinese font data structure
3 {
4 unsignedchar Index[3]; // Chinese character internal code index
5 unsignedchar Msk[32]; // Dot matrix code data
6 };
seven
8/////////////////////////////////////////////////////////////////////////
9 / / Chinese font table//
10 / / Chinese character library: Song Ti 16.dot, horizontal mode, high left, data arrangement: from left to right, from top to bottom//
11 /////////////////////////////////////////////////////////////////////////
12 conststruct typFNT_ GB16 codeGB_ 16 [] = / / data table
13 {
14 /*------------------------------------------------------------------------------
15 ; Source file / text: Xu
16 ; wide × Height (pixels): 16 × sixteen
17 ------------------------------------------------------------------------------*/
18 "" Xu "", 0x10,0x80,0x10,0x80,0x21,0x40,0x42,0x20,0x94,0x10,0x1b, 0xec, 0x20,0x80,0x60,0x80,
19 0xAF,0xF8,0x20,0x80,0x22,0xA0,0x24,0x90,0x2A,0x88,0x21,0x00,0x00,0x00,0x00,0x00,
This structure is very simple: one is the internal code, and the other is the dot matrix sequence. In the past, the dot matrix library was placed according to the internal code sequence, and the internal code index is not required. If only some Chinese characters are placed, the internal code index is required( The Chinese character "Xu" in front is to find the dot matrix sequence of the word when you want to output "Xu". This dot matrix sequence is written by yourself. When it is displayed with 1602, there is no need to write it because there is an English dot matrix sequence in the chip.) generally, the internal code is two bytes, and one byte is added with a tail 0. In this way, The Chinese character string can be placed directly at the inner code of the Chinese character;
codeGB_ 16[k].Index[0]
codeGB_ 16 [k] indicates that there is a structure typfnt_ The array of gb16 is called codegb_ sixteen
codeGB_ 16 [k] is the K + 1st member in the array
Index is the structure typfnt_ Gb16, so codegb can be used_ 16 [k]. Index
At the same time, index is an array, so you can index [0]
if((codeGB_ 16[k].Index[0]==c[0])&&(codeGB_ 16[k].Index[1]==c[1]))
&&Is a logical and operator
It means that the values on both sides of the & & symbol are true, and the value of & & is true, that is, true & & true = true
This sentence means
codeGB_ 16 [k]. Index [0] = = C [0] and codegb_ 16 [k]. Index [1] = = C [1] simultaneously established
If the following statement is executed
codeGB_ 16 [] is a structure array, codegb_ 16 [k]. Index [0] is the 0th element value of the index member of the kth structure of the structure array.
13. 12864 LCD:
Each display point corresponds to a binary number. 1 means on and 0 means off. The ram that stores these lattice information is called the display data memory. To display a graphic or Chinese character is to write the corresponding dot matrix information into the corresponding storage unit.
The address counter (AC) of the drawing RAM will only automatically add one to the horizontal address (x-axis). When the horizontal address = 0Fh, it will be reset to 00h, but it will not automatically add one to the vertical address. Therefore, when multiple data are written continuously, the program needs to
Determine whether the vertical address needs to be reset
1. Drawing RAM (gdram)
Drawing display RAM provides 128 × 8-byte memory space. When changing the drawing ram, first continuously write the horizontal and vertical coordinate values, and then write two bytes of data to the drawing ram, and the address counter (AC) will automatically add one to the horizontal address (x address), and reset it to 00h when the horizontal address is 0xfh; It will not carry the vertical address and automatically add 1. During writing to the drawing ram, the drawing display must be turned off,
[CPP] view plain copy / / display Chinese characters
Our other product: