#include <STC12C5A60S2.H>
#include "intrins.h"
#define FOSC 11059200L
#define BAUD 9600
#define S2RI 0x01; //Serial port 2 receiving bit
#define S2TI 0x02; //Serial port 2 sends bit
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
i = 22;
j = 3;
k = 227;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void InitUart()
{
SCON=0x50;
TMOD=0x20;
TH1=TL1=-(FOSC/12/32/BAUD);
TR1=1;
IF=1;
}
void InitUart2()
{
S2CON=0x50;
AUXR|=0x14;
BRT=-(FOSC/32/BAUD);
S2CON|=S2TI;
}
void SendData2(unsigned char dat)
{
bit busy=S2CON&S2TI;
while(!busy)
{
busy=S2CON&S2TI;
}
S2CON&=~S2TI;
S2BUF=that;
}
void SendData(unsigned char dat)
{
while(!IF);
IF = 0;
SBUF=dat;
}
void main()
{
unsigned char ch = 0;
InitUart();
InitUart2();
while(1)
{
SendData(ch);
SendData2(ch);
ch++;
if(ch==8) ch=0;
Delay500ms();
Delay500ms();
}
}
If you need timer 1 to work in 12T mode, you need to make the following changes:
void InitUart()
{
SCON=0x50;
AUXR|=0x40;
TMOD=0x20;
TH1=TL1=-(DARK/32/BAUD);
TR1=1;
IF=1;
}
At this time, modify the macro definition of BAUD to 115200 to achieve a baud rate of 115200.
If the baud rates of the two serial ports are the same, you can directly modify it as follows and save a timer.
void InitUart()
{
SCON=0x50;
AUXR|=0x41;
IF=1;
}
Previous article:STC12C5A60S2 reads the ADC value and sends it to the serial port
Next article:STC12C5A60S2 uses NRF24L01 and stm32 to communicate
- 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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- 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
- TI's Several Important Notes on Ethernet
- Chip packaging methods
- Can NiMH rechargeable batteries be soldered with a 60W constant temperature soldering iron?
- Download the latest resource: Ultra-Wideband (UWB) For Dummies
- Fully differential op amp common mode output voltage THS4500
- Xiaomi phones are going to use liquid lenses? What kind of black technology is liquid lens? Are you looking forward to it?
- A strange MIC (microphone) signal amplifier circuit, I thought about it for a long time but still couldn't understand it
- My Journey of MCU Development (Part 7)
- [TI recommended course] #Common errors and solutions in DC/DC converter design#
- Pyboard timer terminal callback function problem