Author Topic: How to Program an 8051 Microcontroller Using Keil  (Read 82 times)

Offline SiVa000000

How to Program an 8051 Microcontroller Using Keil
« on: October 31, 2025, 11:19:25 PM »
English: I’m starting this post as a beginner-friendly guide and will keep updating it over time. Since I’m currently occupied with other work, some details may be added gradually.

The main goal is to help FTC Forum users understand the basics of programming the 8051 microcontroller using the Keil IDE. This is my first attempt, so please excuse any small mistakes.

I’ve chosen a low-cost 8051 microcontroller for learning purposes, but Keil is still a professional-grade tool — perfect for both students and developers.

In this thread, I’ll be sharing:

An introduction to the 8051 and Keil

Step-by-step working procedure

Code examples (starting with LED blink)

Screenshots and visuals for better understanding



Anyone trying or testing the setup can share snapshots or feedback — even a small visual reply will help guide others.

Let’s begin with the classic “Blink an LED” example as our first step!


Tamil: இந்த பதிவை நான் தொடக்க நிலை நண்பர்களுக்கும் எளிதாக புரியக்கூடிய வழிகாட்டியாக தொடங்குகிறேன். காலத்தின் போக்கில் இதை தொடர்ந்து புதுப்பித்து கொண்டு இருப்பேன்.
இப்போது வேறு சில பணிகளில் இருப்பதால், சில விவரங்கள் பின்னர் சேர்க்கப்படலாம்.

இந்த பதிவின் முக்கிய நோக்கம் — FTC Forum பயனர்களுக்கு Keil IDE-ஐப் பயன்படுத்தி 8051 மைக்ரோகண்ட்ரோலரை நிரலாக்குவது எப்படி என்று அடிப்படையாகப் புரியச் செய்வது.
இது எனது முதல் முயற்சி, சிறிய பிழைகள் இருந்தால் மன்னிக்கவும்.

நான் தேர்ந்தெடுத்திருப்பது குறைந்த செலவில் கிடைக்கும் 8051 மைக்ரோகண்ட்ரோலர், ஆனால் Keil ஒரு தொழில்முறை (professional) கருவி, மாணவர்கள் மற்றும் டெவலப்பர்கள் இருவருக்கும் சிறந்தது.

இந்த தொடரில் நான் பகிரப் போவது:

8051 மற்றும் Keil பற்றிய அறிமுகம்

படி படியாக செயல்முறை விளக்கம்

உதாரணக் கோடுகள் (முதல் உதாரணம் – LED Blink)

ஸ்கிரீன்ஷாட்கள் மற்றும் காட்சிகள் — எளிதாகப் புரிய உதவும்



யாராவது இந்த அமைப்பை முயற்சித்தால் அல்லது சோதித்தால், snapshot அல்லது visual reply ஒன்றை பகிரலாம் — சிறிய காட்சி உதவி கூட மற்றவர்களுக்கு வழிகாட்டியாக இருக்கும்.

அப்படியே ஆரம்பிப்போம் — நம் முதல் படியாக, “LED ஒன்றை மின்னச் செய்வோம்”! 💡
« Last Edit: November 01, 2025, 09:44:32 AM by SiVa000000 »

Offline SiVa000000

Re: How to Program an 8051 Microcontroller Using Keil
« Reply #1 on: November 01, 2025, 07:26:45 AM »
English:
🧩 Introduction to the 8051 and Keil

The 8051 microcontroller is one of the most popular and widely used controllers for learning embedded systems. Originally developed by Intel, it has been adapted by many manufacturers because of its simple architecture, low cost, and ease of programming.

The 8051 typically includes:

An 8-bit CPU

4 KB ROM (program memory)

128 bytes RAM

32 I/O pins

Timers, serial communication port, and interrupts


Even though it’s an older design, it’s still the best starting point for students to understand how microcontrollers work — including memory organization, port handling, and instruction cycles.


---

⚙️ What is Keil?

