Wednesday, September 28, 2011

First exercise using Keil uVision 4 for 8051 micro-controller

It's easy to create a 8051 project using Keil 8051 Development Tools, uVision 4. You can also debug the program using the build-in simulator.

- New a uVision Project in uVision 4 IDE.
New a uVision Project

- Select project location and file name.
Select project location and file name

- Select 8051 (all Variants) under Generic in Data base, and click OK.
Select 8051 (all Variants)

- Accept Copy Standard 8051 Startup Code to Project Folder and Add File to Project. The IDE will copy STARTUP.A51 file for you.
Copy Standard 8051 Startup Code to Project Folder and Add File to Project

- Right click th project "Target1" and select Options for Target 'Target1'...
Select Options for Target

- Select Small Memory Model and Small Code Rom Size, and click OK.
Config memory model

- Click File -> New... to creat your main.c

- Type in the program, and save it as main.c.
#include <reg51.h>

void DummyDelay();

void main(void){
char c = 0x00;
while(1){
P1 = c++;
DummyDelay();
}

}

void DummyDelay(){
unsigned char i, j;

for(i = 0; i < 0xFF; i++){
for(j = 0; j < 0xFF; j++){
}
}
}

Edit the code

- Right click Source Group 1 under Target1 in Project, and Add Files to Group 'Source Group 1'...
Add Files to Source Group

- Browse to select the main.c just created.
Add main.c

- Click Project to Build Target.
Build Target

- After finished without Errors. Click Debug and Start/Stop Debug Session.
Start Debug Session

- Click Peripherals -> I/O - Ports -> Port 1 to open the Parallel Port 1 monitor window.
Open Port 1 Monitor
Port 1 Monitor

- Finally click on the Run icon, or F5, to run the program in simulated mode. You can see the Port 1 Bits in Parallel Port 1 monitor change while the program running.
Running in Simulator

- Click Debug and Start/Stop Debug Session, or Ctrl-F5 to exit and back to edit mode.

No comments:

Post a Comment