51 MCU Learning Part 6 - 1.2 The first C51 program (lighting up the running light)

Publisher:RadiantBreezeLatest update time:2016-12-28 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Since the school's board is slightly different from the one I bought, for the sake of everyone's reading, all future program writing and burning will be based on the board given by the teacher.

1. Prepare in Advance 

  a Driver installation. Please note that it has been sent in the group. Please install the driver for the board.

 

  b Burning software (burner) stc-isp (It should be noted here that the chip on the board is from stc, and you can also see its model number stc89c52RC. You can use stc's burning software)

   Question: What is burning software?

A: It means downloading the machine language    you have written (C or assembly) into the microcontroller in a certain way. This is called burning. (Just understand it this way for now)

 

  c write software keil uVision 4 (I only use it to compile and generate hex files)

        notpad++ (I use it to write C51 code, and then copy it to Keil. It is great for writing code, and it is domestic software, and most importantly, it is free)

   Question: What is compiler software?

    Answer: Compiler software can compile a large amount of code you write in the compiler into executable corresponding files.

        In the microcontroller, keil is used to compile the written C code file into an executable .HEX file.

    

 

2 Let’s get started!

  1 Connect the board to the computer via USB. (You should know how to do it, right?)

  2 Open notapad++ and write c51 code (you can also write directly in keil, but I don’t like it, the reason will be explained later)

  

    Note! 1 #include is a header file (a bit like C language, right?)

        2 sbit LED1 = P1^0; is a bit operation. Please note that there must be a semicolon ";" at the end of the statement.

         LED1 is actually a variable name

        3 void main() is the main function and there is only one

    analyze:

        

 

 

 

 

 

 

 

 

 

 

P1^0 is P10, that is, P1.0 pin. There is such a sentence in the main function

  LED1 = 0;

  That is to set the P1.0 pin to a low level.

  About Level

  In our study, 0 is low level 0v  

         1 is high level 5v

  The level of the computer's serial port here is MAX232 high level -12v, low level +12v, so it cannot be directly connected to the microcontroller

  But! There is a MAX232 chip in the microcontroller that can convert the voltage level (you can find the development board schematic pdf)

  OK, now we don't have to worry about the level problem. Let's go back to the running light and set P1.0 to a low level.

This picture is a bit complicated, let’s look at another one

In fact, they are the same. When P1.0 is set to a low level, the left side is the Vcc power supply, and when the right side is at a low level, there is a potential difference in the circuit, and current flows through.

If the opposite is true, P1.0 is set to a high level and current cannot pass through the diode.

Ok, I think you should understand!

3 Compile the program to generate a hex file

  Create a new project

 

 

Select a file name and then confirm

Choose a model

atmel AT89c51

Here I would like to explain that Keil is a foreign software and does not have the STC model (but you can add it yourself)

However, since the AT89c51 core is the same, it is also possible to use atmel AT89c51

continue

New or (crtl+n) create and then copy the code written in natePad++ into it (ctrl+c and ctrl+v)

Click Save and pay attention to the file name (please do not use Chinese characters, and the suffix .c should be a c file)

Double-click the source group and add the c file.

 

 

 

Click on the hammer

Then set the crystal frequency in traget, 11.0592Mhz (this is not used now, but set it first)

 

Be sure to select create HEx File and click OK

 

 Click rebuild to generate a hex file (this file is in the 51c file directory you created)

 Note: The hex file name is the project name

 

  

4 Open the burning software stc-isp (burner)

 

Note 1 Choose the MCU model, we are stc89c52rc

    If the model is incorrect, the program cannot be successfully burned.

  2 Select the serial port. When the driver is installed, plug in the USB and select the serial port, which is usually the one with a long name.

This is com3

  3 Open the target program

  

Click to repeat programming. Display the detection target MCU

Then press the power button in the MCU to turn off the power. Then turn on the power button (this is a cold start of the MCU~)

Display operation success means writing success

 

5. Rendering 

 

 

 As shown in the figure, the first running light LED1 lights up.


Reference address:51 MCU Learning Part 6 - 1.2 The first C51 program (lighting up the running light)

Previous article:51 MCU Learning Part 6 - 1.2 The first C51 program (lighting up the running light)
Next article:51 MCU Learning Road—— 1.1 Learning Preparation

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号