Read char-mod.PDF text version

INC. Application Note

Crystal Clear and Visibly Superior LCD Modules

Displaying Characters on an LCD Character Module

I. Introduction:

This application note describes a simple technique to display characters from both the internal character generator and user designed characters on an LCD character module.The controlling microcontroller is a Phillips 87C751, a derivitive of the popular Intel 8051. The LCD module is connected to the microcontroller through its I/O ports. It could also be connected directly to the data bus with the addition of address decoding logic. The process of displaying character to this module is divided into three steps. First the module must be initialized. This sets up the built-in LCD controller chip. Second, some user designed characters are uploaded to the CGRAM. This allows the displaying of up to 8 custom characters in addition to the 192 character permanently stored in the module. Lastly, a message consisting of a mix of standard ASCII characters and custom designed characters is displayed on the module.

II. Circuit Schematic

5V Vdd GND

P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 U1

D0 D1 D2 D3 D4 D5 D6 D7 LCM1

C3 0.1uF R2

SW1 RST 20KOhm XTR1 16MHz X1

87C751

P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 E RS RW

Char LCD Module

5V VDD VL GND 10KOhm R1

X2

C1 33pF

C2 33pF

Parts List LCM1 U1 XTR1 C1,C2 SW1 R1 R2 C3

Part Number HDM16216H-5 87C751 NMP160 33pF -10Kohm 20Kohm 0.1 uF

Description Hantronix Alphanumeric LCD Module Phillips Microcontroller 16MHz Crystal Capacitor Push Button Switche (Reset) Pot Resistor Capacitor

- Page 1 -

INC. Application Note III. Software Flowchart:

Crystal Clear and Visibly Superior LCD Modules

Begin P1 = 38h, Command_Byte

Write

Data=[DPTR] 4.1mSec Delay ? Data = 99h P1 = 38h, Command_Byte Initialization 100uSec Delay P1 = 38h, Command_Byte P1 = 0ch, Command_Byte P1 = 01h, Command_Byte Call Data_Byte

No Yes

Return

INC DPTR

CGRAM First_Line Second_Line: Command_byte IDLE RS low * CGRAM: Program in CGRAM DATA First_Line: Display First Line Second_Line: Display Second Line RS high Data_byte

RW low - Enable write

DELAY Start Timer TestFlag = 0

E low - generate enable pulse

Timer0 Interrupt: TestFlag=1 Stop Timer

nop

TestFlag=1 ?

No

Yes

Return

E high - pull up enable signal

RW high - Read mode

Configure P1 to input port

DB7 = 1?

Yes

No

Return

- Page 2 -

INC. Application Note

;********************************************************** ;; Application Note: ; ================= ; Displaying Characters on an LCD Character Module ; ; Description: Demo software to display "canned" message and custom characters. .; Controller: Phillips 87C751 ; LCD controller: HD44780, KS0066, SED1278 ; ;************************************************************* ; Constant Definition ;************************************************************* EnableT0 equ 082h ;enable timer0 Disable equ 000h ;disable timer D4100h equ 00ch ;timer reload high byte def. D4100l equ 003h ;timer reload = 4.1mSec. D100h equ 000h ;timer reload D100l equ 04ch ;timer reload = 100uSec. ;***************************************** ; Ram Definition ;***************************************** Flags DATA 020h ;flag TstFlag BIT Flags.0 ;interrupt flag bit ;***************************************** ; Port Connections ; ================= ; P1.0 -> D0 ; P1.1 -> D1 ; P1.2 -> D2 ; ... ; P1.7 -> D7 ; P3.0 -> Enable ; P3.1 -> RS ; P3.2 -> RW ;******************************************************* ; Interrupt Vectors ; -----------------org 000h jmp PowerUp ; Power up reset vector org 003h jmp ExInt0 ; External interrupt 0 vector org 00bh jmp Timer0 ; Counter/ Timer 0 int vector org 013h jmp ExInt1 ; External int 1 vector org 01bh ; jmp Timer1 ; Timer 1 int vector org 023h jmp I2C ; I2C serial int vector org 50h PowerUp: ;***** Timer 0 Interrrupt preparation clr TR clr TF ;************************************** ; LCD Initialization Routine ;************************************** cinit: clr P3.1 clr P3.2 setb P3.0 mov mov RTL,#D4100l RTH,#D4100h

Crystal Clear and Visibly Superior LCD Modules

mov acall acall mov mov mov acall acall mov acall mov acall mov acall acall acall acall sdone: setb jmp IDLE sdone ;power down mode p1,#38h command_byte ddelay RTL,#D100l RTH,#D100h p1,#38h command_byte ddelay p1,#38h command_byte p1,#0ch command_byte p1,#01h command_byte cgram first_line second_line

