STC89C52RC serial port baud rate program

Publisher:SparkCrafterLatest update time:2023-06-09 Source: elecfansKeywords:STC89C52RC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. The complete code is as follows: C
#include#define uchar unsigned char

#define uint unsigned int

void send(uchar state)

{

SBUF=state;

while(TI==0);

TI=0;

}

void SCON_init(void)

{

TMOD=0x20;//6T mode, 11.05992@115200

SCON=0x50;

PCON=0x80;

TL1=0xFF;

TH1=0xFF;

TR1=1;

/*SCON=0x50;//Timer 2 mode, 11.0592@115200

TH2=0xFF;

TL2=0xFD;

RCAP2H=0xFF;

RCAP2L=0xFD;

TCLK=1;

RCLK=1;

C_T2=0;

EXEN2=0;

TR2=1;*/

}

void main()

{

SCON_init();

while(1)

{

send('A');

}

}


2. Remarks

The "SCON_init" subroutine is a subroutine for serial port baud rate setting and initialization. It can be called once at the beginning of the main program. In the entire serial port baud rate initialization subroutine, the complete codes of our two methods are in it. The code that is not marked with comment symbols is the code for 6T mode, and the code that is marked with comment symbols is implemented through timer 2 in 12T mode. code.


The setting of 6T or 12T mode is selected by yourself when programming the program, and no code setting is required. Timer 2 is only available in enhanced 51 microcontrollers such as STC89C52RC.


Keywords:STC89C52RC Reference address:STC89C52RC serial port baud rate program

Previous article:Design of eight-way voltmeter using AT89C52 microcontroller
Next article:How to use STC89C52 microcontroller to make a multiple signal generator

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号