SCM programming and chip operation simple summary

First, microcontroller programming summary

1. It is necessary to develop a good habit of summing up. Summarizing is not only a summary of one's own learning, but also a review and deepening of the learning process. It can also avoid the second mistake.

2. Before you write the program, you must have a familiar understanding of the project. Be aware and list out a rough framework. Careful scrutiny of how to layout, how to lay out the most reasonable, this step is very important. To analyze which module to do first, the specific steps to the module, how to name each function, and the convergence of other modules. It's best to take a sheet of paper and write down the important process.

3, for the c language modular programming, we must first divide the various modules, a module and a module of programming, determine a sequence, according to the order, after the success of the module to write the next one. For the header file, write the module's header file after the module is written.

4. A warning should not be overlooked, stating that the procedure must be irrational. It is necessary to clarify its source and find a solution. When looking for sources, you must be targeted. You can search the Internet for information in this area or ask others for advice. For example, actually add the main function in another project to this project. There are actually duplicate function names. There are also analysis of reasons based on experimental phenomena, and the layers are progressive. There is actually an interface selected when the port is defined. Sometimes, I really can't solve it, just take a break and I think it's good. In a simple place, you should also pay attention to it. It is possible to make a mistake.

Second, the chip operation is simple summary

The operation of the chip is mainly the operation of the register in the chip. The register in the chip has its own unique address mapped on the memory, which is the operation of the corresponding address. Look at the chip, first look at the timing diagram, and then understand the corresponding register to understand how to operate, define the required port (program can be identified), write the write operation program and read the operating program.

How to write data into the chip, how to read data, and which port to input or read (most important place).

When connecting the chip through the bus, you must first understand the protocol of the bus. I2c bus connected chip, mainly through the bus to control the chip.

1. A 74hc595 in the dot matrix is ​​used for column selection, so that the outer two are used for color selection, and dot matrix is ​​equivalent to the collection of diodes.

A high level at one end and a low level at the other end will allow the diode to light. Only one end chooses different, bright different colors.

The selection of the timer mode of operation: the upper four bits set the timer T1 and the lower four bits set T0. Then the last two bits of each mode set the operating mode. When setting up two timers, pay attention to use or (|). When using an interrupt, note that the clear is cleared after entering the interrupt.

2, serial port transceiver: baud rate settings generally use mode 2 (automatic reload initial value), because different devices, the ability to process data is different, set the baud rate is mainly to take care of low-speed devices and to communicate with each other. The interrupt flag is cleared by software. When setting the serial port interrupt, no matter which one is sent or received, it can enter the interrupt function. Therefore, set the interrupt function. (Self-sense generally set a function, as a host or a lower machine).

If the transmission is interrupted, it is necessary to solve how to enter the interrupt for the first time. Therefore, it is necessary to send it once. After that, the interrupt can be entered. Only one byte can be sent at a time, and the next bit can only be sent after TI is set.

3, Pcf8591ad conversion, there are four channels of input, read pcf8591, strobe which channel, read the channel input voltage, converted data stored in the chip, and then read. When reading, first write the chip's address, write the device's subaddress (0x40|channel number), and then read the data.

4. Da conversion is to write the device address to the chip first, write the subaddress (0x40), and write the digital quantity to be converted.

Device address chip data is introduced.

5, for the liquid crystal display, after writing the data display, he will always show, do not need to continue to refresh, in order to change, only re-enter.

6. For the ds1302 clock chip, when reading data, the first data is read at the falling edge of the eighth clock when data is written, and then the next data is prepared. Note the writing of the program, and pay attention to the return. The location of the value.

7. First specify the register in Ds1302 and write data to it. The register on the chip data indicates the address. (The write-protection office program is not yet understood. Is it not always written? Why is write protection also turned on?)

