Interfacing the HC(S)12 microcontroller to a Hitachi/Optrex LCD Display Panel The LCD display panel contains its own microcontroller (Hitachi HD44780)

Slides:



Advertisements
Similar presentations
Lab 12 : Liquid Crystal Displays: Slide 2 Slide 3 Slide 4 Slide 5 Slide 6 Slide 7 DMD Basics : Slide 8 Slide 9 Slide 10 Slide 11 Slide 12 Data Write the.
Advertisements

Programmable Interval Timer
SCI: Serial Communications Interface Presented by: Sean Kline Chad Smith Jamie Cruce.
68HC11 Polling and Interrupts
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering Interfacing the HC(S)12 microcontroller to a Hitachi/Optrex LCD Display Panel.
Overview What kind of LCD Interfacing the LCD Displaying Text and Numbers Common Issues.
Digital Outputs LCD Display
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
8279 KEYBOARD AND DISPLAY INTERFACING
9-1 EE 319K Introduction to Microcontrollers Lecture 9:I/O Synchronization; LCD Interfacing; Implementing Local Variables using a Stack Frame; Parameter.
6-1 EE 319K Introduction to Microcontrollers Lecture 6: Indexed Addressing Mode and Variants, Functional Debugging, Arrays, Strings.
1 October 26, 2006ME 6405 MechatronicsSerial Communication Interface Brian Guerriero Jon Rogers Robert Thiets.
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
ECE Lecture 21 Typical Assembly Language Program Bugs.
8279 KEYBOARD AND DISPLAY INTERFACING
Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC.
Advanced Assembly Language Programming
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
Stacks and Subroutines May 23. Stacks and subroutine usage The stack is a special area of the random access memory in the overall memory system The stack.
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
Serial mode of data transfer
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
LCD Interfacing using Atmega 32
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
Mon Sept. 11 Announcements
ECE 3430 – Intro to Microcomputer Systems
MIPS Instruction Set Advantages
Buffered, Interrupt-Driven Printer Design Example
ECE 3430 – Intro to Microcomputer Systems
Fri. Sept 29 Announcements
Mon. Oct 2 Announcements Quiz Postponed to Wednesday – still only on 2.a + 2.b Video lecture for 2.a posted Lab 6 experiment extension You must come to.
LCD and Keyboard Interfacing
Control Structure Applications
GANDHINAGAR INSTITUTE OF TECHNOLOGY
Chapter 11: Inter-Integrated Circuit (I2C) Interface
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
General Purpose I/O.
ECE 3430 – Intro to Microcomputer Systems
8086 Microprocessor.
Programmable Interval Timer
SERIAL PORT PROGRAMMING
Buffered, Interrupt-Driven Printer Design Example
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Keyboard/Display Controller INTEL 8279
EET 2261 Unit 11 Controlling LCD and Keypad
Branching and Looping Lecture L3.2.
Control Structure Applications
LCD and Keyboard Interfacing
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME4447/6405 Microprocessor Control of Manufacturing Systems and
EET 2261 Unit 11 Controlling LCD and Keypad
LCD and Keyboard Interfacing
Programmable Interval timer 8253 / 8254
I2C Protocol and RTC Interfacing
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
LCD and Keyboard Interfacing
LCD and Keyboard Sepehr Naimi
Programmable Interval timer 8253 / 8254
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
8279 – Programmable Keyboard/Display Interface
8051 Micro Controller.
LCD and Keyboard Interfacing
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Presentation transcript:

Interfacing the HC(S)12 microcontroller to a Hitachi/Optrex LCD Display Panel The LCD display panel contains its own microcontroller (Hitachi HD44780) that communicates with an external microcontroller over a relatively simple interface and also controls the LCD display driver IC. This LCD panel receives 8-bit binary commands and/or ASCII data characters from the external microcontroller (our CSM12C32 module). Communication between the external microcontroller and the HD44780 LCD panel microcontroller requires eight or four data lines (in 4-bit mode, the 8-bit data characters and commands are sent as two back-to-back 4-bit nybbles), and two control lines: a data enable clock line (E), and a Command/Data Register Select (RS) line. When 8 data lines are used, communication is faster, but requires four more external microcontroller I/O pins. The number of pins required at the external microcontroller may be reduced to three pins using an SPI port between the LCD panel and the microcontroller!

Optrex and Hitachi LCD Panel Display

LCD Panel Pin Description DB7:0 – Data Bus. 8-bit data bus for both display commands AND display ASCII data. 4-bit mode transfers occur as two back-to- back 4-bit transfers on DB7:4 (DB3:0 are not connected.) RS – Register Select. Set to 0 to indicate a command on Data Bus and 1 to indicate ASCII data on Data Bus. RW-Read/Write. Set to 0 for write to data bus and 1 for read from data bus. We shall strap this pin to 0 V, so that it is permanently enabled for WRITE to data bus mode, in order to simplify our interface. E – Enable (data clock). This pin must rise at least 140 ns after RS and R/W have been set up, and it must fall at least 195 ns after DB7:0 has been set up. Furthermore, DB7:0 must be held at least 10 ns after E falls. Also, E must be high for at least 450 ns.

