12.07.2015 Views

Displaying Characters on an LCD Character Module - Hantronix, Inc

Displaying Characters on an LCD Character Module - Hantronix, Inc

Displaying Characters on an LCD Character Module - Hantronix, Inc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Applicati<strong>on</strong> NoteINC.Crystal Clear <strong>an</strong>d Visibly Superior <strong>LCD</strong> <strong>Module</strong>s<str<strong>on</strong>g>Displaying</str<strong>on</strong>g> <str<strong>on</strong>g><strong>Character</strong>s</str<strong>on</strong>g> <strong>on</strong> <strong>an</strong> <strong>LCD</strong> <strong>Character</strong> <strong>Module</strong>I. Introducti<strong>on</strong>:This applicati<strong>on</strong> note describes a simple technique to display characters from both the internal charactergenerator <strong>an</strong>d user designed characters <strong>on</strong> <strong>an</strong> <strong>LCD</strong> character module.The c<strong>on</strong>trolling microc<strong>on</strong>troller isa Phillips 87C751, a derivitive of the popular Intel 8051. The <strong>LCD</strong> module is c<strong>on</strong>nected to the microc<strong>on</strong>trollerthrough its I/O ports. It could also be c<strong>on</strong>nected directly to the data bus with the additi<strong>on</strong> ofaddress decoding logic.The process of displaying character to this module is divided into three steps. First the module must beinitialized. This sets up the built-in <strong>LCD</strong> c<strong>on</strong>troller chip. Sec<strong>on</strong>d, some user designed characters areuploaded to the CGRAM. This allows the displaying of up to 8 custom characters in additi<strong>on</strong> to the 192character perm<strong>an</strong>ently stored in the module. Lastly, a message c<strong>on</strong>sisting of a mix of st<strong>an</strong>dard ASCIIcharacters <strong>an</strong>d custom designed characters is displayed <strong>on</strong> the module.II. Circuit Schematic5VVddGNDP1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7D0D1D2D3D4D5D6D7C3 SW10.1uFR2 20KOhmXTR116MHzC1 C233pF 33pFRSTX2X1U187C751P3.0P3.1P3.2P3.3P3.4P3.5P3.6P3.7LCM1Char <strong>LCD</strong> <strong>Module</strong>EVDDRSRWVLGND5V10KOhmR1Parts ListLCM1U1XTR1C1,C2SW1R1R2C3Part NumberHDM16216H-587C751NMP16033pF--10Kohm20Kohm0.1 uFDescripti<strong>on</strong>H<strong>an</strong>tr<strong>on</strong>ix Alph<strong>an</strong>umeric <strong>LCD</strong> <strong>Module</strong>Phillips Microc<strong>on</strong>troller16MHz CrystalCapacitorPush Butt<strong>on</strong> Switche (Reset)PotResistorCapacitor- Page 1 -


Applicati<strong>on</strong> NoteINC.Crystal Clear <strong>an</strong>d Visibly Superior <strong>LCD</strong> <strong>Module</strong>sIII. Software Flowchart:BeginWriteP1 = 38h, Comm<strong>an</strong>d_ByteData=[DPTR]4.1mSec DelayP1 = 38h, Comm<strong>an</strong>d_Byte100uSec DelayInitializati<strong>on</strong>?Data = 99hNoCall Data_ByteYesReturnP1 = 38h, Comm<strong>an</strong>d_ByteP1 = 0ch, Comm<strong>an</strong>d_ByteP1 = 01h, Comm<strong>an</strong>d_ByteINC DPTRCGRAMFirst_LineSec<strong>on</strong>d_Line:Comm<strong>an</strong>d_byteData_byteIDLERS lowRS high*CGRAM: Program in CGRAM DATAFirst_Line: Display First LineSec<strong>on</strong>d_Line: Display Sec<strong>on</strong>d LineRW low - Enable writeDELAYE low - generate enable pulseStart TimerTestFlag = 0Timer0 Interrupt:TestFlag=1Stop TimernopTestFlag=1?NoYesReturnE high - pull up enable signalRW high - Read modeC<strong>on</strong>figure P1 to input portDB7 = 1?YesNoReturn- Page 2 -


