The PC controls the LED of the microcontroller on and off or controls the flashing and flashing time of the LED through the upper software. The username and password of the upper software are both admin. Note that PROTEUS serial port simulation needs to be combined with virtual serial port software to work.
Software description of host computer (including source code):
Send data analysis
Byte 1, 2: 0x55 0xaa Data is correct or not judgment flag
Byte 3:
0x01 ------ Single LED control manual control
0x02 ------ Single LED control automatic flashing
Byte 4
This byte controls LED0-LED7 from low to high, for example, 0x01 means manually light up LED0 or LED0 flashes automatically; 0x28 means manually light up LED3, LED5 or LED3, LED5 flashes automatically
Byte 5, 6: Indicates flashing time (6 high 8 bits 5 low 8 bits) Value range 0-5000
Program source code preview:
#include #define uint8 unsigned char #define uint16 unsigned int uint8 receive_buffer[6]; //Store received data uint8 i,k; void delay1ms(uint16 m) //1ms delay program { uint8 j; while(m--) for(j=0;j<112;j++); } void main() { uint16 time; P0 = 0xff; //Initialize LED status, turn off TMOD = 0x20; //Timer 1 works in mode 2 TH1 = 0xfd; TL1 = 0xfd; //Baud rate 9600 TR1 = 1; //Start timer 1 EA = 1; // Enable general interrupt SM0 = 0; SM1 = 1; //Serial port working mode 1 REN = 1; //Enable serial reception ES = 1; // Enable serial port interrupt while(1) { if((receive_buffer[0] == 0x55) && (receive_buffer[1] == 0xaa)) //If 0x55 0xaa is received, it means the received data is correct { time = ((uint16)receive_buffer[5] << 8) + (uint16)receive_buffer[4]; // flashing time switch(receive_buffer[2]) { case 0x01: //manually control the LED on and off P0 = ~receive_buffer[3]; break; case 0x02: //LED flashes automatically P0 = ~receive_buffer[3]; delay1ms(time); P0 = 0xff; delay1ms(time); break; default: break; } } } } void uart_int() interrupt 4 { if(RI == 1) { RI = 0; receive_buffer[i] = SBUF; i++; if(i == 6) { i = 0; k = 0; P0 = 0xff; } } }
Previous article:DS18B20.h LCD1602.h header file download temperature and LCD debugging ok can be called directly
Next article:Keil_uvision4 detailed tutorial (with pictures and explanations)
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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
- EEWORLD University - Isolated Gate Driver Challenges and Solutions
- EEWORLD University Hall----Live playback: The latest low-power 5GHz dual-band Wi-Fi MCU fully meets high security standards
- FPGA Simple Design Method for Efficient Design
- Center-tapped transformer and two coils in series
- TI Signal Chain and Power Q&A Series Live Broadcast - LED Driver Special Prize Live Broadcast is in progress!
- Experience TouchGFX with rewards and start your creative GUI journey
- EVAL-M3-TS6-665PN board review
- Remove the vicor module power supply
- IoT Gateways - A Simple Guide to IoT
- Help with MS41908M lens driver chip driver