C51 Interrupt Receive Query Send
#include
volatile unsigned char rx_data;
volatile bit rx_flag = 0;
void dalay_1ms(unsigned short n)
{
unsigned short i,j;
for(i=0; i
{
for(j=60000; j>0; j--);
}
}
void send_char(unsigned char ch)
{
SBUF = ch;
while(!IF);
IF = 0;
}
void send_string(unsigned char *str, unsigned char len)
{
unsigned char i;
for(i=0; i
{
send_char(*(str+i));
}
}
//----------------------------------------------
void main (void)
{
// volatile unsigned char i,tmp;
unsigned char *str = "Serial test";
TMOD = 0x20; //T1 mode 2
TH1 = 0xFD; //Baud:9600bps@11.0592MHz
TL1 = 0xFD;
TR1 = 1; //Start timer 1
SCON = 0x50; //Serial port mode 1, 8-n-1, receiving is allowed
REN = 1; //Enable serial port reception
EA = 1; // Enable general interrupt
ES = 1; //Turn on the serial port interrupt switch
send_string((unsigned char *)str, 11);
while(1)
{
delay_1ms(1);
if(rx_flag)
{
ES = 0; //The serial port interrupt must be turned off first, otherwise the PC will not receive data
SBUF = rx_data;
while(RI == 0);
ES = 1; //Re-enable serial port interrupt
RI = 0;
}
}
}
//----------------------------------------------
void serial(void) interrupt 4
{
rx_data = SBUF;
P1 = rx_data;
rx_flag = 1;
RI = 0;
}
//----------------------------------------------
Previous article:C51 queue mode interrupt receive query send
Next article:The essence of commonly used electronic password lock source program
- 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 application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- DSP C6000 interrupt program analysis
- Which one is better, 3-axis, 6-axis or 9-axis?
- Zhengdian Atom Elite STM32F103ZET6 Development Board Kit
- Fresh and hot evaluation information is here~~
- LSM6DSOX machine learning core official Chinese information
- Please recommend a chip that can realize a 0.01hz function signal generator
- Does using a high switching frequency converter affect efficiency at higher loads?
- The use of three brackets in C language in keil: (); []; {}
- Share CCS7.3 installation steps
- MSP430 MCU Development Record (4)