Daddy's amateur MCU Study: UART Serial Communication Study Notes (2)

Source: Internet
Author: User

/*************************************
* Serial Communication Experiment
* Oscillator 11.0592 MHz
* Baud rate 9600bps
* Interrupt mode implementation: the microcontroller receives computer data and sends it back to the computer after adding 1
*
**************************************/

# Include <reg52.h>

Unsigned char dat;

*******************/
Void uart_config (unsigned long Baud, CY) // baud rate, Cy Crystal Oscillator
{
Tmod = 0x20; // The timer 1 working mode. The default value is.
Th1 = 256-(CY/(12*32 * baud ));
TL1 = 256-(CY/(12*32 * baud ));
Tr1 = 1;
Sm0 = 0; // The sm0 and SM1 values determine the serial port working mode.
SM1 = 1;
Ren = 1; // allows receiving data
Ea = 1; // total disconnection
Es = 1; // enable serial port interruption
}

*****************/

Int main ()
{
Uart_config (9600,11059200 );
While (1)
{
}
Return 0;
}

Void interrupt_uart () interrupt 4
{
If (RI) // Detection If Ri = 1, the data is received,
{
Ri = 0; // set the software to 0
Dat = sbuf; // read the received data to dat;
Dat ++; // Add 1 to the data
Sbuf = dat; // data is automatically sent to sbuf.
Ren = 0; // prohibited from receiving (prohibited from receiving data when sending data)
}
If (Ti) // Detection If Ti = 1, the data is sent completely.
{
Ti = 0; // Ti 0
Ren = 1; // enable accept
}
}

Daddy's amateur MCU Study: UART Serial Communication Study Notes (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.