/* Name: MCU and PC communication
Description: The microcontroller can receive the PC
Send digital characters, press the microcontroller
After pressing K1, the microcontroller can send
String. Completed in Proteus environment
For this experiment, you need to install Virtual
Serial Port Driver and Serial Port Debug Assistant
This example buffers 100 numeric characters.
When the buffer is full, new numbers are stored from the front (ring buffer).
*/
#include
#define uchar unsigned char
#define uint unsigned int
uchar Receive_Buffer[101]; //Receive buffer
uchar Buf_Index=0;
//Digital tube encoding
// Buffer space index
uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
//Delay
void DelayMS(uint ms)
{
uchar i;
while(ms--) for(i=0;i<120;i++);
}
//Main program
void main()
{
uchar i;
P0=0x00;
Receive_Buffer[0]=-1;
SCON=0x50; Serial port mode 1, allowing reception
TMOD=0x20; //T1 working mode 2
TH1=0xfd; //Baud rate 9600
TL1=0xfd;
PCON=0x00; baud rate is not doubled
EA=1;EX0=1;IT0=1;
ES=1;IP=0x01;
TR1=1;
while(1)
{
for(i=0;i<100;i++)
{ //Receive -1 to end the display
if(Receive_Buffer[i]==-1) break;
P0=DSY_CODE[Receive_Buffer[i]];
DelayMS(200);
}
DelayMS(200);
}
}[page]
//Serial port receive interrupt function
void Serial_INT() interrupt 4
{
uchar c;
if(RI==0) return; //Disable serial port interrupt
ES=0; // Clear the receive interrupt flag
RI=0;
c=SBUF;
if(c>=\'0\'&&c<=\'9\')
{ // Cache each newly received character and put -1 after it as the end mark
Receive_Buffer[Buf_Index]=c-\'0\';
Receive_Buffer[Buf_Index+1]=-1;
Buf_Index=(Buf_Index+1)%100;
}
ES=1;
}
void EX_INT0() interrupt 0 //External interrupt 0
{
uchar *s="This is the string sent by 8051!rn";
uchar i=0;
while(s[i]!=\'\')
{
SBUF=s[i];
while(TI==0);
TI=0;
i++;
}
}
Previous article:Research on intelligent car tracking module based on MSP430 single chip microcomputer
Next article:MCU C language programming: MCU sends a string to the host
Recommended ReadingLatest update time:2024-11-16 21:54
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- Questions about the nonlinear capacitance of MOSFET tubes
- 【RT-Thread software package application works】+ unpacking and development environment establishment
- [STM32WB55 Review] 7# Use and configuration of ADC on STM32WB development board
- Why are we not allowed to take photos without core technology?
- Espressif ESP32-C3-DevKitM-1 review is coming soon. Let’s learn about this board first.
- After deleting a wire that was previously laid, AD09 got stuck.
- Canaan wants to record a video about K510. What kind of content do you hope to see? (Attached is the official information about K510)
- Share some difficult problems with the LM25116EN chip
- [RVB2601 Creative Application Development] Dynamically loading MBRE Postscript
- Distance of ESD tip discharge needle