[SCM learning] Lesson 5: The necessary preparations before writing code

[Ms. Zhu Course Summary] Invasion


The first part, chapter list

1.5.1. Introduction and installation of Keil software

1.5.2. Basic usage demonstration of Keil

1.5.3. Basic introduction to C language

1.5.4. Basic concepts of C language

1.5.5. Overall process combing

1.5.6. Follow the data manual to learn MCU 1

1.5.7. Follow the data manual to learn MCU 2

1.5.8. Follow the data manual to learn MCU 3

1.5.9. Follow the data manual to learn MCU 4

1.5.10. Binary and IO ports


Part Two, Classroom Records


1.5.1. Introduction and installation of Keil software


1.5.1.1. IDE concept
(1) IDE ( Integrated Development Environment  ) is an integrated development environment, which is a complete software system for development.
1.5.1.2 Introduction to Keil uvision
(1) Development:  Introduction to Keil
(2) We use keil v5, generally speaking of K5 for microcontrollers and embedded devices
(3) Where is the installation package? Network download, development board CD
1.5.1.3, Installation and cracking ( win7 and above must remember to run as an administrator before cracking )

    Link: Installation and cracking

    Local guide file: \Development board CD-ROM materials\Course supporting ARM3.0 development board CD-ROM materials\Keil C51 installation and cracking package

1.5.1.4, Keil and MDK
(1) Originally it could only be used to develop 51 single-chip microcomputers, called Keil
(2) Later, ARM company acquired Keil software, based on Keil extended the development of ARM, mainly used to develop ARM Cortex-M series single-chip microcomputers (STM32 for example), the software name is changed to MDK
(3) Just now we installed Keil C51, which can only be used to develop 51 single-chip microcomputer programs. If you want to develop an ARM Cortex-M microcontroller, you need to extend the MDK installation package. You can install it or not. C51 development does not require Pack.

So in the future, Keil is the development of 51 single-chip microcomputers, and MDK is the development of ARM single-chip microcomputers.

Remember this link: KEIL 5 pack offline package Stm32f1/f2/f3/f4    download speed is many, many times faster than the official website!


1.5.2. Basic usage demonstration of Keil


1.5.2.1. Use Keil to open an existing project
(1) IDE (Keil) to develop software, you need to create a project (Project) first, Keil software needs some project files to manage the code in the project.
(2) I can directly open the project created by others in advance using Keil software. There are two opening methods
. The first one: double-click the (project name.uvproj) file after entering the project to open it . Open extensions without extensions.
The second one: After opening the Keil software directly through the shortcut icon, open the project in the software (open project in the menu bar) . When we directly double-click the shortcut icon to open the keil software, the project that was opened when it was closed last time will be opened by default (if the project was not opened when it was closed last time, no project was opened when it was opened this time).

1.5.2.2. Compilation project
(1) There are many files in the project, which are simply divided into three categories: project files, source files, and target files.
     Project files are the files needed by Keil software, and it has nothing to do with our writing programs. The
     source files are us. The source code written is the
     target file we programmed and compiled by the compiler and other tools in Keil to generate the file after compiling our source file, and finally the target file is needed to burn into the microcontroller.
(2) When our project is just created (empty project), only the project file is available. At this time, we have to write and add the source code. After the code is written, there will be the project file and the source file. At this time, click the compile operation to get the target file. .
(3) Errors and warnings may be reported during compilation. Errors are very serious problems. At this time, the compilation is invalid and cannot generate the final burnable program file. You must eliminate the errors and re Compilation works; warnings are minor issues, sometimes they can be ignored and sometimes not, depending on experience.
(4) It is recommended to directly click Rebuild in the shortcut icon bar to compile when compiling .

1.5.2.3. Create a new project in Keil (see "Puzhong 51 MCU Development Strategy--A7.pdf")
(1) It is recommended to close the previous project before creating a new project
(2) Menu bar: Projcet->new uVision Project, select a suitable directory to save future engineering projects, and enter a project name


(3) Choose CPU, generally choose Microchip->AT89C52 , it is better to use Search to search, it will be faster, click OK. Pop up to choose "Whether to add standard 8051 start code", choose No, confirm it is ok. Thank you blogger Bai Ming for his article: About the latest version of KEIL5 without ATMEL (including 89C51 chip)

(4) Now you can start writing the code yourself, or directly copy an already written code file and add it to our project. Here we create a new file, write the code, and name it "main.c"

