0% found this document useful (0 votes)
31 views

Chapter 13 - EUART

This document discusses the Enhanced Universal Asynchronous Receiver Transmitter (EUSART) module used in microcontrollers for serial communication. It provides an introduction to EUSART components and functions including asynchronous transmission and reception, address detection, and baud rate generation. Application examples are given for using EUSART to transfer data between a PC and microcontroller to control LEDs or display on an LCD. Main EUSART commands like #USE rs232, kbhit(), putc(), gets() and getc() are also outlined.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Chapter 13 - EUART

This document discusses the Enhanced Universal Asynchronous Receiver Transmitter (EUSART) module used in microcontrollers for serial communication. It provides an introduction to EUSART components and functions including asynchronous transmission and reception, address detection, and baud rate generation. Application examples are given for using EUSART to transfer data between a PC and microcontroller to control LEDs or display on an LCD. Main EUSART commands like #USE rs232, kbhit(), putc(), gets() and getc() are also outlined.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

HCMC University of Technology and Education

Faculty of Electrical & Electronic Engineering


No.1 Vo Van Ngan Street, Thu Duc Dist., HCMC, VN

MICROCONTROLLERS

NGUYEN THANH NGHIA


12/31/2020 11
NGUYEN THANH NGHIA
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
No.1 Vo Van Ngan Street, Thu Duc Dist., HCMC, VN

CHAPTER 13:
EUART

NGUYEN THANH NGHIA


12/31/2020 22
NGUYEN THANH NGHIA
Outline
1. Introduction.
2. EUSART main commands
3. Application.

NGUYEN THANH NGHIA 3


Chapter 13: EUART
1. Introduction
 The USART is one of the oldest serial communication
systems. The modern versions of this system are
upgraded and called somewhat differently - EUSART.

 The Enhanced Universal Synchronous


Asynchronous Receiver Transmitter (EUSART)
module is a serial I/O communication peripheral unit. It
is also known as Serial Communications Interface
(SCI).

NGUYEN THANH NGHIA 4


Chapter 13: EUART
1. Introduction
 Full-duplex asynchronous transmit and receive

 Programmable 8- or 9-bit wide characters

 Address detection in 9-bit mode

 Input buffer overrun error detection

 Half-duplex communication in synchronous mode.

NGUYEN THANH NGHIA 5


Chapter 13: EUART
1. Introduction
 The EUSART transmits and receives data using a
standard non-return-to-zero (NRZ) format. As seen in
figure below, this mode doesn’t use clock signal, while
the format of data being transferred is very simple:

NGUYEN THANH NGHIA 6


Chapter 13: EUART
1. Introduction
1.1 EUSART asynchronous transmitter

NGUYEN THANH NGHIA 7


Chapter 13: EUART
1. Introduction
1.1 EUSART asynchronous transmitter
 In order to enable data transmission via EUSART module, it is
necessary to configure it to operate as a transmitter. In other words, it is
necessary to define the state of the following bits:

 TXEN = 1 - EUSART transmitter is enabled by setting the TXEN bit


of the TXSTA register.

 SYNC = 0 - EUSART is configured to operate in asynchronous mode


by clearing the SYNC bit of the TXSTA register.

 SPEN = 1 - By setting the SPEN bit of the RCSTAregister, EUSART


is enabled and the TX/CK pin is automatically configured as an output.
If this bit is simultaneously used for some analogue function, it must be
disabled by clearing the corresponding bit of the ANSEL register.
NGUYEN THANH NGHIA 8
Chapter 13: EUART
1. Introduction
1.2 EUSART asynchronous receiver

NGUYEN THANH NGHIA 9


Chapter 13: EUART
1. Introduction
1.2 EUSART asynchronous receiver
 In order to enable data receiver via EUSART module, it is necessary
to configure it to operate as a receiver. In other words, it is necessary to
define the state of the following bits:

 CREN = 1 - EUSART receiver is enabled by setting the CREN bit of


the RCSTA register;

 SYNC = 0 - EUSART is configured to operate in asynchronous mode


by clearing the SYNC bit stored in the TXSTA register; and

 SPEN = 1 - By setting the SPEN bit of the RCSTAregister, EUSART


is enabled and the RX/DT pin is automatically configured as an input.
If this bit is simultaneously used for some analogue function, it must be
disabled by clearing the corresponding bit of the ANSEL register.
NGUYEN THANH NGHIA 10
Chapter 13: EUART
1. Introduction
1.3 Address detection

