Learning Embedded Development of 51 Microcontroller with Proteus 8 Simulation Tool at Zero Hardware Cost

What is Proteus 8?

Proteus 8 is an electronic design automation (EDA) software developed by Lab Center Electronics, widely used in the field of electronic engineering. It integrates functions such as circuit simulation, PCB design, and virtual model simulation, providing a one-stop solution for electronic design, particularly suitable for simulation experiments of the 51 microcontroller, effectively reducing development costs and shortening development cycles.

In terms of circuit simulation, Proteus 8 supports the simulation of analog circuits, digital circuits, and mixed-signal circuits. For example, if you want to design a simple minimum system for the 51 microcontroller, you can build the circuit in Proteus 8, simulate its operation under different conditions, and observe the voltage, current, and signal waveforms at various nodes in the circuit using virtual instruments such as oscilloscopes and logic analyzers, allowing you to identify and resolve issues in the circuit design in a timely manner. It acts like a virtual electronics laboratory, enabling you to validate and debug your design without the need to physically build the hardware circuit.

Regarding PCB design functionality, Proteus 8 provides a complete design flow from schematic to PCB layout. Once you complete the design and simulation of the circuit schematic, you can directly convert it into a PCB design. The software comes with a rich component library that includes various common electronic components, allowing you to easily perform component layout and wiring operations. Additionally, it supports automatic routing functionality, improving design efficiency.

Virtual model simulation is a major feature of Proteus 8. It supports the simulation of various microcontrollers, including the familiar 51 microcontroller. When developing a project with the 51 microcontroller, you can create a virtual model in Proteus 8 that includes the 51 microcontroller and its peripheral circuits, then download the written program to the virtual microcontroller for execution and debugging. This way, you can perform functional validation and optimization of the entire system without actual hardware, which is especially friendly for beginners, allowing them to more intuitively understand and master the working principles and application development of microcontrollers during their learning process.

Why choose Proteus 8 for 51 microcontroller simulation?

1. Rich Component Library

Proteus 8 has a rich component library, where you can find almost all the components needed for 51 microcontroller experiments. For example, commonly used 51 microcontroller chips like AT89C51 and STC89C52, as well as various sensors such as the DS18B20 temperature sensor, which can be used to measure ambient temperature and transmit the temperature data to the 51 microcontroller for processing; and light-sensitive resistors that can sense changes in light intensity, commonly used in smart lighting projects.

Moreover, basic components such as resistors, capacitors, and inductors are also fully available. Resistors of different values can meet various circuit needs such as voltage division and current limiting; capacitors of different capacitances can be used for filtering and coupling functions. For a simple minimum system of the 51 microcontroller, in addition to the microcontroller chip itself, you also need a crystal oscillator to provide clock signals, two capacitors to work with the crystal oscillator, and a reset circuit. All these components, including the crystal oscillator, capacitors, resistors, and buttons, can be quickly found and used in the Proteus 8 component library, greatly facilitating circuit construction and allowing you to focus on circuit design and functionality implementation without worrying about finding component models.

2. Powerful Simulation Functionality

The simulation functionality of Proteus 8 is very powerful, capable of simulating the operating states of various circuits. For example, in a 51 microcontroller-controlled LED chaser experiment, after building a circuit in Proteus 8 that includes the 51 microcontroller, several LEDs, and related resistors, you can download the control program to the virtual 51 microcontroller for simulation. At this point, you can clearly see the LEDs lighting up and turning off in the order set by the program, just like running on actual hardware.

Furthermore, Proteus 8 also provides various virtual instruments, such as oscilloscopes and logic analyzers, to analyze the working conditions of the circuit in depth. For instance, in a serial communication experiment with the 51 microcontroller, using an oscilloscope allows you to observe the waveforms of the signals sent and received through the serial port, and by analyzing parameters such as frequency, amplitude, and phase of the waveforms, you can determine whether the communication is normal and whether there are any signal interferences. The logic analyzer can monitor the logical states of multiple signals simultaneously, which is very helpful for analyzing the logical relationships of complex digital circuits, allowing you to intuitively understand the data transmission and interaction processes between the 51 microcontroller and other devices, thus better analyzing and optimizing circuit designs and promptly identifying potential issues in the circuit.

3. Convenient User Interface

The user interface of Proteus 8 is simple and intuitive, making it easy to get started. The software adopts a drag-and-drop operation method; you only need to find the required components in the component library and drag them into the workspace with the mouse, then complete the circuit construction through simple wiring operations. For beginners who are new to 51 microcontroller simulation, this simple and understandable operation method lowers the learning threshold.

In the workspace, the layout of various tools and options is also very reasonable, making it convenient for users to call them at any time. For example, when drawing circuit diagrams, you can easily draw wires and add nodes using the drawing tools on the toolbar; for setting component properties, you only need to double-click the component to modify it in the pop-up property dialog, such as setting the resistance value of a resistor or the capacitance value of a capacitor. Moreover, Proteus 8 also provides rich view functions, allowing you to zoom in or out of the circuit diagram as needed for clearer detail viewing; you can also switch between different display modes, such as schematic mode and PCB mode, facilitating operations and viewing at different design stages.

4. Compatibility with Other Tools

Proteus 8 is compatible with commonly used microcontroller programming software, such as Keil programming tools. In the development process of the 51 microcontroller, Keil is a widely used programming software for writing and compiling programs for the 51 microcontroller. Proteus 8 focuses on circuit design and simulation. The combination of these two software achieves seamless integration of code writing and circuit simulation.

