1. The difference between the keywords sfr and sbit
sfr is the byte address of the register, and sbit is the bit address of the bit-addressable register.
For example: sfr P1 = 0x90;
sbit A = P1^0 sbit B = P1^1;
2. The microcontroller pins are: power pin, crystal pin, reset pin, download pin, GPIO pin
The crystal pin is mainly used to provide an external clock to drive instruction execution. The GPIO pins include four ports: P0, P1, P2, and P3.
3. Light up an LED
From the circuit diagram, we can know that the LED is the P2 port. If we give the P2.0 pin a low voltage, that is, 0V, the first one will light up. The procedure is as follows
#include"reg52.h" //reference header file
int main()
{
P2 = 0xFE; //1111 1110 represents the output voltage status of P2.0----P2.7 pins
while(1)
{
}
return 0;
}
If I output low voltage to all pins of port P2, P2=0x00, then all LEDs will light up, as shown below
4. LED light flashes
The LED light is controlled to flash by outputting high and low levels, but due to the afterglow effect of the human eye, the flashing cannot be seen, so a delay is needed to achieve the effect. The program is as follows
#include"reg52.h" //reference header file
void Delay(int time)
{
while(time--) //while loop takes 10us
{
}
}
int main()
{
while(1)
{
P2 = 0xFF;
Delay(50000); //Delay about 450ms
P2 = 0xFE;
Delay(50000); //Delay about 450ms
}
return 0;
}
The experimental phenomena are as follows
Previous article:51 single chip microcomputer: LED light water lamp
Next article:51 MCU assembly language: using RET instruction to implement multi-way branching
- 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
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Another question about the matrix keyboard
- Transmit power measurement method
- My Journey of MCU Development (VI)
- [RVB2601 Creative Application Development] 4 Long press and short press to eliminate the letter A
- CC2520 BasicRF Study Notes
- Improve your basic knowledge of embedded systems
- 【FAQ】Microchip Live: Simplifying security application design with dsPIC33/PIC24 and ATECC608 devices
- Application Examples of Portable Spectrum Analyzers for Radio Signal Monitoring
- High Accuracy Split-Phase CT Fuel Gauge Reference Design Using Independent ADCs
- [Xianji HPM6750 Review] HPM SDK Development Environment Construction and Hello World