NGUYEN THANH NGHIA 11


Chapter 13: EUART
1. Introduction
1.3 Address detection
 When the ADDEN bit of the RCSTA register is set, the EUSART module is
able to receive only 9-bit data, whereas all 8-bit data will be ignored.
Although it seems like a restriction, such modes enable serial communication
between several microcontrollers. The principle of operation is simple.
Master device sends a 9-bit data representing the address of one slave
microcontroller. However, all of them must have the ADDEN bit set because
it enables address detection. All slave microcontrollers, sharing the same
transmission line, receive this data (address) and automatically check whether
it matches their own address. Software, in which address match occurs, must
disable address detection by clearing its ADDEN bit.
The master device keeps on sending 8-bit data. All data passing through the
transmission line will be received by the addressed EUSART module only.
When the last byte has been received, the slave device should set the ADDEN
bit in order to enable new address detection.
NGUYEN THANH NGHIA 12
Chapter 13: EUART
1. Introduction
1.4 EUSART baud rate generator
 The BRG timer consists of two 8-bit registers making one 16-bit
register.
 A number written to these two registers determines the baud rate

NGUYEN THANH NGHIA 13


Chapter 13: EUART
1. Introduction
1.4 EUSART baud rate generator
BITS
 The BRG timer consistsBRG / EUSART
of two 8-bit registers BAUD
makingRATE
one 16-bit
SYNC BRG1G BRGH MODE FORMULA
register.
0 0 0 8-bit / asynchronous Fosc / [64 (n + 1)]
A number written to these two registers determines the baud rate
0 0 1 8-bit / asynchronous Fosc / [16 (n + 1)]

0 1 0 16-bit / asynchronous Fosc / [16 (n + 1)]

0 1 1 16-bit / asynchronous Fosc / [4 (n + 1)]

1 0 X 8-bit / asynchronous Fosc / [4 (n + 1)]

1 1 X 16-bit / asynchronous Fosc / [4 (n + 1)]


NGUYEN THANH NGHIA 14
Chapter 13: EUART
1. Introduction
1.4 EUSART baud rate generator

NGUYEN THANH NGHIA 15


Chapter 13: EUART
1. Introduction
1.5 Communication with PC schematic

NGUYEN THANH NGHIA 16


Chapter 13: EUART
1. Introduction
1.5 Communication with PC schematic
 EUSART 2
MCU schematic

NGUYEN THANH NGHIA 17


Chapter 13: EUART
2. EUSART main commands
• #USE rs232(baud=a,xmit=b,rcv=c)
• Configure EUSART

• a: baud rate
• b: transmit pin
• c: receive pin
• Ex:
• #USE rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

NGUYEN THANH NGHIA 18


Chapter 13: EUART
2. EUSART main commands
• value = kbhit()
• This function returns TRUE if a character has been
received and is waiting in the hardware buffer for
getc() to read.

• putc (data)
• This function sends a character over the RS232
XMIT pin. A #USE RS232 must appear before this
call to determine the baud rate and pin used.

NGUYEN THANH NGHIA 19


Chapter 13: EUART
2. EUSART main commands
• puts (string)
• Sends each character in the string out the RS232 pin
using putc()

• value = getc()
• This function waits for a character to come in over
the RS232 RCV pin and returns the character. If you
do not want to hang forever waiting for an incoming
character use kbhit() to test for a character available.

NGUYEN THANH NGHIA 20


Chapter 13: EUART
3. APPLICATION
3.1 Transfer data between PIC and PC for control led
 Create a program to transfer data between computer
and PIC16F887. The PC sent data to PIC. The PIC will
receive data and sent to PortD connected with 8 LEDs.
The baud rate is 9600.

NGUYEN THANH NGHIA 21


Chapter 13: EUART
3. APPLICATION
3.1 Transfer data between PIC and PC for control led
 Schematic:

NGUYEN THANH NGHIA 22


Chapter 13: EUART
3. APPLICATION
3.1 Transfer data between PIC and PC for control led
 Flowchart:

NGUYEN THANH NGHIA 23


Chapter 13: EUART
3. APPLICATION
3.1 Transfer data between PIC and PC for control led
 Code: #INCLUDE <TV_16F887.C>