(5) But the written main.c is not added to the project file, select Source Group1, right-click and select "Add Existing Files to...", and then add main.c to the project.
(6) Click Build to compile and found a problem: there is no .hex file that can be used for burning. There are many files generated during compilation, but only this .hex file is the file we finally need and can be used for burning. The others are all intermediate file (miscellaneous)
solutions: one more step of configuration, open the "Target Options" in the quick menu bar, in the pop-up multi-select box, click the Output menu, click the Creat HEX File below, and then close the menu , Just rebuild.

 (7) The last step is to burn and download the program!


1.5.3. Basic introduction to C language


1.5.3.1. Assembly language and C language
(1) Assembly language programming is more difficult than C language
(2) You can complete tasks in assembly or C language, and write programs
(3) Recommended learning route; Use C language to learn about MCU, Then go to expand learning assembly

1.5.3.2. Standard C language and Keil C51's C language
(1) C language was not specifically invented for 51 single-chip microcomputers, and the use of C language is very wide.
(2) Standard C language is independent of various application fields The standard C language is slightly different from the specific C language of various platforms.

1.5.3.3. Learning methods and ideas
(1) Those who have learned the basic concepts of the C language are easy to learn
(2) Those who have not been exposed to programming languages ​​at all can even learn by rote at the beginning (memory can help understand and understand Can promote memory)
(3) C language keywords are abbreviations of English letters, which can assist memory
(4) First learn the basic concepts of C language, and then explain the rest


1.5.4. Basic concepts of C language


(1) Keyword, a word with special meaning defined by the language itself in C language
(2) Function, which is the basic unit of code organization in C
(3) Variable, which is the amount that can be changed during the running of the program
(4) The header file, which is the .h file, is included by the source file and is a supplement to the source file.
(5) The source file, which is the .c file, is actually a program file.
(6) The executable program is generated after the source file is compiled The hex file
(7) comments can be burned and executed in the microcontroller. There are two comment methods in C language, one is /* */, and the other is //. The content of the comment is not regarded as the official content of the code, but For the description of the code, the comments are for people to see. The result of deleting the comment of the entire program remains unchanged.


1.5.5. Overall process combing


1.5.5.1. Program development process
(1) Source code writing
(2) Compilation to generate executable program
(3) Burning
1.5.5.2, MCU workflow
(1) Single-chip computer power-on
(2) The clock module starts oscillating, the CPU has Clock beats, each module inside the single-chip microcomputer starts to work
(3) CPU reads executable programs one by one from ROM to execute, RAM stores variables (corresponding to variables defined in C language programs) to cooperate with program execution. Until shutdown
1.5.5.3, the program is called out
(1) The program cannot be written to meet the requirements at once
(2) First solve the compile-time error
(3) Then solve the runtime problem


1.5.6. Follow the data manual to learn MCU 1


1.5.6.1. Let me talk about these points first
(1) What the data book does
(2) The content structure of the data book
(3) How to use the data book: First read in general, then read the module
1.5.6.2, STC90C51 briefly
(1) ) Refer to page 6 of the data manual
(2) Problems with 12T, 6T and 1T: The typical 51 single-chip microcomputers are all 12T. 12T means that the 51 single-chip microcomputer will divide the external clock frequency by 12 before giving it to the CPU (if external The crystal oscillator is 12MHz, the external clock frequency is 12MHz, and the main frequency of the internal CPU is 12MHz/12=1MHz), 6T means CPU clock frequency = external clock frequency/6, 1T means internal CPU clock frequency = external clock frequency /1. So 1T MCU is the fastest.


1.5.7. Follow the data manual to learn MCU 2


1.5.7.1, STC90C51 internal structure block diagram
(1) bus, communication line between the internal module of the single-chip microcomputer
(2) module, independent unit with certain functions inside the single-chip microcomputer
(3) requirements: everyone can understand the legend and know the diagram What does each indicate. When we have very little understanding of the original modules inside the CPU, we actually don't see anything from the block diagram. There is actually a lot of information conveyed in the block diagram, which can be seen when I look back in the future.

1.5.7.2, MCU pin diagram
(1) DIP package and SMD package
(2) Pin number and name
Each pin has a number, this number is mainly used to describe the function of the pin when reading the document It is used for marking, which has nothing to do with programming. So the general pin number is not important.
In addition to the number, each pin has a name. The name of this pin is more important. Because the name of this pin is the same as the name we control this pin in the future, the name of the pin is related to programming.

