Docsity

LCD Interface Routines Using the C Programming - Lab 5 Report | ECE 332, Lab Reports of Microprocessors

Toggle sidebar
bg1
Page 1 of 9
E 332L Microprocessors Lab (Fall 2007)
– Lab 5 (Week 7)–
Objective: In this lab, you will develop LCD interface routines using the C programming language.
Note 1: Use Lab 5’s sof and ptf files.
Note 2: KEY0 is processor’s reset. KEY1 (called button1 in Nios II) is level-sensitive button. KEY2 is rising-edge
sensitive button. KEY3 is rising-edge with interrupt button.
Part 1: High-Level Interface Provided by Altera Hardware Abstraction Layer (HAL1)
Interfacing to the Optrex LCD display requires finding, reading and interpreting documentation (data-sheets)
supplied by the manufacturer of the LCD display (Optrex) and the developer of the system utilizing the display
(Altera).
Altera has developed hardware and software to allow integration of the LCD display into their system. The layer
of software developed by Altera integrates the Optrex LCD display very nicely into the system that we have been
using.
The software portion of Altera’s implementation has been accomplished with an interface methodology referred
to as HAL. With this implementation the LCD can be utilized with an standard library functions (see figure
below). However, with this lab we want to understand just what it takes to communicate with the LCD at the
lowest levels.
#include <stdio.h>
#include "system.h"
int main (void)
{
FILE* LCD;
LCD = fopen ("/dev/lcd", "w");
if (LCD == NULL)
{
fprintf(stderr, "open failed\n");
return 0;
}
fprintf(LCD, "This is LCD demo\n");
fprintf(LCD, "Altera HAL usage");
fclose (LCD);
return 0;
}
Code 1: Example utilization of LCD with Altera’s HAL device interface
1 A hardware abstraction layer (HAL) is an abstraction layer, implemented in software, between the physical hardware of a
computer and the software that runs on that computer. Its function is to hide differences in hardware from most of the
operating system kernel, so that most of the kernel-mode code does not need to be changed to run on systems with different
hardware [Ref: http://www.wikipedia.org]
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download LCD Interface Routines Using the C Programming - Lab 5 Report | ECE 332 and more Lab Reports Microprocessors in PDF only on Docsity!

E 332L Microprocessors Lab (Fall 2007)

– Lab 5 (Week 7)–

Objective: In this lab, you will develop LCD interface routines using the C programming language.

Note 1: Use Lab 5’s sof and ptf files.

Note 2: KEY0 is processor’s reset. KEY1 (called button1 in Nios II) is level-sensitive button. KEY2 is rising-edge

sensitive button. KEY3 is rising-edge with interrupt button.

Part 1: High-Level Interface Provided by Altera Hardware Abstraction Layer (HAL

1

Interfacing to the Optrex LCD display requires finding, reading and interpreting documentation (data-sheets)

supplied by the manufacturer of the LCD display (Optrex) and the developer of the system utilizing the display

(Altera).

Altera has developed hardware and software to allow integration of the LCD display into their system. The layer

of software developed by Altera integrates the Optrex LCD display very nicely into the system that we have been

using.

The software portion of Altera’s implementation has been accomplished with an interface methodology referred

to as HAL. With this implementation the LCD can be utilized with an standard library functions (see figure

below). However, with this lab we want to understand just what it takes to communicate with the LCD at the

lowest levels.

#include <stdio.h> #include "system.h"

int main ( void ) { FILE* LCD;

LCD = fopen ("/dev/lcd", "w");

if (LCD == NULL ) { fprintf(stderr, "open failed\n"); return 0; }

fprintf(LCD, "This is LCD demo\n"); fprintf(LCD, "Altera HAL usage");

fclose (LCD);

return 0; }

Code 1: Example utilization of LCD with Altera’s HAL device interface

1 A hardware abstraction layer (HAL) is an abstraction layer, implemented in software, between the physical hardware of a computer and the software that runs on that computer. Its function is to hide differences in hardware from most of the operating system kernel, so that most of the kernel-mode code does not need to be changed to run on systems with different hardware [Ref: http://www.wikipedia.org]

Part 2: Where to Start?

The following is a discussion of some of the issues involved in developing software to work with hardware

devices.

2.1: Documentation

a. Finding it! Hopefully documentation came with the device. Since Altera developed a HAL interface, they did

not feel that it was necessary to provide much information on the low levels of operation. They did supply source

code for the HAL implementation, but wading through the details involved with HAL takes a considerable

amount of time. Optrex documentation can also be found on the web, but verifying that it matches the device

supplied by Altera is problematic.

b. Making sense of the documentation found. Often there is too much information - conflicting or extraneous.

What’s important?

c. Deciding on the applicability or points of view as to which side of device (HW vs. SW), and how to interpret it

for the other side of the device

d. Understanding the documentation is also a problem. The producers of the documentation generally do not like

writing things for consumption by others. This requires that the consumer develop a theory of operation and then

prove or disprove that theory.

In this lab, we will simplify the documentation issue by providing the following documentation for your use.

i. Optrex16207 LCD Controller Core with Avalon Interface (n2cpu_nii51019.pdf)

ii. Crystalfontz America, Inc. CFAH1602B-TMC-JP (CFAH1602BTMCJP.pdf)

iii. DOT Matrix Character LCD Module User’s Manual (Dmcman_full.pdf)

Some of the most important information is provided here. In future labs, you won’t be provided with this amount

of details. The goal is to show you what’s important and what’s not. Hopefully this will help you grasp how to

process the information on your own next time. Below is a block diagram for a generic Dot matrix LCD panel

produced by Optrex. Notice the signals defined on the left side of block diagram since they will be referred to in

later diagrams and documentation.

Detailed information on the method of software initialization as provided by Optrex follows. This is implement in

the LCD_init().

Below is an implementation of the information found in the previous tables and diagrams to accomplish the

process of initializing the Optrex 16207 LCD. You gave you a lot to start working on this lab. You should

compare this LCD_init() to the LCD_init() in LCD.c.

Example LCD Initialization Code

void LCD_init() { usleep(15000); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT;

usleep(4100); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT;

usleep(100); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT;

while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT | LCD_OPT_FUNC_TWO_LINE | LCD_OPT_FUNC_BIGFONT;

while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_ENABLE;

while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_CLEAR;

while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_MODE | LCD_OPT_MODE_INC;

while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_ENABLE | LCD_OPT_ENABLE_DISP | LCD_OPT_ENABLE_CURSOR | LCD_OPT_ENABLE_BLINK; }

#define method of creating above symbolic representation of Table 3.1 information

#define LCD_CMD_FUNC 0x20 // function set

Once the initialization process has been codified, software can be developed from the information provided in

Page 6 to fully utilize the functionality of the Optrex 16207 LCD display.

A set of template files have been provided to establish a framework that will achieve the task of utilizing most of

the functionality found in the 16207 device.

Below is an abbreviated illustration of the data flow that sends a string of characters to the LCD display. It

leaves out the issues involved in making sure that the display unit is not busy and ignoring inputs from an outside

source. Optrex has provided a busy flag that can be checked in order to determine when it is safe to send a

command or data to the device. Even when the busy flag indicates that it is safe to send data, an allowance for

extra delay is required to make sure the exchange of information with the LCD is reliable. Dealing with the issues

of timing and determining when it is safe to communicate with the LCD device should only be done in the low

level access routines.

main() { LCD_init();

while(1) { LCD_puts(“hello world”); } }

void LCD_puts(char s) { while (s) LCD_write_data(*s++); }

static void LCD_write_cmd (byte cmd) { LCD->write_cmd = cmd; }

static byte LCD_read_cmd (void) { return LCD->read_cmd ; }

static void LCD_write_data (byte data) { LCD->write_data = data; }

static byte LCD_write_cmd (void) { return LCD->read_data ; }

Command Register (write)

Bits (7-0)

Status Register (read)

Bits (7-0)

Data Register (write)

Bits (7-0)

Data Register (read)

Bits (7-0)

Low level Access

Functionality exposed to application via header file (LCD.h)