Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
8051 3 wire lcd

8051 3 wire lcd

Ratings: (0)|Views: 24|Likes:
Published by mpkkbtech

More info:

Published by: mpkkbtech on May 20, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less





3-Wire LCD Interface For 8051 SystemsSubmitted by: Vidyasagaran P. (v_sagar_p@yahoo.com) ; ------------- READS51 generated header --------------; module : C:\Rigel\Reads51\Work\LCD\LCD.asm; created : 20:34:08, Thursday, August 15, 2002; author : Vidyasagaran P. (v_sagar_p@yahoo.com); This file contains all the routines needed to manipulate the LCD display; Please note that these routines are hardware wiring specific and will need; changes if the wiring changes. You may have to adjust the delay (DLY_IDX) depending on; the processor speed.; +-------+ +---------------+; P0.0+-------------------------------------->+E LCD ; +----------+ ; P0.1+-------------->+CLK D5+----------->+RS R/W+---+; P0.2+-------------->+INPUT D0-4+--------\-->+D4-D7 ; +--\-->+D0-D3 - Gnd; +-------+ +----------+ +---------------+; 8051 74HC164 -Gnd LCD display; How data is loaded into the LCD;; 1. clock the upper nibble in and use E bit to latch the higher 4 bits; 2. clock the lower nibble in similarly; -----------------------------------------------------;; The following definitions are as per the ABOVE hardware wiring.; It assumes 3 port pins used for display functions. First one directly connected to LCD; E (enable) bit and reset two are connected to an 8 bit output shift register as below.#include <sfr51.inc>;----------------------- PORTING Changes to be done in the following ---------#define LCD_PORT P3 ;Port used for LCD interface#define BASE 000 ;where the code this located#define DLY_IDX 2FH ;depends on speed of processor#define EBIT LCD_PORT.0 ;LCD Ebit pin#define S2P_CLK LCD_PORT.1 ;Serial to parallel convertor 74HC164 clock pin#define S2P_IN LCD_PORT.2 ;Serial to parallel convertor 74HC164 serial inputCodeSeg segment codePublic _Init_LCDPublic _display_string rseg Codesegorg BASE _Init_LCD:clr EBIT ;reset the LCD E bit used. Other pins need not be cleared.
acall init_lcdmov DPTR,#Init_msgacall _display_stringret;-----------------------------------------------------------;clear_home_cursor - put the cursor back to first charclear_home_cursor:;clear displayclr cmov acc,#00000001bacall _write_char;home cursorclr cmov acc,#00000010bacall _write_charret;-----------------------------------------------------------;_display_string is a function which assumes the address of the string;to be passed in DPTR, in the code memory. Strin must have a NULL at the end. _display_string:mov acc,r1 ;save R1push accmov acc,r0 ;save R0, as this is destroyed in _write_charpush accacall clear_home_cursormov r1,#0 ;index count for next characterdisplay_string_loop:mov a,r1 ;move index count to accumulatormovc a,@a+DPTR ;next char to gojz display_string_out ;is it a null?setb c ;if not null set carry to write characall _write_char ;call write_char functioninc r1 ;next char to gosjmp display_string_loop ;repeat till all chars are donedisplay_string_out:pop acc ;restore R0 as write_char destroys thismov r0,accpop acc ;restore R1mov r1,accret;-----------------------------------------------------------;A character is passed in to this routine in accumulator;this routine assumes the following wiring from uP to the LCD.;R0 is destroyed. But exported functions "display_string" saves this,;(a precausion which is optimised also!) _write_char:mov ov,c ;store state of c for second nibble writemov r0,#5 ;we need to shift these many timessetb ac ;this indicates second nibble needs to be written yetwrite_char_loop:mov S2P_IN,c ;serial input bitclr S2P_CLK ;clock once
setb S2P_CLKrlc a ;get c flag set as per data bits from next timedjnz r0,write_char_loop;make the LCD latch the valuesetb EBIT ;pulse Ebit for one time for the first nibbleclr EBITjnb ac,write_char_overclr ac ;get out after the second nibble writtenrrc a ;remove that extra rotationmov c,ov ;restore the original carry to write second nibblemov r0,#5 ;we need to write these many timessjmp write_char_loopwrite_char_over:jb ov,write_char_nodelay ;for command writes delay is needed, notfor chars!acall big_dlywrite_char_nodelay:ret;----------------------------------------------------------;write_one_nibble : writes one Most significant nibble in a passed char;to the LCD. Caller should set the C to indicate write to LCD command;Assumes left roation of bits and hence wiring of data bits from Latch;to be accordingly;contents of R0 is destroyedwrite_one_nibble:mov r0,#5 ;we need to write these many timeswrite_one_nibble_loop:mov S2P_IN,c ;serial input bitclr S2P_CLK ;clock oncesetb S2P_CLKrlc a ;get c flag set as per data bits from second timedjnz r0,write_one_nibble_loop;make the LCD latch the valuesetb EBIT ;pulse Ebit for one time for the first nibbleclr EBITacall big_dlyret;----------------------------------------------------------;a big delay for the LCD to settle after each init stuff. Some places this;delay seems to be very critical. I have put more since it doesn't take much;time and also since it is only one time init.big_dly:mov r0,#DLY_IDXodly:mov acc,#FFHdly:djnz acc,dly ;Simulater virtually hangs here. So comment thisduring simulationdjnz r0,odlyret

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->