Tie Vee pin to 0V for maximum Contrast

The setting of RS and R/W allows us to: The setting of RS and R/W allows us to: (1) write data to Display RAM (DR) (2) Read data from DR (3) Write commands to the display (4) read the busy flag and current value of the address counter (which controls position of character being written to DR.) We shall tie R/W low so that we will only write commands and ASCII data to the LCD panel

Note: to minimize the complexity of our interface (at the expense of slowing data transfer to the LCD panel), we shall use 4-bit mode, and we shall NOT check the LCD panel’s “Busy Flag”. Instead, we shall allow plenty of extra time for the data transfer to complete and for the “Busy Flag” to be set.

Main.asm – Main program that calls the LCD display routine “LCD_MESSAGE” in the “lcd_subroutines.asm” file. xdef Entry ;Entry point must be available to debugger xref LCD_MESSAGE ;These routines are in another file xref LCD_INIT include 'mc9s12c32.inc' CodeSec: SECTION ;relocatable code section Entry: lds #$1000 jsr LCD_INIT ldx #msg1 ldab #0 ;Display Data RAM address 0 = start of 1st line jsr LCD_MESSAGE ldab #$40 ;Display Data RAM address $40 = start of 2nd line ldx #msg2 wthr: bra wthr ConstSec: SECTION ;relocatable constant section msg1: dc.b "hello there", 0 ;ASCII null-terminated string msg2: dc.b "this is a test", 0 ;ASCII null-terminated string end

“lcd_subroutines.asm” file (to be linked with main.asm) ;***************************************************** ;Type: M68HCs12 Assembly Program for Code Warrior ;Program Name: lcd4bit_display ;Written By: Jianjian Song & Keith Hoover ;Date: October 5 2007 ;Purpose: 4-Bit Mode LCD Panel interfacing via E, RS, DB7-4 ;Display Panel Connections ;1--Vss(0V), 2--Vcc(5V), 3--Vee (0V), 4--RS = PT2, 5--R/W = 0V, ;6--E clock = PT3,11--DB4 = PT4,12--DB5 = PT5,13--DB6 = PT6 ;14--DB7 = PT7. ;**************************************************** xdef LCD_INIT ;MAKE THE FOLLOWING ;AVAILABLE TO OTHER FILE xdef LCD_DATA xdef LCD_ADDRESS xdef LCD_MESSAGE include 'mc9s12c32.inc' ;Initialize the LCD panel hardware interface LCD_DATA: EQU PTT LCD_CTRL: EQU PTT LCD_DATA_DIRECTION EQU DDRT LCD_CTRL_DIRECTION EQU DDRT DATA_OUTPUT EQU %11110000

lcd_subroutines.asm, continued CTRL_OUTPUT EQU %00001100 E: EQU %00001000 ;E = MASK TO ACCESS PT3 = LCD CONTROL LINE E RS: EQU %00000100 ;RS = MASK TO ACCESS PT2 = LCD CONTROL LINE RS DataSec: SECTION TIME: DS 2 ;delay time variable CodeSec: SECTION ;************************************************************* ;LCD_INIT subroutine ;Initializes LCD Display according to manufacturer's directions ;************************************************************ LCD_INIT: BSET LCD_DATA_DIRECTION,DATA_OUTPUT ;MAKE PT7:4 DRIVE LCD DB7:4 DATA INPUTS BSET LCD_CTRL_DIRECTION,CTRL_OUTPUT ;MAKE PT2 & PT3 DRIVE LCD RS ;AND E CONTROL LINES BCLR LCD_CTRL,E ; Set E to 0 BCLR LCD_CTRL,RS ; Set RS=0 to select instruction entry mode CLR LCD_DATA ; 1st wait for 20 milliseconds (minimum of 15 ms) MOVW #400, TIME JSR VAR_DELAY

lcd_subroutines.asm, continued ; Note: the LCD display always powers up in 8-bit transfer mode, but even though all 8 ; bits are transferred into the display module when E falls, the bottom 4 bits of each ; byte are IGNORED when an INIT command is sent, so it is OK that the bottom 4 bits of the ; LCD panel data bus (DB3:0) are not connected to anything! ; send the 8-bit mode INIT command 3 times in a row (as recommended by manufacturer) ; Here is the first INIT command LDAB #$30 JSR SEND4bits ; wait for 10 ms ( minimum of 4.1 ms) before sending next INIT command. MOVW #200, TIME JSR VAR_DELAY ; send second INIT command JSR SEND4bits; 3rd wait for 1 millisecond (minimum of 0.1 ms) MOVW #20, TIME