Keil µVision (pronounced MicroVision) is a professional IDE (Integrated Development Environment) used to write, compile, and debug embedded programs. It supports the 8051, ARM, and Cortex families of microcontrollers.

With Keil, you can:

Write programs in C or Assembly

Compile them to a .HEX file

Simulate the program using the built-in debugger

Flash it to your microcontroller hardware using any 8051 programmer


Keil provides a complete platform for both learning and professional development.


---

🔗 Official Keil C51 Download Link

You can download the Keil µVision C51 Compiler (for 8051) from the official Keil website:
👉 https://www.keil.com/download/product/

STEP 1: Go to https://www.keil.com/download/product/ –>Download –> Product Downloads –>Hit on C51 Setup. Enter your contact information with valid address, phone number and email. Fill in all fields of form. Download is free for evaluation version.


STEP 2: Then click on C51V954A.EXE and Download it on your computer.


STEP 3: Next step is to run setup file C51V954A.EXE and then we’ll get pop-up box, hit on Next and Proceed Installation.


STEP 4: Read license agreement, check I agree to all the terms…., and click Next.


STEP 5: Select Destination folder where you want to install Keil or default destination is already there. And hit on Next.


STEP 6: Fill up required fields with all relevant information and click on Next.


STEP 7: Wait for installation completes and hit on Next.


STEP 8: Tick on show release notes, deselect remaining (as per your choice) and click on Finish.




Tamil:
🧩 8051 மற்றும் Keil – அறிமுகம்

8051 மைக்ரோகண்ட்ரோலர் என்பது எம்பெடெட் சிஸ்டம் (Embedded System) கற்றுக்கொள்வதில் மிகவும் பிரபலமான மற்றும் பரவலாகப் பயன்படுத்தப்படும் கண்ட்ரோலர்களில் ஒன்று.
இது முதலில் Intel நிறுவனத்தால் உருவாக்கப்பட்டது. அதன் எளிய வடிவமைப்பு (architecture), குறைந்த செலவு, மற்றும் எளிதான நிரலாக்க (programming) திறன் காரணமாக பல உற்பத்தியாளர்கள் இதை தங்களின் வடிவில் மாற்றி பயன்படுத்தினர்.

8051 மைக்ரோகண்ட்ரோலரில் பொதுவாக அடங்குவது:

8-bit CPU

4 KB ROM (Program Memory)

128 bytes RAM

32 I/O Pins

Timers, Serial Communication Port, மற்றும் Interrupts



இது ஒரு பழைய வடிவமைப்பு என்றாலும், மாணவர்கள் மைக்ரோகண்ட்ரோலர் செயல்பாடு — நினைவக அமைப்பு (Memory Organization), போர்ட் கையாளல் (Port Handling), மற்றும் Instruction Cycle போன்ற அடிப்படைகளை புரிந்து கொள்ள சிறந்த தொடக்கமாகும்.


---

⚙️ Keil என்றால் என்ன?

Keil µVision (மைக்ரோவிஷன் என உச்சரிக்கப்படுகிறது) என்பது ஒரு தொழில்முறை IDE (Integrated Development Environment) ஆகும். இது எம்பெடெட் நிரல்கள் (Embedded Programs) எழுத, Compile செய்ய, மற்றும் Debug செய்ய பயன்படுத்தப்படுகிறது.
Keil, 8051, ARM, மற்றும் Cortex குடும்ப மைக்ரோகண்ட்ரோலர்களை ஆதரிக்கிறது.

Keil மூலம் நீங்கள் செய்யக்கூடியவை:

C அல்லது Assembly மொழியில் நிரல் எழுதலாம்

அதை .HEX கோப்பாக Compile செய்யலாம்

Built-in Debugger மூலம் நிரலை சோதிக்கலாம் (Simulation)

தயாரான நிரலை 8051 Programmer மூலம் ஹார்ட்வேரில் Flash செய்யலாம்