When you complete the program code writing and compilation in Keil, the generated hex file can be directly imported into the 51 microcontroller model in Proteus 8 for simulation. During the simulation process, if you find any issues with the program, you can switch back to Keil at any time to modify and debug the code, then re-import the modified hex file into Proteus 8 for verification, repeating this process until both the program and circuit work correctly.

Application Examples of Proteus 8 in 51 Microcontroller Simulation

1. LED Chaser Experiment

Open the Proteus 8 software and create a new project. Find the AT89C51 microcontroller in the component library and drag it into the workspace. Next, add 8 LEDs and 8 resistors, connecting the anodes of the LEDs through resistors to the +5V power supply, and the cathodes to the 8 pins of the microcontroller’s P1 port (P1.0 – P1.7). This completes the hardware circuit construction.

Next, write the control program. Use Keil software to write the following C language code:

#include <reg51.h>
#include <intrins.h>
void delay(unsigned int time) {
    unsigned int i, j;
    for (i = 0; i < time; i++)
        for (j = 0; j < 1275; j++);
}
void main() {
    while (1) {
        P1 = 0xfe; // 1111 1110, light up the first LED
        delay(500);
        P1 = 0xfd; // 1111 1101, light up the second LED
        delay(500);
        P1 = 0xfb; // 1111 1011, light up the third LED
        delay(500);
        // Continue to light up each LED in order
        P1 = 0x7f; // 0111 1111, light up the eighth LED
        delay(500);
    }
}

In this code, the delay function is used to implement the delay, and by adjusting the time parameter, you can change the duration for which the LED lights up. In the main function, different binary values are written to the P1 port in a loop to control the LEDs to light up sequentially.

After completing the code, compile it in Keil to generate the hex file. Return to Proteus 8, double-click the AT89C51 microcontroller, and in the pop-up property dialog, load the generated hex file into the microcontroller. Click the simulation run button, and you will see the LEDs light up and turn off in the order set by the program, creating the effect of a running light.

2. Temperature Acquisition System Simulation

This case combines the 51 microcontroller with the DS18B20 temperature sensor to simulate a temperature acquisition system and display the collected temperature values on a digital tube.

First, build the hardware circuit. In Proteus 8, add the AT89C51 microcontroller, DS18B20 temperature sensor, common cathode digital tube, and some resistors, capacitors, and other components from the component library. Connect the DQ pin of the DS18B20 to the P3.2 pin of the microcontroller for data transmission. The segment selection pins of the digital tube are connected to the P0 port of the microcontroller, and the digit selection pins are connected to the P2 port, with current-limiting resistors in between.

Use Keil tools to write the program. The program mainly includes functions for initializing the DS18B20, reading temperature, processing data, and displaying on the digital tube. Here is a sample code:

#include <reg51.h>
#include <intrins.h>
sbit DQ = P3^2; // Define the data pin of DS18B20
unsigned char code segCode[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; // Segment codes for the digital tube
unsigned char code digitCode[] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F}; // Digit codes for the digital tube
void delay(unsigned int time) {
    unsigned int i, j;
    for (i = 0; i < time; i++)
        for (j = 0; j < 1275; j++);
}
bit initDS18B20() {
    bit presence;
    DQ = 1;
    _nop_();
    DQ = 0;
    delay(750); // Pull low for 480-960us
    DQ = 1;
    delay(15); // Pull high and wait for 15-60us
    presence = DQ;
    delay(250); // Wait for 60-240us
    return presence;
}
unsigned char readByte() {
    unsigned char i, dat = 0;
    for (i = 0; i < 8; i++) {
        DQ = 0;
        dat >>= 1;
        DQ = 1;
        if (DQ) {
            dat |= 0x80;
        }
        delay(4);
    }
    return dat;
}
void writeByte(unsigned char dat) {
    unsigned char i;
    for (i = 0; i < 8; i++) {
        DQ = 0;
        DQ = dat & 0x01;
        delay(5);
        DQ = 1;
        dat >>= 1;
    }
}
unsigned int getTemperature() {
    unsigned char lowByte, highByte;
    initDS18B20();
    writeByte(0xCC); // Skip ROM command
    writeByte(0x44); // Start temperature conversion
    delay(100); // Wait for conversion to complete
    initDS18B20();
    writeByte(0xCC);
    writeByte(0xBE); // Read temperature register
    lowByte = readByte();
    highByte = readByte();
    return (highByte << 8) | lowByte;
}
void displayTemperature(unsigned int temp) {
    unsigned char digit1, digit2, digit3, digit4;
    digit1 = temp / 1000;
    digit2 = (temp % 1000) / 100;
    digit3 = (temp % 100) / 10;
    digit4 = temp % 10;
    P2 = digitCode[0];
    P0 = segCode[digit1];
    delay(500);
    P2 = digitCode[1];
    P0 = segCode[digit2];
    delay(500);
    P2 = digitCode[2];
    P0 = segCode[digit3];
    delay(500);
    P2 = digitCode[3];
    P0 = segCode[digit4];
    delay(500);
}
void main() {
    unsigned int temperature;
    while (1) {
        temperature = getTemperature();
        displayTemperature(temperature);
    }
}

In this code, the initDS18B20 function is used to initialize the DS18B20; the readByte and writeByte functions are used to read and write a byte of data, respectively; the getTemperature function is responsible for starting the temperature conversion and reading the converted temperature value; the displayTemperature function decomposes the temperature value into individual digits and displays it on the digital tube.

Compile the written program in Keil to generate the hex file, then load it into the microcontroller in Proteus 8 for simulation. After running the simulation, you can see the current temperature value displayed in real-time on the digital tube.

Learning Embedded Development of 51 Microcontroller with Proteus 8 Simulation Tool at Zero Hardware Cost

Leave a Comment