Applicati<strong>on</strong> NoteINC.Crystal Clear <strong>an</strong>d Visibly Superior <strong>LCD</strong> <strong>Module</strong>s;**********************************************************;; Applicati<strong>on</strong> Note:; =================; <str<strong>on</strong>g>Displaying</str<strong>on</strong>g> <str<strong>on</strong>g><strong>Character</strong>s</str<strong>on</strong>g> <strong>on</strong> <strong>an</strong> <strong>LCD</strong> <strong>Character</strong> <strong>Module</strong>;; Descripti<strong>on</strong>: Demo software to display “c<strong>an</strong>ned”message <strong>an</strong>d custom characters..; C<strong>on</strong>troller: Phillips 87C751; <strong>LCD</strong> c<strong>on</strong>troller: HD44780, KS0066, SED1278;;*************************************************************; C<strong>on</strong>st<strong>an</strong>t Definiti<strong>on</strong>;*************************************************************EnableT0 equ 082h ;enable timer0Disable equ 000h ;disable timerD4100h equ 00ch ;timer reload high byte def.D4100l equ 003h ;timer reload = 4.1mSec.D100h equ 000h ;timer reloadD100l equ 04ch ;timer reload = 100uSec.;*****************************************; Ram Definiti<strong>on</strong>;*****************************************Flags DATA 020h ;flagTstFlag BIT Flags.0 ;interrupt flag bit;*****************************************; Port C<strong>on</strong>necti<strong>on</strong>s; =================; P1.0 -> D0; P1.1 -> D1; P1.2 -> D2; . . .; P1.7 -> D7; P3.0 -> Enable; P3.1 -> RS; P3.2 -> RW;*******************************************************; Interrupt Vectors; ------------------org 000hjmp PowerUp ; Power up reset vectororg 003hjmp ExInt0 ; External interrupt 0 vectororg 00bhjmp Timer0 ; Counter/ Timer 0 int vectororg 013hjmp ExInt1 ; External int 1 vectororg 01bh ;jmp Timer1 ; Timer 1 int vectororg 023hjmp I2C ; I2C serial int vectororg 50hPowerUp:;***** Timer 0 Interrrupt preparati<strong>on</strong>clr TR ;disable timerclr TF ;clear overflow;**************************************; <strong>LCD</strong> Initializati<strong>on</strong> Routine;**************************************cinit: clr P3.1 ;RS lowclr P3.2 ;RW lowsetb P3.0 ;Enablemov RTL,#D4100l ;set timer reload valuemov RTH,#D4100h ;dealy time = 4.1mSecsd<strong>on</strong>e:mov p1,#38hacall comm<strong>an</strong>d_byteacall ddelay ;initial delay 4.1mSecmov RTL,#D100l ;set timer reload valuemov RTH,#D100h ;dealy time = 100uSecmov p1,#38h ;functi<strong>on</strong> setacall comm<strong>an</strong>d_byteacall ddelay ;busy flag not avail. yetmov p1,#38h ;functi<strong>on</strong> setacall comm<strong>an</strong>d_bytemov p1,#0ch ;display <strong>on</strong>acall comm<strong>an</strong>d_bytemov p1,#01h ;clear displayacall comm<strong>an</strong>d_byteacall cgram ;define custom f<strong>on</strong>tsacall first_line ;display first lineacall sec<strong>on</strong>d_line ;display sec<strong>on</strong>d linesetb IDLE ;power down modejmp sd<strong>on</strong>e;********************************************************;Subroutine: WRITE;=================;Purpose: To feed in data/comm<strong>an</strong>d bytes to the <strong>LCD</strong> 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/comm<strong>an</strong>d byte; while (new data != 99h) {; set port1 with new data; call data_byte; increment data pointer; }; return;********************************************************write:write_loop:mov a,#0movc a,@a+dptrcjne a,#99h,write_c<strong>on</strong>tretwrite_c<strong>on</strong>t:mov p1,aacall data_byteinc dptrjmp write_loop;************************************************; Delay Routine:; Delay peri<strong>on</strong>d = 4/3uSec * DefRth,l;************************************************ddelay:setb TR ;start timermov IE,#EnableT0 ;enable timerclr TstFlag ;reset flagdloop: jnb TstFlag,dloopret;********************************; set address to beginning; of CG RAM;********************************- Page 3 -


Applicati<strong>on</strong> NoteINC.Crystal Clear <strong>an</strong>d Visibly Superior <strong>LCD</strong> <strong>Module</strong>scgram:mov p1,#40hacall comm<strong>an</strong>d_bytemov dptr,#cgram_dataacall writeret;********************************; Set DDRAM to the beginnig of; the first line - 00;********************************first_line:mov p1,#080h ;set DDRAMacall comm<strong>an</strong>d_bytemov dptr,#fline_dataacall writeret;********************************; Set DDRAM to the beginning of; the sec<strong>on</strong>d line - 40;********************************sec<strong>on</strong>d_line:mov p1,#0c0h ;set DDRAMacall comm<strong>an</strong>d_bytemov dptr,#sline_dataacall writeret;**********************************************************; Feed Comm<strong>an</strong>d/Data to the <strong>LCD</strong> module;***********************************************************comm<strong>an</strong>d_byte:clr p3.1 ; RS low for a comm<strong>an</strong>d byte.jmp bdelaydata_byte:setb p3.1 ; RS high for a data byte.nopbdelay:clr p3.2 ; R/w low for a write modeclr p3.0nopsetb p3.0 ;enable pulsenop;******************* Check Busy Flagmov p1,#0ffh ;c<strong>on</strong>figure port1 to input modesetb p3.2 ;set RW to readclr p3.1 ;set RS to comm<strong>an</strong>dclr p3.0 ;generate enable pulsenopsetb p3.0bloop: nopmov a,p1<strong>an</strong>l a,#80h ;check bit#7 busy flagcjne a,#00h,bloop;keep waiting until busy flag clears;*****************************************; check busy flag twice;*****************************************bwait:mov a,p1<strong>an</strong>l a,#80hcjne a,#00h,bloopclr p3.2 ;return to write moderet;******************************************; Interrupt Routines;******************************************ExInt0:ExInt1:Timer1:I2C:reti;**********************************************Timer0:setb TstFlagclr TRmov IE,#Disablereti;********************************************; Data Bytes;*******************************************FLINE_DATA:db ‘>>> HANTRONIX

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!