lcd_subroutines.asm, continued JSR VAR_DELAY LDAB #$30 JSR SEND4bits ; Send third INIT command MOVW #20, TIME ; Now send a fourth init command so that it changes the data transfer mode ; from 8-bits all at once to the 4-bit transfer mode, in which an 8-bit ; byte is transferred over the most-significant 4 bits of the display panel ; data bus (DB7:4)by two back-to-back calls to SEND4bits LDAB #$20 JSR SEND4bits ; This command sets data transfer mode to 4-bit mode, so now a full 8-bits are transferred ; by two back-to-back calls to SEND4bits LDAB #$28 JSR SENDBYTE ; Function Set Command Format: 0 0 1 DL N F * * ; We just sent: 0 0 1 0 1 0 0 0 ; DL=0 => 4-bit mode, ; N=1 => 1/8 duty cycle ; F=0 => 5 X 7 dot font LDAB #$08 JSR SENDBYTE ; Display OFF command LDAB #$01 JSR SENDBYTE; ;Clear display and return home

lcd_subroutines.asm, continued LDAB #$06 JSR SENDBYTE ;Entry mode set command format: 0 0 0 0 0 1 I/D S ;I/D = 1 => Increment display addr ptr. ;S = 0 => Do not shift (scroll) display LDAB #$01 JSR SENDBYTE; ;Clear display and return home LDAB #$0F JSR SENDBYTE ; Display ON command RTS ;********************************************************

lcd_subroutines.asm, continued ;******************************************************************* ; Subroutine SEND4bits drives 4-bit data outon upper 4 bits of LCD data port ; then, after > 1 us delay, raises the E line, then, after > 1 us delay ; lowers the E line to complete the write cycle, then, after > 1 us delay ; returns. SEND4bits: PSHB ANDB #$F0 LDAA LCD_DATA ANDA #$0F STAA LCD_DATA ORAB LCD_DATA STAB LCD_DATA ;DRIVE 4-BIT DATA OUT ON UPPER 4 BITS OF DATA PORT JSR WT5US BSET LCD_CTRL,E ; RAISE E LINE JSR WT5US ; LET IT STAY HIGH FOR > 1 US BCLR LCD_CTRL,E ; LOWER IT MOVW #2, TIME ; Wait 1 us for BF flag JSR VAR_DELAY PULB RTS

; Subroutine WT5US waits approximately 5 us, then returns ;******************************************************** WT5US: PSHY ;WAIT ABOUT 5 US LDY #10 WTHERE: DBNE Y,WTHERE PULY RTS ;**************************************************************** ; Subroutine: VAR_DELAY ; Delays for a period of time equal to Tdelay = TIME*50 microseconds ; This assumes a 24MHz bus clock, and that the RAM location ; "TIME" is a input variable that must be loaded prior to calling VAR_DELAY ; Note: The inner loop delay time = (4*300+4)*(1/24MHz)=50 microseconds LOOPS EQU 2400 VAR_DELAY: PSHX ; 2 cycles PSHY ; 2 cyles LDY TIME ;3 cycles LP1: LDX #LOOPS ; 2 cycle LP2: DEX ; 1 cycle BNE LP2 ; 3 cycles DEY ; 1 cycles BNE LP1 ; 3 cycles PULY ; 3 cycles PULX ; 3 cycles RTS ; 5 cycles

lcd_subroutines.asm, continued ;********************************* ; SUBROUTINE: SENDBYTE ; Writes a byte in Accumulator B to LCD panel in "4-bit transfer" mode ; via two back-to-back 4-bit writes over bits DB7:4) SENDBYTE: PSHB ; send higher nibble out on DB7:4 first JSR SEND4bits MOVW #2,TIME ;Wait 100 us after first 4-bit transfer cycle JSR VAR_DELAY PULB ; rotate lower nibble up into B7:4 ROLB ; send lower nibble out on DB7:4 last MOVW #2,TIME JSR VAR_DELAY ;Wait 100 us after second 4-bit transfer cycle RTS

lcd_subroutines.asm, continued ;********************************* ; SUBROUTINE: LCD_ADDRESS ; Sends an address in Accumulator B to LCD and thereby positions cursor ; to any arbitrary position on display. Addr $00...$17 => 1st row of display ; Addr $40...$57 => second row of display. LCD_ADDRESS: PSHB BCLR LCD_CTRL, RS ; Place LCD in command mode (RS = 0) ORAB #$80 ; Set MSB so the DDR address set command is sent JSR SENDBYTE PULB RTS ; SUBROUTINE: LCD_DTA ; displays 8-bit ASCII-coded character in B register LCD_DTA: BSET LCD_CTRL, RS ; Place LCD in ASCII CHARACTER DISPLAY mode JSR SENDBYTE ; (RS = 1)

lcd_subroutines.asm, continued ;********************************* ; SUBROUTINE: LCD_MESSAGE(B,X) ; Displays an ASCII text message to LCD. ; Accumulator B contains the address to write to ; For 2 x 24 display, Line 1: 0 - 0x17, Line 2: 0x40..0x57 ; X register contains starting address of the ASCII-coded text message ; The text message must be terminated in an ASCII NULL ($00) character. LCD_MESSAGE: PSHB PSHX JSR LCD_ADDRESS ; send address to LCD NEXT: LDAB 0, X ; load character BEQ DONE ; exit if character is 0 (ASCII Null) JSR LCD_DTA ; send character in Accumulator A to LCD INX BRA NEXT DONE: PULX PULB RTS END