Use Keil and Proteus to light up the LED light. (Without a development board, you can only rely on simulation software. After you have a single-chip microcomputer board, you can do a physical demonstration.)
Function 1: Protues drawing
Function 2: Keil generates .hex file
Enter the text:
1. Proteus part:
We first need to draw our diagram in Proteus. How to draw? The steps are as follows:
1) First, we need to create a new project. If you don't know how to create a project using Proteus, please go to: Create MCU projects using Proteus and Keil
2) Find the required components in Proteus:
Special note: In the third step here, in this example, you only need to search for: AT89C51, CAP, CAP-ELEC, CRYSTAL, LED-BIBY, RES, SWITCH (other components are not used in this example)
3) Start drawing (just like this picture, the parameters of some devices can be based on this picture):
Special note: When drawing here, the VDD and ground symbols are:
4) The Proteus drawing is completed, now enter the Keil part.
2. Keil part:
We first need to create a new Keil project. How to create it? The steps are as follows:
1) If you don't know how to create a project using Keil5, please go to:
Proteus and Keil create microcontroller projects respectively
2) After creating our project, we start writing code:
/*****************************Experimental routine**********************
Function: To realize convenient control of room lighting, one lighting lamp is controlled by a (closed) switch at the door and the bedside.
The closing of the switch does not directly determine whether the light is on or off, but the change of the switch state is the key to determining whether the light is on or off.
No matter what the current state is, as long as one of the switch states changes, the light will switch between the two states of on or off.
In this experiment, the first LED connected to the P0 port is used to simulate a lighting lamp, and S2 and S3 (P1.0 and P1.1) are used to simulate two switches.
Crystal oscillator: 11.0592MHZ Test whether the switch has changed, main function: control the light when a change is detected, and then record the current state
**********************************************************************/
#include sbit light=P0^0; //Note the representation method of a certain bit, a certain bit of the special function register is represented by Sbit sbit s1=P1^0; sbit s2=P1^2; bit change,s1sta,s2sta; //s1sta,s2sta are the states of switches s1 and s2 at the previous moment, which are used to compare with the current states of s1 and s2. //Then determine whether the status of the two switches has changed. bit keyscan() { if((s1^s1sta)||(s2^s2sta)) //^ is XOR, if the two are different, the result is 1. That is, if the state of any of the two switches changes, this condition is true. change=1; return change; } void main() { s1sta=s1; s2sta=s2; while(1) { keyscan(); //Scan whether the key status has changed, that is, whether someone has changed the key status. if(change) { change=0; //clear light=~light; //Once the switch status is changed, the state of the light will be reversed. s1sta=s1; //At the same time, send the current status of s1 and s2 to s1sta and s2sta to prepare for subsequent comparisons. s2sta=s2; } } } 3) After the code is completed, we need to compile and generate the required .hex file (this file needs to be burned into Proteus) first step: Step 2: third step: Special note: I use Keil5, and the default generated .hex file is saved in: 4) At this point, the required .hex file is generated, and we re-enter Proteus: 5) At this point, the .hex file has been burned into Proteus. Click the lower left corner of Proteus to start the simulation: 6) Click the corresponding button in the figure to observe the effect: Finished, sprinkle flowers... This is just a simple Keil+Proteus effect experiment, continue to update more experimental projects...
Previous article:[MCU] Keil+Proteus running light (modular programming)
Next article:[MCU] Proteus and Keil create MCU projects respectively
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Google discontinues Android Things, its IoT operating system
- Reverse voltage protection for battery chargers
- ASUS laptop, the second hard drive is gone? !
- BMS Software Engineer Recruitment
- Low power mode of msp430f149
- GaN Reference Designs
- How to get started with embedded development?
- [Perf-V Review] Transplanting the Hummingbird E203 open source SOC to the FPGA board
- Design USB3.1 high-speed SD Card reader based on Genesys GL3224
- If you want to make the three-pole tube work in the amplification area, what is the idea? You need to calculate the static working point ib ic VCE three...