(According to the previous heroes, you can set a flag after the initialization time. With this flag, you do not need to initialize the time. However, if the MCU's RAM cannot save this flag after the power is turned off, you can use the DS1302's RAM to save the flag. After reading the electricity, read the logo. I am also a beginner. I also plan to use the DS1302 recently. I do not know whether to say it or not. I have not implemented it yet.

8, it is best to write about initialization, to prevent later forget. Sometimes when reading or writing is concerned, the lowest or highest bit is first manipulated, which can be judged from the timing chart.

9, for infrared transceiver, when receiving, he is based on the length of time between the two falling edges to determine whether the level is high or low, write the program, the first use of the timer to determine the length of time, save, and then converted into Binary (the program written more to see, very good).

10. Stepping motor: mainly used for switching, the torque of stepping motor decreases with the increase of speed. It is mainly used for automatic feed of parts processing on the machine tool. It can also be used for places with high precision control.

A stepper motor is an open-loop control stepper motor that converts electrical pulse signals to angular displacement or linear displacement. In the case of non-overloading, the speed of the motor, the position of the stop depends only on the frequency and number of pulses of the pulse signal, and is not affected by the load change. When the step driver receives a pulse signal, it drives the stepper motor. The set direction is rotated by a fixed angle, called the "step angle", and its rotation is performed step by step at a fixed angle. By controlling the number of pulses to control the amount of angular displacement, so as to achieve the purpose of accurate positioning; at the same time can control the pulse frequency to control the speed and acceleration of the motor rotation, so as to achieve the purpose of speed control.

11, servo motor: (servo motor) refers to the engine in the servo system to control the operation of mechanical components, is an auxiliary motor indirect transmission. The servo motor can control the speed and position accuracy very accurately. It can convert the voltage signal into torque and speed to drive the control object. Servo motor rotor speed is controlled by the input signal, and can react quickly. In the automatic control system, it is used as an actuator. It has characteristics such as small electromechanical time constant, high linearity and starting voltage, etc., which can receive the electrical signal. Convert to angular displacement or angular velocity output on the motor shaft. Divided into two major categories of DC and AC servo motor, its main feature is that when the signal voltage is zero there is no rotation phenomenon, the speed decreases with the increase of torque and uniform speed.

DC motor: The range is larger, and it is on the trolley.

12. Overview of Chinese characters:

In order to output the Chinese characters on a display or a printer, the Chinese characters are designed as bitmaps according to graphic symbols, and corresponding dot code codes (font codes) are obtained.

A unified coding method for expressing Chinese characters in a computer forms a Chinese character code called an internal code (such as a national standard code), and the internal code is unique (equivalent to the character's identity number). The Chinese characters encoded to facilitate the input of Chinese characters are input codes and belong to the external codes of Chinese characters. The input codes are different due to different encoding methods and are various. The Chinese characters formed for displaying and printing Chinese characters are coded as a font code. The computer finds the character code of the Chinese character in the font library by using the internal character code of the Chinese character to realize its conversion.

Machine code

According to the provisions of the national standard code, each Chinese character has a certain binary code, but this code will collide with ASCII code when it is processed inside the computer. To solve this problem, add 1 to the first bit of each byte of the national standard code. . Since the ASCII code only uses 7 bits, the "1" on the first digit can be used as a symbol for identifying the Chinese character code. When the computer processes the code with "1" at the top, it understands it as the information of the Chinese character. The code with "0" in the first place understands it as ASCII code. After this processing, the national standard code (inner code) is the internal code. 

If we replace the "." in this "mouth" graphic with "0", we can get the "mouth" font code very vividly: 0000H 0004H 3FFAH 2004H 2004H 2004H 2004H 2004H 2004H 2004H 2004H2004H 3FFAH 2004H 0000H 0000H. When the computer wants to output "port", it first finds the first address of the display font, calculates the code of the "port" according to the internal code of the "port", and then finds the font code of "mouth", and then passes the character generator according to the font code (uses binary). The control scans on the screen one by one, where an empty sweep of the "0" in the binary code, a bright spot of the sweep of the "1", and the character pattern of "mouth" can be obtained.

The Chinese character patterns are arranged in the order of the national standard code, and are stored in the memory in the form of a binary file, which constitutes a Chinese character font library, also known as a Chinese character font library, which is called a Chinese character library.

Two encoding methods, see the header file

GB1616.h

1 //------------------ The data structure definition of the Chinese character font ----------------------- -//

2 struct typFNT_GB16 //Chinese character data structure

3 {

4 unsignedchar Index[3]; // Chinese character index

5 unsignedchar Msk[32]; // Bitmap data

6 };

7

8///////////////////////////////////////////////// ////////////////////////

9// Chinese character form table //

10 // Chinese Character Library: Arial 16.dot, Horizontal Left High, Data Arrangement: From left to right, top to bottom //

11 /////////////////////////////////////////////////// ////////////////////////

12 conststruct typFNT_GB16 codeGB_16[]= //Datasheet

13 {

14 /*----------------------------------------------- -------------------------------

15 ; Source File/Text: Xu

16; width×height (pixels): 16×16

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 inner code, and the other is a lattice sequence. The previous lattice library is placed in the order of the inner code, and no inner code index is needed. If only part of the Chinese characters are placed, the inner code index is needed. (The previous Chinese character "Xu" is a sequence of lattices for finding the word "Xu". This matrix sequence is written by itself. When 1602 is displayed, because the chip has an English lattice sequence, Therefore, we do not need to write.) Generally, two bytes of the inner code are used on the line. The use of one more byte adds a tail 0. In this case, a Chinese character string can be placed directly at the inner code of a Chinese character.

codeGB_16[k].Index[0]

codeGB_16[k] indicates that there is an array of structures typFNT_GB16 called codeGB_16

codeGB_16[k] is the k+1 member of the array

Index is a member of structure typFNT_GB16, so it can be referenced by codeGB_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

This means that the values ​​on both sides of the && sign 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]

If the following statement is executed

codeGB_16[] is an array of structures, and codeGB_16[k].Index[0] is the 0th element value of the index member of the Kth structure of the array of structures.

13,12864 LCD:

Each display point corresponds to a single binary number, with 1 indicating light and 0 indicating off. The RAM that stores these dot matrix information is called a display data memory. To display a graphic or Chinese character is to write the corresponding dot matrix information to the corresponding storage unit.

The address counter (AC) of the drawing RAM is automatically incremented only by the horizontal address (X axis). When the horizontal address = 0FH, it is reset to 00H but the vertical address is not automatically incremented by one. Therefore, when the address is written continuously, When multiple documents are needed, the program must

Determine if the vertical address needs to be reset

1, drawing RAM (GDRAM)

The drawing shows that the RAM provides 128×8 bytes of memory space. When changing the drawing RAM, the horizontal and vertical coordinate values ​​are written consecutively, and then two bytes of data are written to the drawing RAM, while the address counter (AC) The horizontal address (X address) is automatically increased by one. When the horizontal address is 0XFH, it is reset to 00H; the vertical address will not be automatically incremented by 1. During the writing of the drawing RAM, the drawing display must be closed.

[cpp] view plain copy// Display Chinese characters

voiddispString (uchar X, Y, uchar *msg) //Which row is Y, and Y is which column. Msg

For Chinese characters

{

If(X==0) X = 0x80; // First line, Chinese character display coordinates

Else if(X==1) X = 0x90; // second line

Else if(X==2) X = 0x88; // Third line

Else X = 0x98; //the fourth line

Y = X + Y; //Y is 1 to the right

Write_com(Y); // write coordinates

While (*msg)

{

Write_data(*msg++); //Display Chinese characters

}

}

///////////////////////////////// //////////////// /////////////

// display image

Voiddisppicture(uchar code *adder)

{

Uint i,j;

//*******Display the upper half screen content settings

For(i=0;i<32;i++) // 32 column addresses in the upper half screen

{

Write_com(0x80 + i); //SET vertical address VERTICALADD

Write_com(0x80); //SET HORIZONTAL ADD

For(j=0;j<16;j++)

{

Write_data(*adder);

Adder++;

}

}

//*******Display the lower half of the screen settings

For(i=0;i<32;i++) //

{

Write_com(0x80 + i); //SET vertical address VERTICALADD

Write_com(0x88); //SET horizontal address HORIZONTAL ADD

For(j=0;j<16;j++)

{

Write_data(*adder);

Adder++;

}

}

}

For the C language, the defined variable is automatically assigned space, and its address is the name of the variable. By this name, the data can be retrieved in memory, and new data can be obtained through calculation. In the assembly, the programmer needs to define the storage space and send the data to an accumulator, etc. to perform operations. Each step requires a programmer to operate. The C language these processes by the compiler to complete.

Baidu search:

1, microcontroller C language, the memory of its variables is how to proceed? Is the compiler, intelligently in the compilation process to add the allocation and recovery of the code? The key is that I do the procedure, how to ensure that there is no memory overflow Wrong? If I'm doing recursive computing, memory requirements are hard to calculate on my own.

2. Will the SCM C language be constrained in the definition of variables? For example, the multiplication and division of floating-point data, and writing through assembly, the code is quite complex. If the direct C language is used to write, isn't it simple?

3. Is the address allocation of the ROM of the instruction and data automatically allocated by the compiler in the hex file generated by the single-chip C language? Can the user allocate?

Microcontroller program written in c language, first compiled by a program (like c51.exe), after the completion of the compilation, the variable storage space size has been arranged, but not yet assigned a specific address (address floating), followed by another The program (like a51.exe) is connected, after the connection, the specific address is determined

Recycling code? It should be reclaiming storage space.

If there are too many variables, the compiler will prompt the data segment too large, to ensure that there is no memory overflow error, the main concern is whether the stack overflow, rely on experience

SCM c language is generally prohibited recursive, generally avoid the use of recursive computing, SCM is not a PC, after all, will affect the speed, recursive, then use DSP chips more appropriate, in short, will pick the right chip

2:

The size of the variable (number of bits) is generally the same as the number of bits in the chip accumulator, such as 51 commonly used 8-bit, because it is 8-bit microcontroller

The microcontroller can define bit variables, but it is not possible to define bit arrays

Written in c language is just looking at the simple, the actual amount of code generated is the most, the microcontroller used to control almost no floating point operations, not only slow but also troublesome place, if it is DSP chip, it has a suitable hardware structure, will much better

3:

Usually it is automatically assigned,

Can be mixed with c language and assembly language programming, you can also use Keil C online assembly

Both the chip and external data exchange are performed through the port.

Audio Video Cable

Audio Video Cable:Video cable, referred to as video cable, is composed of video cable and connector. Among them, video cable is coaxial shielded cable with characteristic impedance of 75 Ω (Ω). Common specifications are divided into - 3 and - 5 according to wire diameter, single core wire and multi-core wire according to core wire, common specifications of connector are divided into pressure joint and welding joint according to cable end connection mode, and equipment There are BNC (commonly known as bayonet) and RCA (commonly known as lotus head). Audio cable, referred to as audio cable, is composed of audio cable and connector. The audio cable is generally a dual core shielded cable, and the common connectors are RCA (commonly known as lotus head), XLR (commonly known as XLR head) and trsjacks (commonly known as pen plug).

Audio Video Cable

ShenZhen Antenk Electronics Co,Ltd , https://www.antenkcon.com