Getting Started with Keil µvision 3 and C51 1. Create a Project: Start uvision3. Go to Project->New µvision Project on the µvision3 window. Then enter the name of your project and select a location. Click Save on the Create New Project window. Then select Atmel->AT89C51RD2 on the Select Device window. And click OK. 1
Select No on the following screen as we don t need to copy the startup code. Now you have created a new project. The screen will look like the following. 2
Notice that there is nothing in the Source Group 1 folder as we haven t added any source code into the project yet. Next, we ll add a source file to the project. 2. Add a Source File Into the Project. Select File->New on the µvision3 window. Then a blank file will be opened. 3
It s a good idea to save the empty file to your project folder as.c or.a51 file before you enter/edit your program as you can get color display for different syntax for.c or.a51 files. Then type in the following program and save it. We are now ready to add this new file into our project. 4
Right Source Group 1 on the above screen and select Add Files to Group Source Group 1. Select the file you just created then click Add on the following window. 5
Now you will see the new source file tutorial.c showing in the Source Group 1 folder. Next, click Close on the Add Files to Group Source Group 1 window. Before we compile and generate hex file, we need to do the following setup: Select Flash- >Configure Flash Tool on the µvision3 window. 6
The following window will be opened. First, select the output tab, and check the Create HEX File on the upper part of the window. This will allow the µ Vision3 to generate a hex file when your build your project. The hex file will be used to program your Lab Pro-51 board. 7
Then, select Utilities tab, check Use External Tool for Flash Programming, and type in the full path of the flash programming tool, in our case, the full path of flip. For example: C:\Program Files\Atmel\Flip 3.3.1\bin\flip.exe. Then click OK. This setup will allow you to use the flash programming tool from within the µvision Window. Now we are ready to compile our source file. 8
3. Compile the program. Select Project -> Translate on the µvision3 Window: or click the following icon on the right top corner of the window to compile the program. If there is no syntax error in your program, you should see the following message in the Output Window at the bottom. 9
Then we need to generate the object file for simulation and hex file for our target, the Lab Pro-51 board. Click the icon on the left of the translate icon: from the drop window.. Or, select Project Build Target If there is no error in your program, you should see the following message displayed in the Output Window : Now we are ready to simulate our program. 4. Simulate the Program Select Debug Start/Stop Debug Session on the drop down menu, or click the upper right corner. icon on the 10
You will see a warning window popup: Just click OK. This is because we are using an evaluation version of Keil. We can only simulate a program whose machine code size is less than 2K Byte. Since most of our project should be able to fit in 2K Byte, we should be ok. Now the simulator will stop at the first instruction of your program and ready to execute your program. The yellow arrow on the program window indicates the instruction where the simulate stops. 11
Now to run the program, select Debug Run from the drop down menu, or click the the upper right corner. icon on This tutorial program reads from Port 0 then output the value to Port 1. So in order for us to observe this activity, we need to show the two ports. Select Peripherals I/O-Ports->Port 0, to open Port 0 window. Do the same thing for Port 1 to open Port 1 window. Then you will see both port windows showing on top of the program window. Move both windows to the right side of the program window so that it does not block your source code. This step is not necessary, but it gives you convenience when debugging your code. Now try to uncheck one of the box on the second row of your Port 0 and observe the change in Port 1. Port 1 copies Port 0, that s why we call it Little Copy Cat. 12
To stop debugging, simply click the icon again. 5. Download and Test Your Program on the Lab Pro-51 Board After you simulate your program and fixed all the problems we can find, we are ready to download our program to the lab board for testing. Select Flash Download from the drop down menu. This will start the flash programming tools we specified in one of our previous step, i.e., Flip. The following Flip window will be opened. 13
First, select Device->Select on the drop down menu. Select AT89C51RD2 on the following window. Then, select File load HEX File to load tutorial.hex. 14
Last, setup communication 15
Then, we are ready to program our board. Click Run on the bottom left corner. If everything goes well, we will see green button on the left of each box in Operations Flow window. 16
Now we are ready to test our program on our Lab Pro-51 board. 17