µV
MPMC Lab · Experiment 5 · 8051 · Keil + Nuvoton

Introduction to the 8051 Programming Environment

Keil µVision project set-up, building a HEX file, and programming a Nuvoton W78E052D with the ISP utility.

☰ All experiments

Aim

To install and practise using the Keil µVision IDE and the Nuvoton ISP utility for developing, building and executing 8051 programs.

Learning objectives

1
Project set-up
Create a µVision project, select the correct device and add source files.
2
Target options
Set the crystal frequency and enable HEX file generation.
3
Build
Read the Build Output: errors, warnings, program size and HEX creation.
4
Simulation
Use the debugger: run, step, breakpoints, registers and ports.
5
Programming
Program the W78E052D APROM through the Nuvoton ISP tool and verify it.
6
Edit–build–flash
Change a program and see the change on the board.

What this experiment demonstrates

  • The full embedded tool chain: source → object → absolute → Intel HEX → flash.
  • How the same program behaves in the simulator and on the board.
  • Why device selection, crystal and output settings matter.

Sub-tasks

  • 5.1 A LED blink (assembly)
  • 5.1 B LED blink (Embedded C)

Tool chain

Editmain.a51 / main.cA51 / C51→ .OBJBL51 linker→ absoluteOH51→ .HEXNuvoton ISP toolUSB-UART → APROM Board runs from 0000H µVision's built-in simulator (Debug ▸ Start Session) lets you test before programming the chip.
Fig 1. Keil µVision tool chain from source code to a programmed W78E052D.

The 8051 / W78E052D

W78E052D8051 · 40-pin DIP P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78RST9P3.0 RXD10P3.1 TXD11P3.2 INT012P3.3 INT113P3.4 T014P3.5 T115P3.6 WR16P3.7 RD17XTAL218XTAL119GND20VCC40P0.0 AD039P0.138P0.237P0.336P0.435P0.534P0.633P0.732EA/VPP31ALE30PSEN29P2.7 A1528P2.627P2.526P2.425P2.324P2.223P2.122P2.0 A821 P0: open-drain (needs pull-ups)P1, P2, P3: quasi-bidirectionalwith internal weak pull-upsEA → VCC: run internal flashCrystal 11.0592 MHz + 2×33 pF
Fig 2. 8051 (W78E052D) pin-out.

The W78E052D is a Nuvoton 8051-compatible MCU: 8 KB flash (APROM), 256 bytes RAM, 4 × 8-bit ports, 3 timers and a UART. Its LDROM boot code can reprogram the APROM over the serial port (ISP). That is what the Nuvoton utility uses.

Machine cycle

Classic 8051: 1 machine cycle = 12 oscillator periods T = 12 / 11.0592 MHz = 1.085 µs 1-cycle instructions (MOV A,R0) : 1.085 µs 2-cycle instructions (SJMP, DJNZ): 2.17 µs Delay = (number of machine cycles) × T

11.0592 MHz is chosen because it divides exactly to standard baud rates (9600, 19200).

Intel HEX format

:10 0000 00 75 90 FF 11 0C 75 90 00 11 0C 80 F4 7B 02 7A C8 9C │ │ │ └── data bytes ─────────────────────────────┘ └ checksum │ │ └ record type (00 = data, 01 = end of file) │ └ load address └ byte count Checksum = two's complement of (count + address bytes + type + data)

Keil options to check

WhereSettingWhy
DeviceNuvoton ▸ W78E052DCorrect SFRs, memory size, simulator
TargetXtal 11.0592 MHzSimulator timing and the stopwatch
Output☑ Create HEX FileThe ISP tool needs the .hex file
STARTUP.A51No for asm, Yes for CC start-up code

Apparatus & environment

ItemSpecificationQty
PC with Keil µVisionC51/A51 tool chain (evaluation version is fine)1
8051 trainer boardNuvoton W78E052D, 11.0592 MHz crystal1
Nuvoton ISP-ICP utilityAPROM programming over USB-UART (CH340)—
USB cableUSB-A to the board's serial/ISP port1
Power supply+5 V regulated (board adapter)1

Safety rules & good practice

  • ⚡ Switch the board off before connecting or removing modules, ribbon cables or jumpers.
  • 🔌 Check the supply: +5 V only. Reverse polarity or more than 6 V destroys the controller.
  • 🧲 Handle ICs by the edges and touch a grounded surface first (ESD).
  • 🔁 Do not drive a port pin connected to a switch with 0 while the switch is pressed to VCC. Read inputs only after writing 1s.
  • 🔥 If a component gets hot or smells, switch off immediately and inform the instructor.

Procedure (hardware / real tools)

  1. Install Keil µVision (C51) and the Nuvoton ISP-ICP utility. Install the CH340 USB-serial driver.
  2. Project ▸ New µVision Project. Choose a folder without spaces and name it EXP5.
  3. Select the device Nuvoton ▸ W78E052D. Answer No to "Copy STARTUP.A51" for an assembly project.
  4. File ▸ New, type the LED program, save it as main.a51, and add it to Source Group 1.
  5. Options for Target: Xtal = 11.0592 MHz. On the Output tab tick Create HEX File.
  6. Build (F7). Check "0 Error(s)" and "creating hex file".
  7. Debug ▸ Start/Stop Debug Session. Open Peripherals ▸ I/O Ports ▸ Port 1, then run and step through the program.
  8. Open the Nuvoton ISP tool, select the COM port, press Connect and reset the board.
  9. Load the .hex into APROM, tick Erase, press Start and wait for "Program OK / Verify OK".
  10. Reset the board, observe the LEDs, then change the delay, rebuild and re-program.
Click a step to tick it off. Your progress is saved in this browser.

Doing it in this virtual lab

  1. Follow the Guided workflow at the top of the Simulator tab. Each step is a mock Keil/Nuvoton dialog that gives hints when you choose wrongly.
  2. At the Build step use the µVision window below the workflow.
  3. After programming, the board runs your code. Edit the delay or pattern, rebuild, and program again.
  4. Switch to the C version (5.1 B) and compare the code size and timing.

Pre-Lab Test 6 questions · diagnostic

Check your prerequisite knowledge. Each answer gets instant feedback. Score at least 4/6 before using the simulator.

Observation table

Rows are added by ● Record in the simulator: inputs, the expected (theoretical) value and the simulator result. Type your own hand calculation in "Your value" to check it. Add rows by hand for hardware-bench readings. The table is saved in this browser.

#Sub-taskInputsExpectedSimulatorYour valueCheckNote

Edge cases to test

  1. Untick "Create HEX File" and build: what is missing in Build Output?
  2. Choose N76E003 or AT89S52 in the device dialog and read the hint.
  3. Delete SJMP MAIN in 5.1 A: what happens after the second DELAY?
  4. Switch the core to 1T: how much faster does the LED blink?
  5. Change the crystal to 12 MHz: compare the period.
  6. Load the .lst file instead of the .hex in the ISP tool.

Analysis & conclusion

Saved automatically in this browser.

Post-Lab Test 9 questions · instant hints

A wrong answer shows a hint so you can try again. Only first attempts count towards the score.

9. Numerical: machine-cycle time of a 12T 8051 at 11.0592 MHz, in µs (3 decimals)?

Self-evaluation

Tick what you can now do confidently.

Overall confidence:

Feedback summary

Finish the post-lab test to see your personalised summary.