Interface and Simulation of a LCD Text Display



Similar documents
Definitions and Documents

Keil C51 Cross Compiler

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

Lecture 22: C Programming 4 Embedded Systems

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

AN4032 Application note

LMB162ABC LCD Module User Manual

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

ELEG3924 Microprocessor Ch.7 Programming In C

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

ENGI E1112 Departmental Project Report: Computer Science/Computer Engineering

8051 MICROCONTROLLER COURSE

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Microprocessor & Assembly Language

Microtronics technologies Mobile:

Help on the Embedded Software Block

GDM1602A SPECIFICATIONS OF LCD MODULE. Features. Outline dimension

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

AN1754 APPLICATION NOTE

AVR Butterfly Training. Atmel Norway, AVR Applications Group

CENTRONICS interface and Parallel Printer Port LPT

LCD I 2 C/Serial RX Backpack. Data Sheet. LCD to I2C/Serial RX Backpack I2C or Serial RX communication with Standard 16 Pin LCD modules

Project Manager Editor & Debugger

Chapter 5 Real time clock by John Leung

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

HD44780U (LCD-II) (Dot Matrix Liquid Crystal Display Controller/Driver)

Using the CoreSight ITM for debug and testing in RTX applications

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

DOT MATRIX CHARACTER LCD MODULE USER S MANUAL

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

HD44780-Based LCD Modules. Introduction to the LM018L

OPTREX CORP. LCD MODULE

NB3H5150 I2C Programming Guide. I2C/SMBus Custom Configuration Application Note

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Informatica e Sistemi in Tempo Reale

Software based Finite State Machine (FSM) with general purpose processors

PART B QUESTIONS AND ANSWERS UNIT I

Arduino Lesson 5. The Serial Monitor

RS-485 Protocol Manual

Embedded C Programming

Designed & Developed By: Ms. Nidhi Agarwal. Under the Guidance of: Dr. SRN Reddy, Associate Professor, CSE. Computer Science & Engineering Department

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

LCM NHD-12032BZ-FSW-GBW. User s Guide. (Liquid Crystal Display Graphic Module) RoHS Compliant. For product support, contact

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

Implementing a Data Logger with Spansion SPI Flash

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Embedded Systems Design Course Applying the mbed microcontroller

Ride7 for ARM. RAISONANCE Tools for the STRx and STM32 families. Overview and Getting Started

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

Technical Data Sheet UM-005. UM005-doc In reference to UM005-c-01.04

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Keil Debugger Tutorial

Embedded Software development Process and Tools:

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

The programming language C. sws1 1

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

Freescale Semiconductor, I

1602 LCD adopts standard 14 pins(no backlight) or 16pins(with backlight) interface, Instruction of each pin interface is as follows:

4 Character 5x7 LED Matrix Display

Creating a Project with PSoC Designer

USBSPYDER08 Discovery Kit for Freescale MC9RS08KA, MC9S08QD and MC9S08QG Microcontrollers User s Manual

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

Have both hardware and software. Want to hide the details from the programmer (user).

Sources: On the Web: Slides will be available on:

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO

HANDLING SUSPEND MODE ON A USB MOUSE

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Servo Motor API nxt_motor_get_count nxt_motor_set_count nxt_motor_set_speed

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

