Test method: You can write 95 10 20 25 in the sending box of the serial port debugging assistant, and select hexadecimal sending, and select hexadecimal display in the receiving box. If 95 10 20 25 is received every time it is sent, it means the test is successful.
//This is a microcontroller C51 serial port receiving (interrupt) and sending routine, which can be used to test the interrupt reception
//and query sending of the 51 microcontroller. In addition, I think it is not necessary to use interrupts for sending, because the program overhead is the same
#include
#include
#define INBUF_LEN 4 //data length
unsigned char inbuf1[INBUF_LEN];
unsigned char checksum,count3;
bit read_flag= 0 ;
void init_serialcomm( void )
{
SCON = 0x50 ; //SCON: serail mode 1, 8-bit UART, enable ucvr
TMOD |= 0x20 ; //TMOD: timer 1, mode 2, 8-bit reload
PCON |= 0x80 ; //SMOD=1;
TH1 = 0xF4 ; //Baud:4800 fosc=11.0592MHz
IE |= 0x90 ; //Enable Serial Interrupt
TR1 = 1 ; // timer 1 run
// TI=1;
}
//Send a character to the serial port
void send_char_com( unsigned char ch)
{
SBUF=ch;
while (TI== 0 );
TI= 0 ;
}
//Send a string to the serial port, strlen is the length of the string void
send_string_com( unsigned char *str, unsigned int strlen)
{
unsigned int k= 0 ;
do
{
send_char_com(*(str + k));
k++;
} while (k < strlen);
} //Serial port receive interrupt function void serial () interrupt 4 using 3 { if (RI) { unsigned char ch; RI = 0 ; ch=SBUF; if (ch> 127 ) { count3= 0 ; inbuf1[count3]=ch; checksum= ch- 128 ; } else { count3++; inbuf1[count3]=ch; checksum ^= ch; if ( (count3==(INBUF_LEN- 1 )) && (!checksum) ) { read_flag= 1 ; //If the serial port receives data up to INBUF_LEN and the verification is correct, //set the data read flag } } } } main() { init_serialcomm(); //Initialize the serial portwhile ( 1 ) { if (read_flag) //If the data read flag is set, send the read number from the serial port { read_flag= 0 ; //Clear the data read flag send_string_com(inbuf1,INBUF_LEN); } } }
Previous article:Temperature and humidity automatic detection system composed of AT89C51 55
Next article:Design of computer key peripheral circuit based on AT89C51RC
- 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
- [Mill Edge AI Computing Box FZ5 Review] Pynq Framework - Helloworld!
- pybNano development board added to uf2-stm32f
- Compound tube and complementary push-pull circuit
- [RTT & Renesas high performance CPK-RA6M4 development board review] - Serial and USB communication
- During the epidemic, how to use UWB technology to ensure the prevention and control of enterprises?
- My childhood fantasy has finally come true! OLED pen!
- 555 classic circuit diagram: 555 test circuit
- Last day! TI live broadcast with prizes, ACI motor actual control evaluation example, in-depth understanding of TI C2000
- Here is a Tai Chi Bagua diagram of the radio frequency industry
- [Chuanglong TL570x-EVM] Example project running