#USE rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
UNSIGNED INT8 RDATA=0;
VOID MAIN()
{
SET_TRIS_D(0x00); OUTPUT_D(RDATA);
WHILE(TRUE)
{
IF(KBHIT())
{
RDATA = GETCH();
OUTPUT_D(RDATA);
}
}
}

NGUYEN THANH NGHIA 24


Chapter 13: EUART
3. APPLICATION
3.2 Transfer data between PIC and PC display on LCD
 Create a program to transfer data between computer
and PIC16F887. The PC sent data to PIC. The PIC will
receive data and display on LCD. The baud rate is 9600.

NGUYEN THANH NGHIA 25


Chapter 13: EUART
3. APPLICATION
3.2 Transfer data between PIC and PC display on LCD
 Schematic:

NGUYEN THANH NGHIA 26


Chapter 13: EUART
3. APPLICATION
3.2 Transfer data between PIC and PC display on LCD
 Flowchart:

NGUYEN THANH NGHIA 27


Chapter 13: EUART
3. APPLICATION
3.2 Transfer data between PIC and PC display on LCD
 Code: #INCLUDE <TV_16F887.C>
#INCLUDE <TV_LCD.C>
#USE rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
UNSIGNED INT8 RDATA=0,I;
const unsigned char HANG1[16]={"Transfer data PC"};
VOID MAIN()
{
SET_TRIS_E(0x00); SET_TRIS_D(0x00);
LCD_SETUP();
LCD_COMMAND(ADDR_LINE1); DELAY_US(10);
FOR (I=0;I<16;I++) { LCD_DATA(HANG1[I]);}
LCD_COMMAND(ADDR_LINE2); DELAY_US(10);
WHILE(TRUE)
{
IF(KBHIT())
{
RDATA = GETCH(); LCD_DATA(RDATA);
}
}
}

NGUYEN THANH NGHIA 28


Chapter 13: EUART
3. APPLICATION
3.3 Transfer data between PIC and PC display on LCD
 Create a program to Control MCU1 read temperature
from LM35 then send the read value to MCU2 to display
on it on LCD. The baud rate is 9600.

NGUYEN THANH NGHIA 29


Chapter 13: EUART
3. APPLICATION
3.3 Transfer data between PIC and PC display on LCD
 Schematic:

NGUYEN THANH NGHIA 30


Chapter 13: EUART
3. APPLICATION
3.3 Transfer data between PIC and PC display on LCD
 Code for MCU1: #USE rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
#INCLUDE <TV_16F887.C> #INCLUDE <TV_LCD.C>

UNSIGNED INT16 KQADC,J;


VOID MAIN()
{
SET_TRIS_B(0x00); SET_TRIS_D(0x00);
SET_TRIS_C(0x00); SET_TRIS_A(0xFF);
SETUP_ADC(ADC_CLOCK_DIV_8);
SETUP_ADC_PORTS(sAN0|Vss_Vdd);
SET_ADC_CHANNEL(0);
WHILE(TRUE)
{
KQADC=0;
FOR (J=0; J<200; J++)
{
KQADC=KQADC+READ_ADC();
DELAY_MS(1);
}
KQADC= KQADC /2.046;
KQADC=KQADC/200;
putc(KQADC); delay_ms(50);
}
}

NGUYEN THANH NGHIA 31


Chapter 13: EUART
3. APPLICATION
3.3 Transfer data between PIC and PC display on LCD
 Code for MCU2:
#INCLUDE <TV_16F887.C> DELAY_US(10);
#INCLUDE <TV_LCD.C> FOR (I=0;I<16;I++) {
#USE LCD_DATA(HANG1[I]);}
rs232(baud=9600,xmit=pin_c6,rcv=pin_c7) enable_interrupts(global);
UNSIGNED INT16 nd,i; enable_interrupts(int_rda);
const unsigned char WHILE(TRUE)
HANG1[16]={"Transfer MCU 1-2"}; {
#int_rda LCD_COMMAND(0xC7);
void interrupt_UART() LCD_DATA(nd/10+0x30);
{ LCD_DATA(nd%10+0x30);
nd=getch(); delay_ms(500);
} }
VOID MAIN() }
{
SET_TRIS_C(0x80);SET_TRIS_E(0x00);
SET_TRIS_A(0x00); LCD_SETUP();
LCD_COMMAND(ADDR_LINE1);

NGUYEN THANH NGHIA 32


Chapter 13: EUART

The end!

NGUYEN THANH NGHIA 33

You might also like