Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Parallel LCD Not Working?

Status
Not open for further replies.

wuchy143

Member
Hi All,

I"m trying to program Hantronix Inc's LCD(P/N: HDM24216L-2). Their spec isn't very helpfull and this is the first time I've needed to program a parallel LCD. My experience is the serial ones.

From what I've gathered you have 3 control lines. RS, R/W, and E. I want to display a "0" on the screen. So I set RS = "high" because I'm giving the LCD a data input. R/w = 0v because I'm writing data. Last is the E which on it's transition from High to Low the LCD starts to take in the data on it's data ports.(This is the enable pin)

I"m not sure why this isn't working. Does anyone have experience with parallel LCD's and know of some things I may be doing wrong? Or less ideal? I did read in the datasheet that you need to supply power a certain way but I checked that on my scope and I"m withing the allowable range. I"m stumped.....I appreciate the help. My code is below.

Regards,

-mike

Code:
void main() {

  ANSEL  = 0;                                    // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;

  TRISA = 0x00;
  TRISB = 0x00;
  TRISC = 0x00;
  TRISD = 0x00;

  PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;
  PORTD = 0x00;
  PORTA = 0b00110000;
  RB7_bit = 1;
  Delay_ms(500);

   


   RB5_bit = 1;
   RB6_bit = 0;
   Delay_ms(500);
   RB7_bit = 0;
   Delay_ms(500);
  for(;;){}
 
Last edited by a moderator:
I think I am. :) but from the datasheet I found I don't fully understand how to do the initialization so I could be doing it wrong. I"m not sure. I need to look at this more tomm in greater detail.

hmm. here is what I think the initialization should be:

Code:
void wait() {
  Delay_ms(100);
}

void main() {

  ANSEL  = 0;                                    // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;

  TRISA = 0x00;
  TRISB = 0x00;
  TRISC = 0x00;
  TRISD = 0x00;

  PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;
  PORTD = 0x00;
  
  Delay_ms(1000);
  
  RB7_bit = 1;
  Delay_ms(20);
  RB5_bit = 1;
  RB6_bit = 0;
  PORTA = 0b00110000;
  RB7_bit = 0;
  Delay_ms(5);
  
  RB7_bit = 1;
  PORTA = 0b00110000;
  RB7_bit = 0;
  Delay_us(105);
  
  RB7_bit = 1;
  PORTA = 0b00110000;
  RB7_bit = 0;
  
  //Delay_us(105);
  RB7_bit = 1;
  PORTA = 0b00111000;
  RB7_bit = 0;
  
  //Delay_us(105);
  RB7_bit = 1;
  PORTA = 0b00001000;
  RB7_bit = 0;
  
  //Delay_us(105);
  RB7_bit = 1;
  PORTA = 0b00000001;
  RB7_bit = 0;
  
  //Delay_us(105);
  RB7_bit = 1;
  PORTA = 0b00000111;
  RB7_bit = 0;
  //Delay_us(105);
  
  PORTA = 0b00110000;
  RB7_bit = 1;

  Delay_ms(500);

   


   RB5_bit = 1;
   RB6_bit = 0;
   Delay_ms(500);
   RB7_bit = 0;
   Delay_ms(500);
  for(;;){}
}

I'm trying to follow the datasheet but I'm not sure if I'm doing it correct. I'm going to go look this over and see if I can get any further.
 
Last edited by a moderator:
In the sticky section of this forum there is a thread that list most of the good LCD tutorials and work that people have done with them.

EDIT: A suggestion. Use #define in you code to make it more readable.

#define LCD_E RB7_bit

LED_E = 1;
 
Last edited:
It works just like the a hd LCD

Tie read write low power up the LCD wait about 150ns set port data pins for cmd strobe wait not much to it.

Your not writing the data all at the same time Port = cmd strobe delay port = data strobe delay

To put a one on your lcd PORT=0b00110001 strobe delay

A 0 would be LCD PORT=0b00110000 strobe delay

The way his code looks it would happen so fast the LCD would never show a 0 and he not changing to data
 
Last edited:
In the sticky section of this forum there is a thread that list most of the good LCD tutorials and work that people have done with them.

The first tutorial in the sticky has two pdf's. It seems they are corrupted because when I open them on my PC i'm able to read it for 10 seconds or so and then it crashed and shuts down. They look like usefull tutorials. Do you know if they exist anywhere else on the web?
 
