
Chapter 3. Build Your First Project
To start a new project, we should first create a project.
Click ‘Project’ – ‘New uVision Project...’.

Name the project file to ‘my.uv2’.
Now, choose the device we need to experiment with. Here, we select Atmel AT89S51, a very popular MCU.

After the MCU is chosen, Keil will ask to add startup code to the project. We click no.

Till now, our project is created.

We can write source code in the Keil uVision IDE. Our example codes are the minimum codes needed to light up a LED.
Click ‘File’ – ‘New...’

Type below codes in the popped text editor.

loop:
CLR P1.0
Ajmp loop
END
Only 4 statements are used in this example.
CLR P1.0 will set the MCU P1.0 to low level. From the schematic, we know that to light the LED up, we need to set P1.0 to low.
The first line ‘loop’ is a label. ‘Ajmp loop’ force the program to jump to the position where label loop locates.
END is the ending of the program.
A simple program is finished. Now click ‘File’ – ‘Save As...’ to save the file, and name it to ‘led.asm’. Notice that ‘.asm’ is its file extension, because codes are in assemble language. If C language is used, we should name the file with ‘.c’.
With the project ‘my’ we created, and source code file ‘led’ we wrote, now we should add the source code file into the project. Click the left ‘plus’ and right click ‘Source Group’, then click ‘Add files to Group ‘Source Group 1’. Select ‘led.asm’ and click ok to add it into our project.

Now it’s time to compile all the source files, and generate target file that will be programmed into AT89C51 later on.
To generate hex file for programming, some settings are needed before compiling. Right click ‘Target 1’ and select ‘Options for Target ‘Target 1’.

Activate the ‘Output’ sheet in ‘Options for Target ‘Target 1’, and enable ‘Create HEX file’ option. Then click OK to confirm the setting.

Now, press shortcut F7 to start compiling. ‘my.hex’ file will be generated in the directory where ‘led.asm’ is located. It’s a hexadecimal file that can be used to program a MCU.
To see if the generated hex file is what we need the MCU to do, we can emulate it in our KinCony 8051 MCU Development Platform.
Repeat the before-mentioned process, activate the ‘Target’ sheet and set ‘Xtal (MHz)’ to 11.0592 which is the emulation frequency.

Select ‘Debug’ sheet, and choose ‘Use: Keil Montor-51 Driver’.

Then click ‘Settings’ to set proper COM port number and Baudrate in the popped dialog. In this example, we use COM1 and 38400bps.

Till now, all settings for emulation have been done. Let’s click ‘Debug’ – ‘Start/Stop Debug Session’, or press the shortcut to run the debug.

Click ‘Debug’ – ‘Run’ or press the shortcut to run the program. You will see the first LED p1.0 lighted up as we hope so.

To end the emulation, press the reset key in the board, and then click ‘Debug’ – ‘Start/Stop Debug Session’ again to exit the emulation.
|