/*
Keywords:C51
Reference address:C51: Transmitting data via serial port interruption
1. Serial port mode, baud rate setting:
1.1 T1 working mode 2, automatic reload 8-bit counting mode, as baud rate generator, baud rate calculation:
1.1 Baud rate calculation:
Baud rate = 2^SMOD * T1 overflow rate / 32
T1 overflow rate = f/(12*(256-TH1))
Result: Baud rate = 2^SMOD * f/32 * 1/[12*(256-TH1)]
For example: f=11.0592, SMOD=0, baud rate=9600, then: TH1=0xfd.
1.2 T1 working mode 2 (timer T1 interrupt disabled) setting:
TMOD=0x20;
TR1=1;
1.3 Serial port mode 1, allow receiving settings
SCON = 0x50;
If you use printf() to send data from the serial port, you must set TI=1.
2. Serial port interrupt setting
2.1 Open the general interrupt, EA=1;
2.2 Enable serial port interrupt, ES=1;
*/
/*
Programming features:
1. The serial port uses interrupt mode: after receiving a character, it sends the character immediately.
*/
#include "reg52.h"
#define uchar unsigned char
uchar mybuf;
//Declare the serial port initialization function
void init();
//
void main()
{
init();
//Open interrupt
EA=1;
ES=1;
while(1);
}
//Serial port interrupt response function
void serial() interrupt 4
{
//Disable interrupt
ES=0;
//Serial port receives characters
if(RI==1)
{
RI=0;
mybuf=SBUF;
SBUF=mybuf;
while(TI==0);
TI=0;
}
//Open interrupt
ES=1;
}
//Serial port initialization
void init()
{
//T1 mode 2 as baud rate,
TMOD=0x20;
//Serial port mode 1, allow receiving settings
SCON=0x50;
//f=11.0592,baud=9600,calculate constant
TH1=0xfd;
TL1=0xfd;
//start up
TR1=1;
}
Previous article:c51: Sending strings with a 16-bit keyboard
Next article:c51: pulse period measurement
Recommended ReadingLatest update time:2024-11-16 15:43
C51 single chip microcomputer uses 74hc138 to expand the simulation circuit diagram + program of the water lamp
The C51 microcontroller uses 74hc138 to expand the water lamp program, which includes source code. The simulation circuit can be expanded to multiple LED circuits at will. The schematic diagram is as follows: The microcontroller source program is as follows: #define uint unsigned int #define uchar unsigned char vo
[Microcontroller]
static, const, code keywords in C51 development
static Keyword Static can be used to modify variables in C, and can also be used to modify functions. static modifier variable Variables can exist in three places in C: the global data area, the stack, and the heap. The stack and the heap are different. int a ; int main() { int b ; int c* = (int *)malloc(sizeo
[Microcontroller]
Understanding of C51 external interrupts and program calls
First, let's introduce the basic concept of C51 external interrupt Advantages of interrupts: 1. Real-time processing. The CPU is required to respond or process immediately. 2. Exception handling: If power outages, program errors, and other problems occur during operation, the CPU needs to handle the source of the faul
[Microcontroller]
C51---4.1 Static digital tube display
Digital tube pin definition Schematic 74HC138 Through the 74HC138 decoder P2_2 P2_3 P2_4 control LED1-LED8 output 0 is selected For example P2_2=1//low position P2_3=0 P2_4=1//High 101 is 5 in decimal, so the 5th bit is valid and the low level is effective. The digital tube is connected with a common cathode
[Microcontroller]
Detailed explanation of Keil C51 software usage
Section 1 Keil C51 Compiler Control Instructions The control instructions of the C51 compiler are divided into three categories: source file control, target file control and list control. 1. Source file control NOEXTEND: C51 source files are not allowed to use ANSI C extension functions. DEFINE (DF): define prepro
[Microcontroller]
Single chip infrared TV remote control C51 program code
//************************************************ ****************
//Name: Single-chip infrared TV remote control C51 program code()
/*--------------------------------------------------------------
Description:
The output of general infrared TV remote control is generated by pulse amplitude modulation of 38-40kHz
[Microcontroller]
KEIL C51 printf formatted output special usage
/******************************************* KEIL has expanded the b, h, and l to set the input byte width: (1) b is 8 bits (2) h is 16 bits (default) (3) l is 32 bits In Keil C51, when using printf to output a single-byte variable, you need to use %bd, such as unsigned char counter; printf("Current count: %bd\n", cou
[Microcontroller]
C51 MCU C language function editing
In fact, main(), which always appears in the examples, is also a function, but it is special. It is used as the beginning of the program when compiling. With functions, C language has the advantage of modularization. Generally, for programs with more functions, each individual function will be divided into several sub
[Microcontroller]
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Thank you for being my confidant
- Suspicious signal from outer space
- Download gift: USB Type C related development and test materials, read it when you have nothing to do, and you will become a master by accident
- Qorvo explains WIFI and 5G clearly
- SPIN3201 (STSPIN32F0) three-resistance control board: FOC motor drive schematic/code/debugging documents and other detailed information...
- Should segment display screens be backlit? How to add it?
- Installation and setup of CCS StarterWare, successfully compiling a project with CCS7.3
- EEWORLD University ---- Operational Amplifier Video Tutorial
- Have you ever encountered the problem of USB drive repair? Is there any good tool you can recommend?
- Several major wireless technologies