1.5.7.3. About the emulator and ISP
(1) The emulator. As the auxiliary equipment for the early development of single-chip software, many of the early single-chips could only be programmed once, or did not provide debugging functions, and software development was very difficult. Later, the MCU manufacturer specially invented a device called an emulator, which can simulate the effect of the single-chip microcomputer and can be used to debug programs. So at that time, after I bought a single-chip computer, I had to buy an emulator, and use the emulator to develop it, and then burn it to the MCU to run.
Defects: 1. One emulator corresponds to one SCM model. 2. The emulator is expensive.
(2) Because emulators are very expensive, some companies have developed software emulators called soft emulation. For example, keil has its own software simulation function.
(3) Later the emulator was abandoned and upgraded to a debugger. The idea of ​​the debugger is: program development is still in the microcontroller, but we can use a dedicated debugger to directly complete the simulation in the microcontroller. A typical debugger is Jlink. The debugger is cheaper than the emulator, so it is a better solution. Most of the current microcontrollers support the debugger program.
(4) Sometimes the development program does not use the debugger for single-step debugging, but directly opens the program and downloads the program to the microcontroller through the serial port (ISP download) to run, and then directly judge the positioning problem according to the running phenomenon , Then solve the problem, and finally complete the program software development. In this way, a dedicated hardware emulator and debugger are not needed, and sometimes the software emulation function is used in conjunction. You can also use the serial port to print, or LED lights to debug.
Summary: 3 and 4 are the mainstream methods we now develop software. Relatively speaking, inexperienced people prefer 3 (experienced like 4); the later (microcontroller to embedded to the Internet of Things), the less 3 is used, the more 4 is used;
the direction of our course is: 51 The MCU stage uses software simulation combined with the ISP download method to debug the program. The STM32 learning stage is a combination of the debugger and the ISP download method. When it comes to the embedded stage, it returns to the 4 method, and will not use Jlink in the future. The debugger is out.


1.5.8. Follow the data manual to learn MCU 3


1.5.8.1. Browse the selection table

1.5.8.2 Introduction to the minimum system of the single-chip microcomputer
(1) The minimum system of the single-chip microcomputer refers to the single-chip microcomputer plus the minimum peripheral circuits, and then it can still work.
(2) There are 3 parts of circuits in the smallest system: power supply circuit, power-on reset circuit, crystal oscillator circuit

1.5.8.3. Pin definitions
(1) Power supply and other pins, there are some pins on the microcontroller that are used to support the microcontroller, such as VCC, GND, RST, etc. These pins have nothing to do with programming, and the program cannot control these pins. foot. Software engineers don't care about these pins, hardware engineers are very concerned.
(2) IO port. The IO port is a window for the single-chip microcomputer to interact with an external circuit. The external circuit inputs (input) information into the single-chip microcomputer through IO, and the single-chip microcomputer outputs (output) information to the outside through the IO port. Most of the pins in the single-chip microcomputer are IO (the pins at the beginning of P are all IO). In the future, the program running in the single-chip microcomputer will interact with external circuits by operating these IOs to achieve the purpose of the program.
(3) Pin multiplexing. A common pin is a pin with only one name and one function; some pins have two names (for example, P3.0/RxD), this pin has two functions (meaning that this pin can be used at the same time) Two things, but to say that this pin can work in two different modes at different times), this pin can work in a certain mode at a certain time through software programming. There is no correlation between the two modes of a pin, and the configuration work in A mode has nothing to do with B mode.
Why do pin multiplexing? It is purely to save pins.


1.5.9. Follow the data manual to learn MCU 4


1.5.9.1, package size
1.5.9.2, naming rules


1.5.10. Binary and IO ports


1.5.10.1, binary and bit
1.5.10.2, bit (bit, b) and byte (byte, B)
(1) 1 byte = 8 bits
1.5.10.3, first understanding of IO port
(1) What is IO ( input/output), the IO of the single-chip microcomputer is physically represented as the pin of the single-chip microcomputer
(2) The important significance of IO to the single-chip microcomputer.
(3) How many IOs does the microcontroller have
(4) The organization of IO. First of all, many IOs of a single-chip microcomputer are divided into multiple ports (ports), and a port is composed of several IO pins (8 in many cases). It can be understood that a port is a group of IO pins.
(5) How to program and control IO


10MB  10Mb
100Mbit/s        12.8MB

Guess you like

Origin blog.csdn.net/qq_27148893/article/details/109293088