0% found this document useful (0 votes)
263 views8 pages

EE366 - Lab Report #4

This document describes a lab experiment on interfacing a PIC microcontroller with an LCD display. The objectives are to understand LCD interfacing and the MikroC programming language. The experiment involves two exercises: 1) Rotating LEDs on a board with variable delay controlled by a potentiometer and button. 2) Displaying and rotating text on a LCD module using a PIC microcontroller programmed in MikroC. The results show the code worked in simulation but not on the physical board for exercise 1. Exercise 2 successfully displayed and rotated text on the LCD as programmed. In conclusion, LCDs have many applications and this lab helped learn LCD interfacing.

Uploaded by

Noura MD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
263 views8 pages

EE366 - Lab Report #4

This document describes a lab experiment on interfacing a PIC microcontroller with an LCD display. The objectives are to understand LCD interfacing and the MikroC programming language. The experiment involves two exercises: 1) Rotating LEDs on a board with variable delay controlled by a potentiometer and button. 2) Displaying and rotating text on a LCD module using a PIC microcontroller programmed in MikroC. The results show the code worked in simulation but not on the physical board for exercise 1. Exercise 2 successfully displayed and rotated text on the LCD as programmed. In conclusion, LCDs have many applications and this lab helped learn LCD interfacing.

Uploaded by

Noura MD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

King Abdulaziz University

Faculty of Engineering
Electrical-Computer Engineering Department

EE366 | Microprocessors and Microcontrollers


Lab Experiment #4
PIC Microcontrollers LCD Interfacing

Section
EAG

Lab Time
Wednesday, 14:00–15:50

Submission Date

Thursday, March 12th, 2020

Team Members

Haneen Alsaedi 1606278

Lana Joharji 1607588

Noura Aldakhil 1614549

Instructors
Dr. Rania Elmanfalouty
Eng. Haneen Almaghrabi
Table of Contents

Introduction................................................................................................................................3
Objectives...................................................................................................................................3
Experiment.................................................................................................................................3
Schematic Diagram................................................................................................................3
Source Code...........................................................................................................................4
Results........................................................................................................................................5
Conclusion..................................................................................................................................6
References..................................................................................................................................6

2
Introduction

An LCD, Liquid Crystal Display, is a displaying device which is commonly used for
microcontroller-based applications. It is the easiest way to observe the output of any given
program quickly. The dimensions of the LCD used in this lab is 16 columns by 2 rows
viewing 32 ASCII characters. In this lab, LCD interfacing with a PIC18 microcontroller is the
tested application. MikroC is utilized to write the interfacing code which will then be
observed and tested. In addition, virtual simulation using Proteus software will take place for
some of the exercises. This lab aims to investigate the performance of a new component
(LCD) while restating the basic structure of a MikroC based code on a PIC18
microcontroller.

Objectives

 To gain an understanding of LCD interfacing


 To gain an understanding of MikroC, its function and libraries as applied to the PIC18
family

Experiment

3
Schematic Diagram
In this section, the circuit schematics constructed on Proteus for exercise 2 is provided, as
shown in Figure 1. As for exercise 1, there are no schematics since the team was instructed to
install the .hex file directly onto the Dwengo board without simulation. Furthermore, the run
simulation of Figure 1 is discussed in detail in the “Results” section. The circuit
specifications were as follows:

 MCU: PIC18F4550
 LCD: LM016L
 Power: 5V

EXERCISE 2

Figure 1: Exercise 2 Schematic Diagram

4
Source Code
Provided in this section is the source code of all both exercises conducted using
mikroC software.

EXERCISE 1 
unsigned int ADC_res;

void main() {
int DIREC = 0; // Variable to keep track of rotation direction
ADCON1 = 0x0E; // Initialize all ports as digital except AN0
TRISD = 0; // Initialize PortD as output
TRISB.B0 = 1; // Initialize RA0/AN0 as input

LATD = 0x04; // Turn on LEDs

while(1) {
ADC_res = ADC_Read(0); // Get ADC result from AN0
Vdelay_ms(ADC_res); // Variable delay based on ADC result
while (PORTB.B0 == 1) {
if(DIREC == 0)
PORTD = PORTD << 1 // Rotate left
else
PORTD = PORTD >> 1 // Rotate right
}
DIREC = ~DIREC; // Toggle direction
}
}

5
EXERCISE 2
// LCD module connections
sbit LCD_RS at RE0_bit;
sbit LCD_EN at RE2_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISE0_bit;
sbit LCD_EN_Direction at TRISE2_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

// Text to be displayed on LCD


char txt1[] = " EE 366";
char txt2[] = "MICROCONTROLER";

void main() {
int i;
ADCON1 = 0x0F; // Digital I/O
TRISE = 0x00; // PORTE is Output
TRISD = 0x00; // PORTD is Output
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt1); // Write text at center in first line
Lcd_Out(2,1,txt2); // Write text in second line
while(1){
// Iterate through LCD display locations
for(i=0;i<16;i++){
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,i,txt1); // Write text in first line
Lcd_Out(2,i,txt2); // Write text in second line
Delay_ms(40); // Delay
}
}
}

6
Results
EXERCISE 1. Building on the previous exercises in LAB-3 which showed how to rotate
turning on the LED’s with a variable time delay and how to make a software switch
debounce, this exercise adds the direction of rotation. The potentiometer will control the
speed of rotation while the button is used to reverse the direction of rotation. The program
needs to keep track of rotation direction and new code needs to be added to rotate in the
other direction.

Regarding exercise 1, the code found in the “Source Code” section built successfully on
mikroC without any syntax or runtime errors. However, the team faces issues when
attempting to install it on the Dwengo board; it did not achieve the desired outcome, which
was the rotation of LED’s with variable time delay.

EXERCISE 2. In this exercise, we will use a 16x2 character LCD on Dwengo Board to
display and rotate the following text right:
EE 366
MICROCONTROLLER

During this exercise, a 16x2 LCD is used to display the characters EE366 Microcontroller.
First, the LCD module connections were specified. Then, two arrays of type char containing
the text were initialized. In the main function, the input and output ports were configured as
digital and ports E and D were configured as output. Next, the LCD functions Lcd_Init() ,
Lcd_Cmd(), and Lcd_Out() were used to display the texts. After that, a rotation to the right
was achieved by adding a for loop to the code Which results in the text appearing to rotate on
the LCD. Figures 2 and 3 below show the results.

Figure 2: LCD Simulation of Exercise 2

7
Figure 3: Rotation of Text on LCD

Conclusion

In conclusion, this lab contained two exercises the first one was to rotate the LED’s with
variable time delay controlled by the potentiometer. The second exercise was about
displaying a specific text on the LCD in the Proteus and rotate that text using for loop.
Finally, there are a lot of some useful applications for LCD in general include robotics,
cameras, phones, high resolution colour displays(tv).

You might also like