Personal practice: serial port interruption and communication

Publisher:BlissfulWhisperLatest update time:2019-09-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Writing interrupts requires a timer:

1. Set its register TMOD

2. The value of THx and TLx (this is to set the initial value of the timer)

3. Turn on the timer (TRx=1)

-----------------------------

Note: There are two registers in the serial port

SCON (Serial Port Controller) and PCON

4. SCON format: SM0 SM1 SM2 REN TB8 RB8 TI RI

(1) SM0 and SM1 are used to set the serial port working mode: 0, 1, 2, 3, a total of 4 working modes.

(2) SM2 is only used for multi-machine communication control bits in Mode 2 and Mode 3.

(3) REN serial reception enable bit. 0 - Disable reception 1 - Enable reception

(4) TB8: In methods 2 and 3, TB8 is the ninth bit of data to be sent by the transmitter.

(5) RB8: In methods 2 and 3, RB8 is the ninth bit of data received by the receiver, which comes from TB8 of the transmitter.

(6)TI: Transmit interrupt flag. It must be cleared by software before sending. During the sending process, TI remains at zero. After sending a frame of data,

Automatically set to 1 by hardware. If you want to continue sending, you must clear it by software.

(7) RI: Receive interrupt flag. Before receiving, it must be cleared by software. During the receiving process, RI remains at zero. After receiving a frame of data,

Automatically set to 1 by the on-chip hardware. If you need to continue receiving, you must clear it again by software.


Power Control Register (Power Controller)

SMOD bit of PCON: baud rate doubling bit. When calculating the baud rate of serial modes 1, 2, and 3; 0 - do not double; 1 - double.


Reference address:Personal practice: serial port interruption and communication

Previous article:How to use STM8L interrupt line and interrupt port
Next article:STM8L serial port interrupt cannot enter

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号