0% found this document useful (0 votes)
50 views6 pages

Lab 11

This document describes objectives and procedures for a lab on serial communication between a PIC microcontroller and a PC. The lab introduces asynchronous serial communication using a PIC18F452 microcontroller, RS-232 transceiver, and MAX232 level converter. Students write code to transmit and receive single characters and strings via UART until specific delimiters. The document provides code examples and instructions to test the code in Proteus and on hardware using a RS-232 serial port and HyperTerminal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views6 pages

Lab 11

This document describes objectives and procedures for a lab on serial communication between a PIC microcontroller and a PC. The lab introduces asynchronous serial communication using a PIC18F452 microcontroller, RS-232 transceiver, and MAX232 level converter. Students write code to transmit and receive single characters and strings via UART until specific delimiters. The document provides code examples and instructions to test the code in Proteus and on hardware using a RS-232 serial port and HyperTerminal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab 11

Serial Communication

Objectives:
➢ Getting introduced to serial port of microcontroller
➢ Serially interfacing microcontroller with PC

Hardware:
➢ PIC18F452
➢ RS-232
➢ Max 232
➢ PC with serial port

Introduction:

Synchronous communication:
When using the synchronous communication – the information is transmitted from the
transmitter to the receiver:
• In sequence
• Bit after Bit
• With fixed baud rate
• And the clock frequency is transmitted along with the bits
That means that the transmitter and the receiver are synchronized between them by the
same clock frequency.
Asynchronous communication:
When using the asynchronous communication - the transmitter and the receiver refraining
to transmit long sequences of bits because there is not a full synchronization between the
transmitter and receiver. In this case, the information is divided into frames, in the size of
byte. Each one of the frame has:
“Start” bit marks the beginning of a new frame.
“Stop” bit marks the end of the frame.
Frames of information must not necessarily be transmitted at equal time space, since
they are independent of the clock.
To communicate with external components such as computers or microcontrollers, the
PIC microcontroller uses a component called USART (Universal Synchronous
Asynchronous Receiver Transmitter0). This component can be configured as:
• A Full-Duplex asynchronous system that can communicate with peripheral
devices, such as CRT terminals and personal computers
• A Half-Duplex synchronous system that can communicate with peripheral
devices, such as A/D or D/A integrated circuits, serial EEPROMs, etc.

MAX232 – Level Converter IC:


The serial port of computer sends/receives data serially at logic levels between -12 to
and +12V whereas, microcontroller works at logic levels between 0 to 5V (TTL). A
MAX232 is used for this purpose. It provides 2-channel RS232C port and requires
external 10uF capacitors. The driver requires a single supply of +5V.
While using software mikroC a library of “UART” is included to use USART
comfortably.

LIBRARY of UART:

Function Syntax Description


UARTx_Init UART1_Init(baud rate); Configures and initializes
the UART module
UARTx_Data_Ready UART1_Data_Ready(); This function is used to test if
data in receive buffer is ready
for reading. Return 1 if data is
ready for reading return 0 if
there is no data in the receive
register.
UARTx_Tx_Idle UART1_Tx_Idle(); This function is used to test if
the transmit shift register is
empty or not. Return 1 if the
data has been transmitted 0
otherwise.
UARTx_Read UART1_Read(); Returns the received byte.
UARTx_Read_Text UART1_Read_Text(output,"b Reads characters received
ye",255); via UART until the delimiter
sequence is detected
UARTx_Write UART1_Write('a'); The function transmits a byte
via the UART module
UARTx_Write_Text UART1_Write_Text(“Hello”); Sends text via UART.
Text should be limited to 255
characters and zero
terminated.
Procedure:
Open MikroC and make a new project then write this code.

Task # 1:
Write a code to transmit a string “Serial Communication” serially. Perform it in Proteus
using virtual Terminal and on Hardware via RS232 and Max232 using HyperTerminal.
Code:
void main()
{
UART1_Init(9600); //Initialize UART module at 9600 bps
Delay_ms(100); //Wait for UART module to stabilize
while(1) //Infinite loop
{
UART1_Write_Text("Serial Communication");
Delay_ms(1000);
}
}

Schemtic:
Task # 2:

Write a code to Receive a data (byte) serially and then transmit back to display it
on Hyper Terminal screen. Perform it in Proteus using virtual Terminal and on Hardware
via RS232 and Max232 using HyperTerminal.

Code:
void main()
{
char data1;
UART1_Init(9600); //Initialize UART module at 9600 BPS
Delay_ms(100); //Wait for UART module to stabilize
while(1)
{
while(UART1_Data_Ready()==0); //If data is ready then
data1= UART1_Read(); //Receive the data(byte) and store it in data1
UART1_Write(data1); //Transmit the received data(byte) data1
}
}

Schemtic:

Press the character you want to transmit and then pic microcontroller receive this and
then send it back. Heper Terminal / Virtual Terminal will display this character on
Screen after receiving.
Lab Task # 3:

Write a code to Receive a string serially until “.” is found and then transmit back to display
it on Hyper Terminal screen. Perform it in Proteus using virtual Terminal and on Hardware
via RS232 and Max232 using Hyper Terminal.

Code:
void main()
{
char output[255];
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1)
{
while(UART1_Data_Ready()==0); //Check to see if data is ready or not
{
UART1_Read_Text(output,".",255); // Reads text until '.' is found
UART1_Write_Text(output); //Transmit the text back which is received before "."
}
}
}

Lab Task # 4:

Write a code to Receive a string serially until “.” is found and then count the number of
characters in the input entered and then transmit it back to display it on Hyper Terminal
screen. Perform it in Proteus using virtual Terminal.

You might also like