/**************************************************
Method 1: Delay method
Hardware: 11.0592MHz crystal, STC89C52, RXD P1.0 TXD P1.1
Baud rate: 9600
Description: T1 is used for timing, mode 1, timing time 50ms, interrupt mode, timing time is up, TF1=1, use the simulated serial port to send character 0x69
**************************************************/
#include "reg52.h"
#define uchar unsigned char
sbit P1_0 = 0x90;
sbit P1_1 = 0x91;
sbit P1_2 = 0x92;
#define RXD P1_0
#define TXD P1_1
#define WRDYN 44 //Write delay
#define RDDYN 43 //Read delay
void Delay2cp(unsigned char i);
//Write a byte to the serial port
void WByte(uchar input)
{
uchar i=8;
TXD=(bit)0; //Send start bit
Delay2cp(39);
//Send 8 bits of data
while(i--)
{
TXD=(bit)(input&0x01); //Transmit low bit first
Delay2cp(36);
input=input>>1;
}
//Send check digit (none)
TXD=(bit)1; //Send end bit
Delay2cp(46);
}
//Read a byte from the serial port
uchar RByte(void)
{
uchar Output=0;
uchar i=8;
uchar temp=RDDYN;
//Send 8 bits of data
Delay2cp(RDDYN*1.5); //Note here, wait until the start bit
while(i--)
{
Output >>=1;
if(RXD) Output |=0x80; //Receive low bit first
Delay2cp(35); //(96-26)/2, the loop takes up 26 instruction cycles in total
}
while(--temp) //Search for the end position within the specified time.
{
Delay2cp(1);
if(RXD)break; //exit after receiving the end bit
}
return Output;
}
//Delay program*
void Delay2cp(unsigned char i)
{
while(--i); //Exactly two instruction cycles.
}
void main()
{
TMOD=0x10; //T1 mode 1
TH1=0x9E; //50ms initial value
TL1=0x58; //50ms initial value
TR1=1; //Enable timer T1
ET1=1; //Open timer T1 interrupt
EA=1; //Open the general interrupt
while(1){;}
}
void timer1(void) interrupt 3
{
TH1=0x9E; //Reset the timing initial value
TL1=0x58;
WByte(0x69); //Send character
TF1=0; //Software clears interrupt flag
}
Previous article:Use of 51 MCU timer T1 2-query method
Next article:51 MCU IO port simulation serial communication 6
- Popular Resources
- Popular amplifiers
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
- 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
- Digital Signal Processing (DSP) Library for MSP430 Microcontrollers
- LM5117 WEBENCH 13.6V-17.6V to 5.00V@3A Design Solution
- CCS6.0 creates a DSPc2000 series project operation steps
- Live FAQ: Renesas RA MCU family members are growing rapidly, helping to build safe and stable industrial control systems
- Bluetooth protocol analysis (5)_Technical analysis related to BLE broadcast communication
- [Voice and vision module based on ESP32S3] Software development progress - using openmvIDE, I can finally transfer pictures, the speed is...
- Check out the exclusive disassembly document! How do TWS earphones achieve hands-free and voice wake-up control?
- Shenmu Android Face Recognition SDK Compilation Instructions
- C6678 multi-core DSP development - several key issues of hello world
- For example, #35: #error directive "Not supported." What is the reason? Please give me some advice.