HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering Interfacing the HC(S)12 microcontroller to a Hitachi/Optrex LCD Display Panel.

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

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.
The 8051 Microcontroller and Embedded Systems
1 ELE271 Mon. April 7, Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54 Timer 2 Port (A,B), No Bidirectional.
Programmable Interval Timer
Programmable Keyboard/ Display Interface: 8279
SCI: Serial Communications Interface Presented by: Sean Kline Chad Smith Jamie Cruce.
Input/Output (I/O) Ports and Interfacing
ELEC 330 Digital Systems Engineering Dr. Ron Hayne
68HC11 Analog I/O Chapter 12.
68HC11 Polling and Interrupts
C and Assembler Subroutines: Using the LCD. Outline Basic structure of CW-created C programs for the HC12 How to incorporate assembly code How to use.
Spring EE 316 Computer Engineering Junior Lab LCD modules.
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.
Overview What kind of LCD Interfacing the LCD Displaying Text and Numbers Common Issues.
Digital Outputs LCD Display
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
MICROPROCESSOR INPUT/OUTPUT
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
8086/8088 Hardware Specifications Power supply:  +5V with tolerance of ±10%;  360mA. Input characteristics:  Logic 0 – 0.8V maximum, ±10μA maximum;
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
8279 KEYBOARD AND DISPLAY INTERFACING
EE 316 Computer Engineering Junior Lab Serial Ports, LCD Displays & PROMs.
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.
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
1 Stacks, Subroutines, I/O Routines Today: First Hour: Stacks, Subroutines –Section 3.9,3.10 of Huang’s Textbook –In-class Activity #1 Second Hour: I/O.
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
8-1 EE 319K Introduction to Microcontrollers Lecture 8:Fixed Point Numbers, Local Variables, Binding, Allocation, Access, Deallocation.
Ch.2 Intro. To Assembly Language Programming From Introduction to Embedded Systems: Interfacing to the Freescale 9s12 by Valvano, published by CENGAGE.
8279 KEYBOARD AND DISPLAY INTERFACING
Parallel I/O. Introduction This section focuses on performing parallel input and output operations on the 68HC11 3 operation types – Simple, blind data.
Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC.
Department of Electronic & Electrical Engineering Serial interfaces Serial Interfaces allow communication between devices sending one bit at a time. In.
Advanced Assembly Language Programming
Serial Peripheral Interface SPI I2C (i-squared cee)
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
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.
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
ECE 3430 – Intro to Microcomputer Systems
Interfacing the HC(S)12 microcontroller to a Hitachi/Optrex LCD Display Panel The LCD display panel contains its own microcontroller (Hitachi HD44780)
Buffered, Interrupt-Driven Printer Design Example
Fri. Sept 29 Announcements
LCD and Keyboard Interfacing
Control Structure Applications
GANDHINAGAR INSTITUTE OF TECHNOLOGY
Chapter 11: Inter-Integrated Circuit (I2C) Interface
SERIAL PORT PROGRAMMING
Buffered, Interrupt-Driven Printer Design Example
EET 2261 Unit 11 Controlling LCD and Keypad
Branching and Looping Lecture L3.2.
Control Structure Applications
LCD and Keyboard Interfacing
EET 2261 Unit 11 Controlling LCD and Keypad
LCD and Keyboard Interfacing
LCD and Keyboard Interfacing
LCD and Keyboard Sepehr Naimi
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
LCD and Keyboard Interfacing
Presentation transcript:

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering 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.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).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.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.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!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!

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering Optrex and Hitachi LCD Panel Display

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering

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.)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.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.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.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.

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering Tie Vee pin to 0V for maximum Contrast

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering 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

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering

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.

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering

