Hammad Khan Lab11
Hammad Khan Lab11
With PIC18F452
Submitted To:
Engr. Mariam Sabir
Lab Engineer
____________
EXPERIMENT NO 11
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
Equipment:
Hardware:
SSD(Common Anode)
Keypad(4x3)
LCD display(16x2)
PIC18F452
Software:
1. MikroC for PIC
2. Smart-pro 5000u
Discussion:
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
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:
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
LAB TASKS
Task#01
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.
Program Code
void main()
{
char abc;
UART1_Init(9600); //Initialize UART module at 9600 bps
Delay_ms(100);
while(1)
{
Delay_ms(1000);
UART1_Write_Text(" Serial Communication ");
}
Proteus Circuit
Output
Task#02
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.
Program Code
void main() {
char var[255];
UART1_Init(9600);
Delay_ms(100);
while(1){
while(UART1_Data_Ready() == 0);
UART1_Read_text(var,".",9600);
UART1_write_text(var);
}
}
Proteus Circuit
Output
Task#03
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.
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
}
}
Proteus Circuit
Output
Learning Outcomes:
In this lab, we learnt about serial communication using PIC 18F452 in MikroC. Serial
communication is Synchronous communication which means the information is transmitted from
the transmitter to the receiver.
We used virtual terminal as a hyper terminal in proteus simulation to verify our code and to
simulate in on proteus. We performed several tasks such as to send data to virtual terminal as a
string. After that we performed a task in which we can keep sending data to terminal until a
certain character (in our case “.”) is pressed in which we were able to understand how serial
communication works.