#include#include #inclde void delay(unsigned char time) //The function must be declared, otherwise the following error will occur: void main() { P0 = 0xfe; //P must be uppercase while(1) { delay(200); P0 = _cror_(P0,1); } } void delay() { unsigned char I,j; for(i=0;i<=time;i++) { for(j=0;j<=200;j++) { _nop_(); //Null instruction, calculated according to the machine cycle of the microcontroller } } }
Another way to achieve this:
Application of sbit
Data Type Notes:
Data Types
|
Number of digits
|
Number of bytes
|
Numerical range
|
illustrate
|
bit
|
1
|
|
0 or 1
|
Position type
|
Signed char
|
8
|
1
|
-128——+127
|
Signed byte type
|
Unsigned char
|
8
|
1
|
0~255
|
Character or eight-bit unsigned integer
|
enum
|
16
|
2
|
-32768~+32767
|
Enumeration
|
Signed short
|
16
|
2
|
-32768~+32767
|
Signed short integer
|
Unsigned short
|
16
|
2
|
0~6535
|
Unsigned short integer
|
Signed int
|
16
|
2
|
-32768~32767
|
|
Unsigned int
|
|
|
|
|
Signed long
|
|
|
|
|
Unsigned long
|
|
|
|
|
float
|
|
|
|
|
Spit
|
1
|
|
0 1
|
Position type
|
Sfr
|
8
|
1
|
0~255
|
8-bit special function register
|
Sfr16
|
|
|
|
|
|
|
|
|
|
Program code:
#include#include #include sbit P0_0 = P0^0; // I/O port definition method, the difference between the two, if not defined in this way, it will be said that it is not defined sbit P0_1 = P0^1; sbit P0_2 = P0^2; sbit P0_3 = P0^3; sbit P0_4 = P0^4; sbit P0_5 = p0^5; sbit P0_6 = P0^6; sbit P0_7 = P0^7; void delay(unsigned char time); //Function declaration, important void main() { while(1) { P0_0 = 0; delay(200); P0_1 = 0; delay(200); P0_3 = 0; delay(200); P0_4 = 0; delay(200); P0_5 = 0; delay(200); P0_6 = 0; delay(200); P0_7 = 0; delay(200); } void delay(unsigned char time) { unsigned char i,j; for(i=0;i<=time;i++) { for(j=0;j<=200;j++) { _nop_() } } } Control the on and off procedure: #include // Port definition is already included in this header file, so P0 can be directly assigned #include #include void delay(unsigned char time); void delay(unsigned char time) { unsigned i,j; for(i=0;i<=time;i++) { for(j=0;j<=200;j++) { _nop_(); } } } void main() { while(1) { P0 = 0x00; delay(200); P0 = 0xff; delay(200); } }
Previous article:Small RTOS keyboard scanner
Next article:Single chip remote synchronization lamp circuit + program
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- The express delivery didn’t arrive for 6 days. I took a look and found out that the express delivery also misses home.
- [GD32L233C-START Review] - Transplanting Freertos real-time system
- [Warehouse temperature and humidity automatic control simulation system] 3. RSL10 BLE Mesh networking first experience
- DSP 2812: GPIO encapsulation using C++
- Compound op amp amplification problem
- The DC power supply output voltage is unstable. How to calibrate and test it?
- [National Technology N32G457 Review] 11 N32G45 and STM32 CAN Communication Example
- PCB drawing board suggestions for B628 lithium battery boost circuit chip
- RT Thread IPC Summary
- Analysis of 5G millimeter wave terminal technology and test solutions