xdef Entry ;Entry point must be available to debugger xrefLCD_MESSAGE;These routines are in another file xrefLCD_INIT, PLL_INIT xref__SEG_END_SSTACK ;High end of STACK area in RAM include 'mc9s12c128.inc' CodeSec: SECTION ;relocatable code section Entry: lds #__SEG_END_SSTACK jsr PLL_INIT;Set Bus Clock to 24 MHz jsr PLL_INIT;Set Bus Clock to 24 MHz jsr LCD_INIT ;Init LCD Display jsr LCD_INIT ;Init LCD Display ldx #msg1 ldx #msg1 ldab #0 ;Display Data RAM address 0 = start of 1 st line ldab #0 ;Display Data RAM address 0 = start of 1 st line jsr LCD_MESSAGE jsr LCD_MESSAGE ldab #$40 ;Display Data RAM address $40 = start of 2nd line ldab #$40 ;Display Data RAM address $40 = start of 2nd line ldx #msg2 ldx #msg2 jsr LCD_MESSAGE jsr LCD_MESSAGE 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 end Main.asm – Main program that calls the LCD display routine “LCD_MESSAGE” in the “lcd_subroutines.asm” file.

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering ;***************************************************** ;Type:M68HCs12 Assembly Program for Code Warrior ;Program Name:lcd4bit_display ;Written By: Jianjian Song & Keith Hoover ;Date:October ;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 xdefLCD_DTA xdefLCD_ADDRESS xdefLCD_MESSAGE include 'mc9s12c128.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 % “lcd_subroutines.asm” file (to be linked with main.asm)

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering CTRL_OUTPUT EQU % E:EQU% ;E = MASK TO ACCESS PT3 = LCD CONTROL LINE E RS:EQU% ;RS = MASK TO ACCESS PT2 = LCD CONTROL LINE RS DataSec: SECTION TIME:DS2;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 ;AND E CONTROL LINES BCLRLCD_CTRL,E ; Set E to 0 BCLRLCD_CTRL,RS; Set RS=0 to select instruction entry mode BCLRLCD_DATA,DATA_OUTPUT ;Set 4-bit data output to 0 ; 1st wait for 20 milliseconds (minimum of 15 ms) MOVW#400, TIME JSRVAR_DELAY lcd_subroutines.asm, continued

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering ; 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 JSR SEND4bits ; wait for 10 ms ( minimum of 4.1 ms) before sending next INIT command. MOVW#200, TIME JSRVAR_DELAY ; send second INIT command LDAB #$30 JSR SEND4bits; 3rd wait for 1 millisecond (minimum of 0.1 ms) JSR SEND4bits; 3rd wait for 1 millisecond (minimum of 0.1 ms) MOVW#20, TIME lcd_subroutines.asm, continued

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering JSRVAR_DELAY LDAB #$30 JSR SEND4bits ; Send third INIT command JSR SEND4bits ; Send third INIT command MOVW#20, TIME MOVW#20, TIME JSRVAR_DELAY ; 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 JSR SEND4bits MOVW#20, TIME MOVW#20, TIME JSRVAR_DELAY ; 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 LDAB #$28 JSR SENDBYTE ; Function Set Command Format: DL N F * * JSR SENDBYTE ; Function Set Command Format: DL N F * * ; We just sent: ; 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 JSR SENDBYTE ; Display OFF command LDAB #$01 LDAB #$01 JSR SENDBYTE; ;Clear display and return home JSR SENDBYTE; ;Clear display and return home lcd_subroutines.asm, continued

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

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering ;******************************************************************* ; Subroutine SEND4bits drives 4-bit data out on 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 PSHB ANDB #$F0 ANDB #$F0 LDAA LCD_DATA ; Load high 4 bits of accum B into LCD_DATA (PTT), but LDAA LCD_DATA ; Load high 4 bits of accum B into LCD_DATA (PTT), but ANDA #$0F ; leave the bottom 4 bits untouched (since E and RS are ANDA #$0F ; leave the bottom 4 bits untouched (since E and RS are STAA LCD_DATA ; in the bottom 4 bits!) STAA LCD_DATA ; in the bottom 4 bits!) ORAB LCD_DATA ORAB LCD_DATA STAB LCD_DATA ;DRIVE 4-BIT DATA OUT ON UPPER 4 BITS OF DATA PORT STAB LCD_DATA ;DRIVE 4-BIT DATA OUT ON UPPER 4 BITS OF DATA PORT JSR WT5US JSR WT5US BSET LCD_CTRL,E ; RAISE E LINE JSR WT5US ; LET IT STAY HIGH FOR > 1 US BCLRLCD_CTRL,E ; LOWER IT MOVW#2, TIME ; Wait 1 us for BF flag JSRVAR_DELAY PULBRTS lcd_subroutines.asm, continued

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering ; Subroutine WT5US waits approximately 5 us, then returns ;********************************************************WT5US: PSHY ;WAIT ABOUT 5 US PSHY ;WAIT ABOUT 5 US LDY #10 LDY #10WTHERE: DBNE Y,WTHERE DBNE Y,WTHERE PULY PULY RTS 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 BNELP2; 3 cycles DEY ; 1 cycles BNELP1; 3 cycles PULY; 3 cycles PULX ; 3 cycles RTS; 5 cycles

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering ;********************************* ; 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 PULBPSHB ; rotate lower nibble up into B7:4 ROLBROLBROLBROLB ; send lower nibble out on DB7:4 last JSR SEND4bits MOVW#2,TIME JSRVAR_DELAY ;Wait 100 us after second 4-bit transfer cycle PULBRTS lcd_subroutines.asm, continued

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering ;********************************* ; 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 JSR SENDBYTEPULBRTS;********************************* ; SUBROUTINE: LCD_DTA ; displays 8-bit ASCII-coded character in B register ;*********************************LCD_DTA:PSHB BSET LCD_CTRL, RS ; Place LCD in ASCII CHARACTER DISPLAY mode JSR SENDBYTE ; (RS = 1) JSR SENDBYTE ; (RS = 1)PULBRTS lcd_subroutines.asm, continued

HC12 and LCD, Jianjian Song, Dept. of Electrical and Computer Engineering ;********************************* ; 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 PSHBPSHX JSRLCD_ADDRESS; send address to LCD NEXT:LDAB0, X ; load character BEQDONE ; exit if character is 0 (ASCII Null) JSRLCD_DTA ; send character in Accumulator A to LCD INX BRANEXT DONE:PULX PULB PULBRTSEND lcd_subroutines.asm, continued