8051 UART
Serial communication Registers
SBUF: Serial Buffer Register
SCON: Serial Control Register
Bit 7:6 - SM0:SM1: Serial Mode Specifier
SM1 |
SM0 |
|
0 |
0 |
1/12 of Osc frequency shift register mode fixed baud rate |
0 |
1 |
8-bit UART with timer 1 determined baud rate |
1 |
0 |
9-bit UART with 1/32 of Osc fixed baud rate |
1 |
1 |
9-bit UART with timer 1 determined baud rate |
/*
* 8051_Serial_UART
*/
#include <reg51.h> /* Include x51 header file */
void UART_Init()
{
TMOD = 0x20; /* Timer 1, 8-bit auto reload mode */
TH1 = 0xFD; /* Load value for 9600 baud rate */
SCON = 0x50; /* Mode 1, reception enable */
TR1 = 1; /* Start timer 1 */
}
void Transmit_data(char tx_data)
{
SBUF = tx_data; /* Load char in SBUF register */
while (TI==0); /* Wait until stop bit transmit */
TI = 0; /* Clear TI flag */
}
void String(char *str)
{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
Transmit_data(str[i]); /* Call transmit data function */
}
}
void main()
{
UART_Init(); /* UART initialize function */
String("test"); /* Transmit 'test' */
while(1);
}
'공학속으로 > 마이컴' 카테고리의 다른 글
8051 모든 인터럽트 (0) | 2020.03.04 |
---|---|
외부 인터럽트 (0) | 2020.03.04 |
8051/4051 Timers (0) | 2020.03.04 |
8051/4051 UART Interrupt (0) | 2020.03.03 |
8051 LED Blinking Program (0) | 2020.03.03 |
댓글