Newsgroups: comp.robotics
Path: brunix!sgiblab!swrinde!cs.utexas.edu!howland.reston.ans.net!vixen.cso.uiuc.edu!newsrelay.iastate.edu!destroyer!nntp.cs.ubc.ca!newsserver.sfu.ca!sfu.ca!jnicol
From: jnicol@malibu.sfu.ca (Jordan James Nicol)
Subject: Help needed with LCD module
Message-ID: <jnicol.761256069@sfu.ca>
Summary: I can't interface 6811 to LM16155 LCD w/ 4-bit operation.
Keywords: LCD, LM16155,HD44780
Sender: news@sfu.ca (seymour news)
Organization: Simon Fraser University, Burnaby, B.C., Canada
Date: Mon, 14 Feb 1994 20:01:09 GMT
Lines: 146

Hi, 

I'm trying to interface a Sharp LM16155 LCD module to  a 68HC11
on  a Miniboard and I'm not having much luck. Has anyone used one of
these in the 4-bit mode of operation? The module uses a Hitachi
HD44780 LCD Controller. I've got the specs/instructions for this
device from the data manual but I can't find what I'm doing wrong.


Just to prove that I can get it work I have written a simple assembly
program which has been inserted into a C source code file. This
program, to the best of my knowledge, exactly follows the step-by-step
instructions for a 4-bit operation example given on p. 162 of Hitachi
LCD Controller/Driver LSI Data Book. The end result should be the
appearnce of the cursor in position 0. However, I can't get anything
to appear on the screen. (BTW, the creen is getting power--sometimes
when the RS232 cable is connected to the MB I get some strange
characters momentarily appaering on the screen.)

What follows is some assumptions I've made (based on the data book)
about 4-bit operation. After that I've include the program I've been
using. I would greatly appreciate if those people who are familiar
with this device would check my assumptions. If you would look at my
code that would be a bonus :-)

Assumptions:
1) The Enable bit must be high before and during an instruction/data
write. I figure that setting this bit high in the previous assembly
instruction is adequate set-up time.
2) The R/W bit can stay low since I'm only performing writes and not
checking the Busy flag. Instead, I wait more than 50us between
successive instructions to allow the LCD controller time to process.
The exception is when a Clear Display or Return Home instruction is
issued-then I wait 2ms.
3) The 50us time is only necessary between instructions and not
between two successive nibbles of a single instruction.
4) The RS bit need only go high when writing data to CG or DD RAM as
opposed to writing instructions.
5) The data need only be valid for duration of a single assembly
instruction since tDSW = 195ns < typical assembly instruction @ fc =
8MHz.

Well, here is the code. PortC of the 6811 (which has been designated
as an output port) is connected to the LCD module with the following
pin assignments:

	PC7	DB7
	PC6	DB6
	PC5	DB5
	PC4	DB4
	PC3	nc
	PC2	RS
	PC1	R/W
	PC0	E


Thanks a lot for any forthcoming help or suggestions! If and when I
get this thing working I've got some nifty(IMHO) LCD routines that I
will make available to anyone interested. 


Cheers,

Jordan Nicol
jnicol@sfu.ca
School of Kinesiology
Simon Fraser University


/*_____________________________________________________________________*/
/* LCD TEST#1                                                 Feb 3/94 */
/* LCD outputs thru PORTA, Reads switch info from PA0                  */


/* Display2.c : Program to develop LCD display routines       Dec9/93 */
/* Now includes Initialize routines                          Dec10/93 */
/* When PORTA(1) is logic 1, then "ON" is displayed on LCD, otherwise */
/* "OFF" is displayed.                                                */
/* Source debugged with Turbo C++                           Dec 10/93 */

#include extern.h  
/* unsigned char PORTC,PORTA; */


main()
{
	  unsigned char instruction,ONalready,OFFalready, Prt_A;

	PORTC = 0;

	asm{
	LDX #$1000
	BSET $1007,X,$FF             Set PortC as output
LCD     BSET $1003,X,%00000001       Enable high
	BSET $1003,X,%00100001       Set LCD to 4-bit operation
	BRA DELAY1                   Wait approx. .5ms
C1       CLR $1003,X                 Clear PortC

*       Here we begin 4-bit operation. Sets 4-bit operation and selects 
*       1-line display and 5 by 7 dot character font.
	BSET $1003,X,%00000001       Enable high
	BSET $1003,X,%00100001       Send MS nibble
	CLR $1003,X                  Clear PortC
	BSET $1003,X,%00000001       Enable high
	BSET $1003,X,%00000001       Send LS nibble
	BRA DELAY2                   Wait .5 ms
C2       CLR $1003,X                 Clear PortC
*       Turns on display and cursor. Sent in two nibbles.
	BSET $1003,X,%00000001       Enable high
	BSET $1003,X,%00000001       Send MS nibble
	CLR $1003,X                  Clear PortC
	BSET $1003,X,%00000001       Enable high
	BSET $1003,X,%11100001       Send LS nibble
	BRA END                      Goto end of assembly code
DELAY1  CLR $1004,X        
L1      INC $1004,X
	BNE L1
	BRA C1
DELAY2  CLR $1004,X        
L2      INC $1004,X
	BNE L2
	BRA C2
END     NOP                          Now resume with c code
	}


	/* Initialize variables */
	PORTC = 0;    
	PORTA = 0;
	ONalready = false;
	OFFalready = false;
	motor(3,16);
	msleep(500);
	off(3);      
	while(1)                 /* stop here and loop  4-ever */
	{
	PORTA = 0;
	}



	}    /** end of infinite while loop  **/
}           /** end of main  **/
	 