Keil ஒரு முழுமையான தளம் (Complete Platform) — கற்றலுக்கும், தொழில்முறை அபிவிருத்திக்கும் (Professional Development) ஏற்றது.


---

🔗 அதிகாரப்பூர்வ Keil C51 பதிவிறக்க இணைப்பு

Keil µVision C51 Compiler (8051க்காக) பதிவிறக்க, அதிகாரப்பூர்வ Keil வலைத்தளத்தைப் பார்வையிடுங்கள்:

👉 https://www.keil.com/download/product/
« Last Edit: November 01, 2025, 09:56:40 AM by SiVa000000 »

Offline SiVa000000

Re: How to Program an 8051 Microcontroller Using Keil
« Reply #2 on: November 01, 2025, 11:20:52 AM »
🚀 Step-by-Step Working Procedure: Let's Get Started!

In this section, we’ll begin with our first hands-on project — programming the MG82F6D17 (Megawin 8051 family) microcontroller using Keil µVision and Megawin ICE Programmer (TH065)
 
This will be a simple "Blink an LED" example, ideal for beginners to understand the basic setup and workflow.


🧰 Required Components and Tools

ItemDescriptionLink
MicrocontrollerMegawin MG82F6D17AL20 (8051-based, 20-pin SSOP)Buy Here
DatasheetOfficial MG82F6D17 Datasheet
ProgrammerMegawin 8051 ICE Programmer (TH065)View Product
AdapterSOIC/SSOP to DIP-20 Pin AdapterBuy Here
Soldering Iron StationYihua 948DB-II T12 PrecisionBuy Here
Soldering Flux10 ml flux for clean jointsBuy Here
Solder Wire1.00 mm, 50 gm spoolBuy Here
Male Header Pins2.54 mm Right Angle Header StripBuy Here
BreadboardMB102 (830 points, high quality)Buy Here
TweezerStraight ESD-11 Precision TweezerBuy Here
« Last Edit: November 01, 2025, 11:39:52 AM by SiVa000000 »

Offline SiVa000000

Re: How to Program an 8051 Microcontroller Using Keil
« Reply #3 on: November 01, 2025, 11:41:55 AM »
🚀 Step-by-Step Working Procedure: Assembling the DIP Adapter and MCU

Before we start programming, we need to assemble the MG82F6D17 microcontroller on a DIP-20 adapter board
Since the MG82F6D17 comes in an SSOP-20 surface-mount package, it must be soldered to an adapter to use it with a breadboard or programmer.





🪛 Step 1: Identify the Pin 1 Mark

On the MG82F6D17 IC, locate the Pin 1 marking — usually a small dot or notch on one side of the package. 
Also, note the Pin 1 position on the DIP adapter board. The correct orientation ensures that your pin mapping matches the programmer’s socket.

📘 Refer to the datasheet for pin configuration:





🔥 Step 2: Apply Flux and Align the Chip

1. Apply a thin layer of soldering flux on the SSOP pads of the adapter board. 
2. Carefully place the MG82F6D17 chip on the pads, ensuring all pins are aligned with their respective tracks. 
3. Use tweezers for accurate positioning — once aligned, tack down one corner pin with solder to keep it fixed.

Tip: Good alignment before soldering is crucial; SSOP pitch is very fine!


🧲 Step 3: Solder the Pins

1. Heat the soldering iron (around 330–350°C). 
2. Lightly tin the iron tip with solder. 
3. Gently drag-solder across the pins using minimal solder and flux — the surface tension will bridge correctly to each pad. 
4. If any pins get shorted, clean with flux and use a solder wick to remove the excess.

✅ Ensure all pins are properly soldered and no bridges exist between adjacent legs.


🔌 Step 4: Attach Male Headers

1. Insert Male headers into the DIP adapter holes. 
2. Solder them on the underside to make the module breadboard-friendly. 
3. Make sure the headers are straight for easy insertion into breadboards or programmer sockets.


