Wednesday, December 29, 2010

Weak current College】 【MCU c language tutorial-lesson one: building your first C projects】.

<br> 51 MCU C language learning Miscellanies Learn SCM is not an easy task, to purchase high price of programmer, emulator, to learn a programming language, there are many types of single-chip select is really a headache. 51 in the numerous .single-chip architecture chips popular long learning material is relatively many, is dropping one of the better choice. 51 programming language commonly used two types of Assembly language, one is the C language. The Assembly language of the machine code generated is very efficient but .readability is not strong, complex procedures is difficult to read, and the C language in most cases its machine code generation efficiency and assembly-language equivalent, but readability and portability are far more than Assembly language and C language can also be embedded into the Assembly .to address the high effectiveness of the code. For the development cycle, in large software written in c language development cycle is usually much smaller than Assembly language. The above advantages of C language, I'm learning with the C language. Later in the .tutorial also just in the learning process of some study notes and essays, tidying up and modify, hope to join the Exchange with the wing, fertilizer, learning, progress together. <br> * Note: you can say for sure that this tutorial is .for beginners or novice, I myself have just amateurs, is expected to master the pointing errors you heroes. <br> Bill Rammell 2003-3-30 pnzwzw@cdle.net first lesson establishes your first C program using C language would use to C .compiler in order to write ac program compiled to machine code, so that the SCM can perform write good programs. KEIL uVISION2 is many SCM application development software in one of the best software, it supports many different companies MCS51 chips, its schema set to edit ., compile, simulation is equal to one, while also supporting, PLM, compilation and C language programming, the interface and commonly used Microsoft VC + + interface similar to that of a friendly interface, easy to learn and use, in the debugger, software .simulation also has very powerful features. So many development 51 application engineers or ordinary single-chip microcomputer enthusiasts, but also for its 10 fertilizer. <br> The above outlined KEIL51 software, to use the software, the necessary first KEIL51 to install it. .KEIL51 is a commercial software for our ordinary fans can go to the KEIL Chinese agent ucos website, downloading can compile 2 k DEMO Edition software, the Basic can meet the General personal learning and development of small applications. (The installation methods and General software do .not quite here introduced) <br> After installation, you can hardly wait to build their first C program project? here let's set up a small project. Perhaps your hand is not a piece of experimental Board, not even a single chip, but no .relationship we can see through the KEIL software simulation program to run. <br> First of course is run KEIL51 software. How to open? Oh! you want to learn computer from scratch. Oh, a joke, I think the readers will not mention .: P. Run for a few seconds to appear as in Figure 1-1 on the screen. <br> <br> Figure 1-1 startup screen <br> Then follow these steps to build your first item: <br> (1 .) click on the Project menu, select the drop-down menu that pops up in the New Project, as in Figure 1-2. Then bring up a standard Windows file dialog window, shown in Figure 1-3, this stuff must all be .met N times, usage tips also not here to say that subsequent chapters will no longer appear similar. In the file name box, enter your first C program project name, here we use the "test", this is the name of the author, .you don't have to copy it, as long as you comply with the file name of the Windows file rules. "Save" the file extension after uv2, KEIL uVision2 project file extension, then we can click on this file to open the items .previously done. <br> <br> Figure 1-2 New Project menu <br> <br> Figure 1-3 file window <br> (2) select the MCU that here we select common Ateml company AT89C51. The screen shown in .Figure 1-4 below. What is the function, AT89C51 features?, without hurry illustration on the right there is a simple introduction, later chapters will make more detailed introduction. After completing the above steps, we can write a program. <br> .(3) first of all we want in a project to create a new program file, or to join the old program files. If you do not have ready-made program, create a program file. Some of the KEIL program Demo, here we .are in a C program, for example describes how to create a C program and how to add to your first project. Click on Figure 1-5 in 1 of the new file shortcut buttons, 2 a new text editing window, this operation can also .be accessed from menu File-New or the shortcut CTRL + N. OK, now you can write a program, the cursor has been appearing in text edit window, waiting for our input. The first program, write a simple and straightforward. Here is .a classic, Oh, if you read another program book may have similar programs: # include <AT89X51.H> <br> # include <stdio.h> void main (void) <br> {<br> SCON = 0x50 .; / / Serial mode 1, allows to receive <br> TMOD = 0x20; / / Timer 1 timing mode 2 <br> TCON = 0x40; / / Set timer 1-countBR> TH1 = 0xE8; / / 11.0592MHz 1200 baud rate .<br> TL1 = 0xE8; <br> TI = 1; <br> TR1 = 1; / / Start the timer <br> <br> while (1) <br> {<br> printf ("Hello World! \ .n "); / / Displays Hello World <br>} <br>} <br> <br> Figure 1-4 to select the chip <br> <br> <br> Figure 1-5 new program files <br> .This program features are continuously from the serial port output "Hello World!" Characters, regardless of the program syntax and meaning, first take a look at how to integrate it into your project and how to compile the test run. <br> (4 .) click on Figure 1-5 of 3 saved new programs, or you can use menu File-Save or the shortcut CTRL + S to save it. Due to the new file saved will pop out similar to figure 1-3 file operations window, .we put the first program named test1.c, saved in the project in the same directory, then you will find that Word has a different color, description of the C syntax checking KEIL. Figure 1-6 the mouse on the left side of the .screen Source Group1 folder icon on the right click popup menu, where you can do to increase the reduction in the project file, and so on. We? quot; Add to Group 'Source File Group 1' pop-up window, select the file .just saved the file, press the ADD button, close the file Windows, program files have been added to the project. At this point in the Source folder icon to the left a Group1 a little plus sign on the instructions, a file group with the .file, click it to expand the view. <br> <br> Figure 1-6 the file to the project file group <br> (5) C program file has been added to the project, we have compiled the following left running. .This project, we just make learning a new program item and compile run simulation method, using default settings for the compilation of the software, it will not be generated for chip Programmer's HEX file, how to set the generate HEX file, please see the following .third lesson. Let's look at Figure 1-7, Figure 1, 2, 3 are compile button, different is 1 is used to compile a single file. 2 compile the current project, if a previously compiled once files are not doing dynamic editorial changes ., and then click is not recompiled again. 3 is recompiled, every click on a link will be once again compile once, regardless of whether the program has changed. In 3 right is to stop the compile button, click on the first three of the .stop button to take effect. 5 of them in the menu, I personally would not use it. Hei Hei, this project has only one file, you press a 123 can be compiled. Press the? good fast Oh, huh, huh. You .can see in the 4 compile error message and the use of system resources, etc, then we want to look up the wrong depends on it. 6 is there a small magnifying glass button that is open to close debug mode / button, it also exists .in the Debug menu, shortcut keys Debug-Start \ Stop Session as Ctrl + F5. <br> <br> Figure 1-7 compiler <br> (6) to enter debug mode, the software window styles is roughly as in Figure 1 .-8. Figure 1 is running, when the program is in a stopped state, 2 to stop, when the program is running. 3 is reset, the simulation of chip reset, the program back to the beginning of the implementation. 4 we can .open 5 serial debugging window, the window we can see from the 51 chip serial port input and output character, here's the first project is here to see the results. These are also in the menu, there is no longer a presentation you may wish to .look, and other features are also in later lessons gradually introduced. First by 4 open serial debug window, and then press the run button, then you can see the serial debug window keep playing? quot; Hello World! ". Oh, is not .difficult to? this completes your first C program. Finally we have to stop the program to run back to the file in edit mode, press the stop button and then press open / close debug mode button. And then we can hold off KEIL, and .other related operations. <br> At this point, the first lesson has ended, the preliminary study a number of project files KEIL uVision2 create, compile, run, and the basics of software simulation. Which have been mentioned in some of the features of .the use of shortcuts, indeed in the actual development of the application in the application shortcut keys can greatly improve work efficiency, it is recommended that we can use there here mentioned how by analogy to similar operations. <br> <br> Figure 1 - .8 debugging to run the program <br> This tutorial all 9 classes, please query other related 8 class, combining the last source program learning! C51 tutorial full version of matching source download. rar.

No comments:

Post a Comment