Last edited:
Here is my code cleaned up a bit. I put in the defines. All I'm trying to do here is init the LCD and then simply display a "0".

Code:
#define LCD_E RB7_bit
 #define LCD_RW RB6_bit
 #define LCD_RS RB5_bit


void main() {

  ANSEL  = 0;                                    // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;

  TRISA = 0x00;
  TRISB = 0x00;
  TRISC = 0x00;
  TRISD = 0x00;

  PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;
  PORTD = 0x00;
  Delay_ms(1000);

  /**********      INITIALIZATION     ***************************/
  
  LCD_E = 1;
  Delay_ms(20);
  LCD_RS = 1;
  LCD_RW = 0;
  PORTA = 0b00110000;
  LCD_E = 0;
  Delay_ms(5);
  
  LCD_E = 1;
  PORTA = 0b00110000;
  LCD_E = 0;
  Delay_us(105);
  
  LCD_E = 1;
  PORTA = 0b00110000;
  LCD_E = 0;
  
  Delay_us(105);
  LCD_E = 1;
  PORTA = 0b00111000;
  LCD_E = 0;
  
  Delay_us(105);
  LCD_E = 1;
  PORTA = 0b00001000;
  LCD_E = 0;
  
  Delay_us(105);
  LCD_E = 1;
  PORTA = 0b00000001;
  LCD_E = 0;
  
  Delay_us(105);
  LCD_E = 1;
  PORTA = 0b00000111;
  LCD_E = 0;
  Delay_us(105);
  
  /********************   trying to display a "0"*   *************************/
  
  PORTA = 0b00110000;      //
  LCD_E = 1;

  Delay_ms(500);


   


   LCD_RS = 1;
   LCD_RW = 0;
   Delay_ms(500);
   LCD_E = 0;
   Delay_ms(500);
  for(;;){}
}
 
It's still wrong you load the porta then strobe
Code:
'I would use a micro'

micro strobe

     bsf PORT.X
     nop
     nop
     bcf PORT.X
endM


then may code would be a simple send cmd strobe
change for data send data strobe

Your clocking before you load the data pins

Code:
Delay_us(105);
  LCD_E = 1;
  PORTA = 0b00000001;
  LCD_E = 0;

should be like this
Code:
   delay
   PORTA =0b0011000
   strobe
with the with RS low you set the cmd
with the RS high you you set the data

Try this toy out It's cool

But you'll get a quick understanding of how a LCD works
LCD Simulator {/JavaScipt}
 
Thanks Burt. The simulator is very helpfull. I understand how the sim works. But I guess I"m not translating that understanding to my code. I took your advice and added a micro to do the strobing. It makes the code easier to read. I think I fixed when you said

delay
PORTA =0b0011000
strobe

Now it should look more like
delay
PORTA =0b0011000
strobe

Though it's still sitting there dumb as a door nail. hmmm. I must be initializing wrong....
 
Code:
 #define LCD_E RB7_bit
 #define LCD_RW RB6_bit
 #define LCD_RS RB5_bit
 
void MicroStrobe(void);


void main() {

  ANSEL  = 0;                                    // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;

  TRISA = 0x00;
  TRISB = 0x00;
  TRISC = 0x00;
  TRISD = 0x00;

  PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;
  PORTD = 0x00;
  Delay_ms(1000);

  /**********      INITIALIZATION     ***************************/
  LCD_RW = 0;
  LCD_RS = 0;
  PORTA = 0b00110000;
  MicroStrobe();
  Delay_ms(5);


  PORTA = 0b00110000;
  MicroStrobe();
  Delay_us(105);


  PORTA = 0b00110000;
  MicroStrobe();

  Delay_us(105);
  PORTA = 0b00111000;                 //Function Set
  MicroStrobe();

  Delay_us(105);
  PORTA = 0b00001000;                 //Display off
  MicroStrobe();

  Delay_us(105);
  PORTA = 0b00000001;                 //Display Clear
  MicroStrobe();

  Delay_us(105);
  PORTA = 0b00000111;                 //Entry mode set
  MicroStrobe();
  Delay_us(105);
  
  PORTA = 0b00001111;                 //turning display, cursor, and blink ON
  MicroStrobe();
  Delay_us(105);

  /********************   trying to display a "0"*   *************************/

  LCD_RS = 1;                    //Selecting Data Input
  PORTA = 0b00110000;            //Code for a "0"
  MicroStrobe();                 //clock in data


  for(;;){
  LCD_E = 1;                     //turning on LCD_E so I can see that I make it to this point in my code
  }
}