⚡ Step 5: Continuity Check

Before powering the circuit: 
- Use a multimeter in continuity mode. 
- Check all 20 pins for proper solder contact and absence of short circuits. 
- Verify that VCC and GND pins are correctly connected.
« Last Edit: November 01, 2025, 12:01:15 PM by SiVa000000 »

Offline SiVa000000

Re: How to Program an 8051 Microcontroller Using Keil
« Reply #4 on: November 01, 2025, 12:05:15 PM »
⚙️ Step-by-Step Working Procedure: Connecting to the Programmer





When selecting the right microcontroller for a project, you must consider cost, performance, features, power consumption, and overall size

When we consider the price-to-performance or price-to-features ratio, most mainstream MCUs can be quite expensive — especially during the recent global silicon shortage

That’s where manufacturers like Megawin, Nuvoton, and STMicroelectronics step in to provide excellent alternatives at affordable prices.



🏗️ Megawin – MG82 Series 
Megawin’s MG82 series MCUs are cost-effective 8051-based controllers offering modern features such as enhanced flash memory, high-speed operation, and a wide range of peripherals — all while remaining compatible with classic 8051 tools and programmers.


⚡ Nuvoton – N76 / MS51 Series 
The Nuvoton N76 and MS51 series are also 8051-based and provide good performance at a reasonable price, suitable for industrial and hobby applications.


🔋 STMicroelectronics – STM8 Series 
The STM8 series from STMicroelectronics is another strong option. These MCUs are widely supported, but during the pandemic their prices increased considerably.


🏁 Final Comparison 
When comparing features, Megawin Microcontrollers clearly offer the best balance between cost and capability, making them an excellent choice for embedded developers seeking reliable and affordable 8-bit performance.

📊 Difference Between Megawin (MG82F6D17), Nuvoton (N76E003), and ST (STM8S003) Low-Cost Microcontrollers

Now, arguably — which is the best low-cost microcontroller currently available in the market? 

To find that out, we compared three popular budget-friendly MCUs: 
- MG82F6D17 from Megawin Technology 
- N76E003 from Nuvoton Technology 
- STM8S003 from STMicroelectronics 

The comparison below highlights the key features and specifications of each device, helping you decide which fits best for your next embedded project.



📋 Features Comparison Table

FeatureMegawin MG82F6D17Nuvoton N76E003ST STM8S003
Core ArchitectureEnhanced 8051Enhanced 8051STM8 (Proprietary 8-bit)
Program Memory (Flash)16 KB18 KB8 KB
RAM1 KB1.2 KB1 KB
EEPROM / Data Flash512 Bytes (Emulated)1 KB (Emulated)640 Bytes (Integrated)
Operating Voltage2.4V – 5.5V2.4V – 5.5V2.95V – 5.5V
Clock FrequencyUp to 24 MHzUp to 16 MHzUp to 16 MHz
I/O Pins181816
ADC Channels8-bit × 8 channels12-bit × 8 channels10-bit × 5 channels
Timers3 × 16-bit3 × 16-bit2 × 16-bit
UART / SPI / I²CYes / Yes / YesYes / Yes / YesYes / Yes / Yes
Package TypeSSOP-20 / DIP-20 (via adapter)TSSOP-20 / DIP-20TSSOP-20 / SOIC-20
Programming InterfaceICP / ISPICP / ISPSWIM
Typical Price (INR)₹45 – ₹55₹60 – ₹75₹70 – ₹85


🏁 Conclusion

Based on the specifications and availability, the Megawin MG82F6D17 offers excellent value with a good blend of performance, peripheral support, and compatibility with standard 8051 tools — making it a strong contender for cost-sensitive embedded designs.

« Last Edit: November 01, 2025, 12:26:18 PM by SiVa000000 »

Offline SiVa000000

Re: How to Program an 8051 Microcontroller Using Keil
« Reply #5 on: November 01, 2025, 12:15:27 PM »
To be continued..