;initial delay 4.1mSec ;set timer reload value ;dealy time = 100uSec ;function set ;busy flag not avail. yet ;function set ;display on ;clear display

;define custom fonts ;display first line ;display second line

;******************************************************** ;Subroutine: WRITE ;================= ;Purpose: To feed in data/command bytes to the LCD module ;Parameters:dptr = should be set to the beginning of ; the data byte address ; Data bytes should be finished with 99H ;Alg: get a new data/command byte ; while (new data != 99h) { ; set port1 with new data ; call data_byte ; increment data pointer ; } ; return ;******************************************************** write: write_loop: mov a,#0 movc a,@a+dptr cjne a,#99h,write_cont ret write_cont: mov p1,a acall data_byte inc dptr jmp write_loop ;************************************************ ; Delay Routine: ; Delay periond = 4/3uSec * DefRth,l ;************************************************ ddelay: setb TR ;start timer mov IE,#EnableT0 ;enable timer clr TstFlag ;reset flag dloop: jnb TstFlag,dloop ret ;******************************** ; set address to beginning ; of CG RAM ;********************************

;disable timer ;clear overflow

;RS low ;RW low ;Enable ;set timer reload value ;dealy time = 4.1mSec

- Page 3 -

INC. Application Note

cgram: mov p1,#40h acall command_byte mov dptr,#cgram_data acall write ret ;******************************** ; Set DDRAM to the beginnig of ; the first line - 00 ;******************************** first_line: mov p1,#080h ;set DDRAM acall command_byte mov dptr,#fline_data acall write ret ;******************************** ; Set DDRAM to the beginning of ; the second line - 40 ;******************************** second_line: mov p1,#0c0h ;set DDRAM acall command_byte mov dptr,#sline_data acall write ret ;********************************************************** ; Feed Command/Data to the LCD module ;*********************************************************** command_byte: clr p3.1 ; RS low for a command byte. jmp bdelay data_byte: setb p3.1 ; RS high for a data byte. nop bdelay: clr p3.2 ; R/w low for a write mode clr p3.0 nop setb p3.0 ;enable pulse nop ;******************* Check Busy Flag mov p1,#0ffh ;configure port1 to input mode setb p3.2 ;set RW to read clr p3.1 ;set RS to command clr p3.0 ;generate enable pulse nop setb p3.0 bloop: nop mov a,p1 anl a,#80h ;check bit#7 busy flag cjne a,#00h,bloop;keep waiting until busy flag clears ;***************************************** ; check busy flag twice ;***************************************** bwait: mov a,p1 anl a,#80h cjne a,#00h,bloop clr p3.2 ;return to write mode ret ;****************************************** ; Interrupt Routines ;****************************************** ExInt0: ExInt1: Timer1: I2C: reti ;********************************************** Timer0: setb TstFlag clr TR mov IE,#Disable reti ;******************************************** ; Data Bytes ;******************************************* FLINE_DATA: db `>>> HANTRONIX <<<' db 099h SLINE_DATA: db 00h,01h,02h,03h,04h,05h,06h,07h db 099h CGRAM_DATA: font1: db 0ah,15h,11h,11h,0ah,04h,00h,00h font2: db 04h,0ah,11h,11h,15h,0ah,00h,00h font3: db 04h,0eh,15h,04h,04h,04h,04h,00h font4: db 04h,04h,04h,04h,15h,0eh,04h,00h font5: db 18h,18h,1fh,1fh,1fh,18h,18h,00h font6: db 1fh,1fh,03h,03h,03h,1fh,1fh,00h font7: db 0ah,15h,0ah,15h,0ah,15h,0ah,00h font8: db 15h,0ah,15h,0ah,15h,0ah,15h,00h db 99h end

Crystal Clear and Visibly Superior LCD Modules

*Display on a 16x2 Character Module

* Display Character Position and DDRAM Address of a 16x2 Character Module.

1 First Line Second Line 00 40 2 01 41 3 02 42 4 03 43 Display Position .... .... DDRAM Address 14 0D 4D 15 0E 4E 16 0F 4F

BITS 7 6 5 4 3 2 1 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7 BYTE 8

BITS 5,6,&7 NOT USED

* Custom characters memory map.

- Page 4 -

Information

char-mod.PDF

4 pages

Report File (DMCA)

Our content is added by our users. We aim to remove reported files within 1 working day. Please use this link to notify us:

Report this file as copyright or inappropriate

201788


You might also be interested in

BETA
char-mod.PDF