void MicroStrobe(void){
     LCD_E = 1;
     Delay_ms(1);
     LCD_E = 0;
     }
 
What chip you using I don't think you posted it. and do want a sample in asm I'm rusty but I think I could post you a simple code I use Swordfish basic for the 18f chips and h-teck C and pic basic pro for the rest
 
PIC16F887

I'd love a sample in assembly. I'm using Mikroelectronica's mikroC Pro. So anything you have in hi-tech C would be very usefull.
 
Oh forgot to mention. I'm hacking into the dev board which comes with the pickit 2. It makes it easy because I can program and test without touching anything.
 
This is not rocket science but I know it can seem like it.

Check again that you have the right port bits going to the LCD pins you are using in the code. Then check again.

Make darn sure you have the bits you are using set to digital IO.

Do you have a pot hooked to the contrast so you can see the display ? What happens when you adjust the pot.

If you have all the hardware hooked up right an you pick the 4 or 8 bit mode as per how you wired it.... then the rest is just book work. Turn the right bits on and off at the right time.

The examples in the sticky and the nice simulator Burt provided should be enough for you to understand the process.

@Burt... They are called MACROS.
 
3v0 I no what there called @Burt... They are called MACROS
it was late and I was thinking faster then I can type micros lol It's MACROS

Any way this should light up a 18F chip but

Code:
;   Oscillator Selection:
    CONFIG	FOSC = XT_XT         ;XT oscillator, XT used by USB
	
	CBLOCK	0x000
	d1
	d2
	d01
		ENDC
		
;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

		ORG	0x0000

		goto	Main		;go to start of main code
	strobe macro	;strobes the E pin
		BSF PORTA,2
		NOP
		NOP
		NOP
		NOP
		BCF PORTA,2
	endm
	cmd macro      	;SetsRS high for cmd
	 	BSF PORTA,3
		nop
		nop
	endm
	cmd_end macro   ; SetsRS low for data
		BCF PORTA,3  
		NOP
		NOP
	endm

	

Main:
	CLRF LATA 		; Alternate method
					; to clear output
					; data latches
	MOVLW 0Fh 		; Configure A/D
	MOVWF ADCON1	; for digital inputs
	MOVLW 07h 		; Configure comparators
	MOVWF CMCON 	; for digital input
	MOVLW 0x00 		; Value used to
					; initialize data
					; direction
	MOVWF TRISA 	; all as outputs
					

	CLRF LATB 		; Alternate method
					; to clear output
					; data latches
	MOVLW 0Eh 		; Set RB<4:0> as
	MOVWF ADCON1 	; digital I/O pins
					; (required if config bit
					; PBADEN is set)
	MOVLW 0x00 		; Value used to
					; initialize data
					; direction
	MOVWF TRISB 	; Set all to output
    GOTO LCD_Start
					
LCD_Start:               ;startup your LCD and make it blink 
	call ST_Delay
	cmd                ; sets LCD for for command
	MOVLW b'00001111'  ;loads cmd data
	MOVWF PORTB        ;puts it out on the data port
	strobe                   ; tells the LCD come and get the command data
	call DATCMDelay
	cmd_end              ;Sets to send data 
	MOVLW b'0011000'  ;puts it out on the data port
	MOVWF PORTB      
	strobe                  ; tells the LCD come and get the command data
	GOTO Wait
Wait:				;hang out here so you can see the LCD print a 0
	GOTO Wait
DATCMDelay
			;496 cycles
	movlw	0xA5
	movwf	d01
DATCMD_0
	decfsz	d01, f
	goto	DATCMD_0

			;4 cycles (including call)
	return

	
ST_Delay
			;4993 cycles
	movlw	0xE6
	movwf	d1
	movlw	0x04
	movwf	d2
ST_Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	ST_Delay_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return


	end
 
I was thinking it was cute.

Let me tale you some thing cute LOL I hooked the LCD up for 4 bit not 8 bit think it would work NOT LOL
gone crazy

I'm setting here with my head up my AZZZZZZZZZZZZZZZZ LOL

write code for 8 bit LCD test on 4 bit LCD then get mad delete code and pick LCD up and flip it over

dang I even made that board just for LCD I new it was 4 bit what am I thinking
 
Last edited:
Well I wrote basically the same code in SwordfishBasic and it works give me a few hours and I'll post you something for 16f887 in asm that will work.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top