CSEP567 PreLab 4: “LCD Functions”

Task

Create two functions to control an LCD screen that you will use in Lab 4. One funtion should  initialize the LCD screen and the other should display a character on the LCD and keep track of the cursor position..

The LCD

The LCD which you will be using has many advanced functions (see the datasheet for a complete explanation), but you will only be concerned with the following two:

  1. Reset and clear the display.
  2. Write characters to the display.

We are using a LCD with a display area of 2 rows by 16 columns which gives a total of 32 characters that can be displayed at once.

The pin layout of the LCD follows:

Pin

Name

Function

1

GND

0 V

2

Vdd

5 V

3

Vo

1 V

4

RS

High: Data input

Low: Instruction input

5

R/W

High: Read from LCD

Low: Write to LCD

6

E

Enable the LCD

7

DB0

Data bus

8

DB1

9

DB2

10

DB3

11

DB4

12

DB5

13

DB6

14

DB7

 

Pins 1-3 are power supply connections and will be explained later. Pins 4-14 are signals that you must supply.  R/W specifies whether you are reading or writing the display: Since you will only be writing to the display, the R/W signal will always be 0. RS is used to determine whether you are sending a command or ASCII data to the display. E (enable) is used to provide a strobe that causes the operation to be executed.  The enable E is really a clock signal for the LCD that you must generate: the LCD reads the signals being placed on its pins and commits a new character or command on the negative edge of E.  The data pins contain either an ASCII character code or a command code depending upon the value of RS. In Lab you will need to multiplex this data bus between the signals meant for the LCD and signals meant for the 7-segment LED.  

The following is a table with the codes for 5 of the commands that you need to execute for this assignment. The first four should be called in an intialization routine and executed in sequence on reset. Please check the datasheet for the timings needed. The last command is used to write a character to the display. You can look at the documentation (see the datasheet) if you would like to try out other commands.

Operation

RS

DB[7:0]

Clear Display

0

0000 0001

Function Set

0

0011 1000

Display On

0

0000 1100

Entry Mode Set

0

0000 0110

Write Character

1

DDDD DDDD

The LCD will be connected to the prototyping board by wiring the ATmega's PORTC[7:0] to the LCD's DB[7:0].  (NOTE: In Lab you will use the Enable signal to multiplex PORTC between signals meant for the LCD and signals meant for the 7-segment LED). Connect the LCD's  Enable and RS signal to PD2(Pin 16) and PD3(Pin 17).

Prelab Turn-In

Code Requirements: I mplement two functions

  1. LCD initialization - Should initialize/setup the LCD screen to receive characters.
  2. LCD character displaying function 

Please complete the prelab individually. Please turn-in your commented C at the beginning of next week's lab.

Notes about Lab 4:

This week's prelab does NOT cover all the code you will need to write for Lab 4. Lab 4 also requires you to use the ADC to determine the value of the potentiometer and photoresistor. Feel free to start working ahead on the lab so that you will be able to finish on time. The lab will be posted on Tuesday (or earlier).