Parallax Serial LCD 2 rows x 16 characters Non-backlit (#27976) 2 rows x 16 characters Backlit (#27977) 4 rows x 20 characters Backlit (#27979)

Surveillance System Using Wireless Sensor Networks

Bluetooth to serial HC-06 wireless module

CHAPTER 11: Flip Flops

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

LCD Module User Manual

Adapting the PowerPC 403 ROM Monitor Software for a 512Kb Flash Device

Embedded Component Based Programming with DAVE 3

Getting Graphic: Defining Custom LCD Characters

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

1. Computer System Structure and Components

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Using the HCS12 Serial Monitor on Wytec Dragon-12 boards. Using Motorola s HCS12 Serial Monitor on Wytec s Dragon-12 boards

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Designing VM2 Application Boards

Specification. For. LCD Module CCM1620CSL

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

SUDT AccessPort TM Advanced Terminal / Monitor / Debugger Version 1.37 User Manual

3.2 inch QVGA TFT Color LCD User s Guide Version 1 & 2

Section 29. Real-Time Clock and Calendar (RTCC)

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Set up a Nios II project that specifies a desired hardware system and software program

Introduction to graphics and LCD technologies. NXP Product Line Microcontrollers Business Line Standard ICs

µtasker Document FTP Client

Transcription:

OVERVIEW The following application note describes the interface of a LCD text display to a 8051 microcontroller system. This application note comes with the µvision2 project LCD_Display.UV2 that includes C source code of the interface software and a complete simulation script for simulator based testing. In this example, we are using the LCD-Controller ST6077. However, the interface to other text displays is similar. µvision2 provides full integration of the C51 compiler and debugger. Today applications need to be tested before real hardware becomes available. Therefore µvision2 offers both: a simulator that seamless simulates the complete peripherals of countless 8051 derivatives, and a target debugger that allows software testing in real hardware with a target monitor or emulator. If you open the µvision2 project LCD_Display.UV2 you can easily follow the steps described in this application note. HARDWARE INTERFACE This section gives an overview about the connection and communication between the ST6077 LCD display device and the 8051 microcontroller. Details are provided in the datasheet st6077v151.pdf that comes in the file.zip. The schematic below shows you how the devices are connected: The data bus of the ST7066 is connected to the 8051 Port P0. The three control pins RS, RW, and E are connected to the 8051 I/O Port P2.0 P2.1. These connections are reflected in the software interface. Overview of the display pins DB0 DB7 RW RS Page 1 of 6 8bit data bus Selects Read or Write mode 0: Read 1: Write Select Registers 0: Instruction register (for write) / address counter (for read)

1: Data Register (read and write) E Enables data read/write (This has to follow each command) SOFTWARE INTERFACE The file LCD_interface.C, that comes with the µvision2 project LCD_Display.UV2 is the source code that handles all basic input/output to the LCD text display. You may use this file as template for your own 8051 display driver. ------------------------------------------------------------------------------ LCD_interface.C Copyright 2001 Keil Software, Inc. ------------------------------------------------------------------------------ #include <reg51.h> #include <stdio.h> #include <intrins.h> sbit P20_PIN = P2^0; // I/O Pin for P2.0 sbit P21_PIN = P2^1; // I/O Pin for P2.1 sbit P22_PIN = P2^2; // I/O Pin for P2.2 #define LINE1_ADDR 0x00 #define LINE2_ADDR 0x40 // Start of line 1 in the DD-Ram // Start of line 2 in the DD-Ram Display-Commands #define CLEAR_DISPLAY 0x01 // Clear entire display and set Display Data Address to 0 #define DD_RAM_PTR 0x80 // Address Display Data RAM pointer #define DISP_INIT 0x38 // 8 bit 2 lines #define INC_MODE 0x06 // Display Data RAM pointer incremented after write * ReadInstrReg: Read from Instruction Register of LCD Display Device static unsigned char ReadInstrReg (void) { unsigned char Instr; // DATA PORT is input P20_PIN = 0; // select instruction register P21_PIN = 1; // read operation Instr = P0; // read Instruction return(instr); * WriteInstrReg: Write to Instruction Register of LCD Display Device static void WriteInstrReg (unsigned char Instr) { P20_PIN = 0; // select instruction register P21_PIN = 0; // write operation P0 = Instr; // write instruction // DATA_PORT is input [prevent I/O-Port from damage] * ReadDataReg: Read from Data Register of LCD Display Device Page 2 of 6

static unsigned char ReadDataReg (void) { unsigned char val; // DATA_PORT is input P20_PIN = 1; // select data register P21_PIN = 1; // read-operation val = P0; // read Instruction return (val); * WriteDataReg: Write to Data Register of LCD Display Device static void WriteDataReg (unsigned char val) { P20_PIN = 1; // select data register P21_PIN = 0; // write operation P0 = val; // write value // DATA_PORT is input [prevent I/O-Port from demage] char putchar (char c) { unsigned char line; if (c == '\n') { line = ReadInstrReg (); if (line & LINE2_ADDR) { // is already in line 2 WriteInstrReg (LINE1_ADDR DD_RAM_PTR); // place to start of line 1 else { WriteInstrReg (LINE2_ADDR DD_RAM_PTR); // place to start of line 2 else { WriteDataReg (c); return (c); * Waits for some time so the 7066 can do the last command void wait (unsigned int time) { int i; for (i = 0; i < time ;i++){ * Clear_Display: Write 0x20 to Display RAM static void Clear_Display (void) { WriteInstrReg (CLEAR_DISPLAY); wait (1); The putchar function is the basic output routine that is used for simple character output. These function is used by the function printf. In addition we have implemented the function Clear_Display. Page 3 of 6

The following test code allows you to check the implementation. void main (void) { unsigned char c; for (c = 'A'; c < 'H'; c++) { // Put the characters A to H to the display putchar (c); printf ("Hello \n"); // Puts Hello to the display using printf() Clear_Display (); //Clear the display and reset cursor for (c = 0; c < 10; c++) {. printf ("This is Display Line %bd\n", c); while (1); //never stop // another printf() testing Function Overview of the Software Interface ReadInstrReg () WriteInstrReg (Instr) ReadDataReg () WriteDataReg (val) putchar (c) Clear_Display () Returns the instruction in the instruction register. Writes the instruction Instr out to the instruction register. Nothing is returned. Returns the value in the Data Register. Writes the value val to the Data Register. Behaves like a normal putchar value. The value in c is written to the display and returned if it was successful. Clears the entire Display by filling the Data Ram with blanks. The test code does not use all interface functions, but they are implemented for completeness. µvision2 SIMULATION The following section shows you how to simulate the LCD text display with µvision2. The µvision2 simulator provides several ways to simulate a text display. One of the easiest methods is to use the µvision2 memory window as ASCII display. In addition to the standard microcontroller memory, µvision2 offers four user defined memory spaces that are accessed with the prefixes S:, T:, U:, and V:. We are using the U: memory space as display memory for the LCD text display. The µvision2 memory window is used in ASCII mode. You may resize the window, so that it reflects the size of your LCD display as shown below. The following µvision2 script defines debug functions and other required settings to simulate the LCD text display. Page 4 of 6

The MAP command reserves 80 Bytes of the user-memory U:. The size is identical to your display size. In this example: 2 rows * 0x40 characters = 0x80 character with 1 Byte each The debug function Simulate_Display is triggered on a write to Port 2 (P2). This behavior is defined with the BreakSet command on the last line of the µvision2 script. This command connects the control lines of the LCD text display controller to the simulated 8051 device. Any write event on Port 2 (P2) calls the function Simulate_Display. Depending on the previous Port 2 (SD_oldPORT2) state, a LCD display read or write command is performed as explained in the following diagram. E Read from display Write to display Read from LCD display: E (P2.2) signal changes from low to high. Write to LCD display: E (P2.2) signal changes from high to low. The signal RS (Port 2.0) selects the instruction register or the display RAM of the LCD device. The signal RW (Port 2.1) defines a read or write command to the LCD device. define unsigned char SD_oldPORT2; define unsigned char SD_cursor; MAP U:0, U:0x80 READ WRITE // This line maps the user memory. // U:0 as start address in the memory window shows it * Simulate the 'Clear Display' command func void SD_clear (void) { unsigned char i; for (i = 0; i < 0x80; i++) { _WBYTE (U:0+i, 0x20); // Writes blanks to the whole user memory ( display memory ) SD_cursor = 0; // Sets the cursor to the origin * Process all commands of the LCD display controller func void Simulate_Display (void) { if (!(SD_oldPORT2 & 0x04) && (PORT2 & 0x04)) { // LCD read: E changes to high if ((PORT2 & 0x03) == 0x02) { // read flag register PORT0 = (SD_cursor & 0x7F); //return DD RAM pointer to port 0 of the 8051 Page 5 of 6

if ((SD_oldPORT2 & 0x04) &&!(PORT2 & 0x04)) { // LCD write: E changes to low if ((PORT2 & 0x03) == 0) { // write to command register if (PORT0 == 0x01) { // command is 'Clear Display' SD_clear (); // call the 'Clear Display' simulation if (PORT0 & 0x80) { // Set DDRAM address (cursor position) SD_cursor = (PORT0 & 0x7F); // set DD RAM pointer if ((PORT2 & 0x03) == 0x01) { // command is 'Write to RAM' _WBYTE (U:0+SD_cursor, PORT0); // write to DD RAM (user memory @ U:0xXX) SD_cursor++; // Advance cursor position by 1 if (PORT2 & 0x02) { // read mode PORT0 = 0xFF; // display data goes to high SD_oldPORT2 = PORT2; // store E for change detection BS WRITE PORT2, 1, "Simulate_Display ()" The debug function Simulate_Display analyses some of the states of the LCD display device. To simplify the debug function, we have only implemented the commands that are used by the C51 software interface. The variable SD_cursor holds the cursor position in the DDRAM (diplay memory) and is used as pointer to the user memory U:. CONCLUSION Implementing an LCD text interface is straight forward with the Keil development tools. It is even possible to simulate the whole target system with µvision2 without scarifying execution speed. The simulation model described in this application note may be adapted to most other LCD text display controllers. This application note uses the µvision2 debug functions as peripheral interface. Application Note 154 Implementing µvision2 DLL s for Simulating User Defined Hardware describes an interface that is able to simulate complex peripherals which require accurate timing and/or several input/output variables. Page 6 of 6