Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help needed regarding 2x16 JHD162A LCD and PIC16f877 code

Status
Not open for further replies.

karthi27

Newbie level 5
Joined
Aug 23, 2009
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Gurgoan
Activity points
1,351
Hi 
I've been working with PIC16F877 and 2x16 JHD162A LCD module for the past 3 days. No success yet.
All that i get is black boxes in row one. And after sometime a portion of black boxes in row 2 is displayed and nothing else happens.

I monitored my EN bit, RS bit, RW bit and busy bit(DB7) with leds. Even the data bus. They are working fine. The PIC controller and ICD2 programmer are fine.

I suspect a bug in my program. Please help me identify the bug. Guess its in the initializing routine. Tried with various delay values. No success.

Code:
[b]//Contents of LCDtest.c code:[/b]
#include <16f877.h>
#USE delay(clock=4000000)     //SETTING CLOCK FREQUENCY 
#FUSES XT,NOWDT,NOBROWNOUT,NOPROTECT,NOPUT  //SETTING FUSES
#BYTE porta=5           //LOCATION OF REGISTER PORT A 
#BYTE portb=6           //LOCATION OF REGISTER PORT B 
#BYTE portc=7           //LOCATION OF REGISTER PORT C 

#define LCD_PORT portb
#bit RS=portc.0
#bit EN=portc.1
#bit RW=portc.2
#bit busy=portc.3

[b]//=========Declarations============[/b]
void lcd_init(void);               
void write_in(unsigned char inst);      
void write_data(unsigned char data);   

[u]//Program Code to display alphabet A:[/u]
void main()
{
set_tris_b(0b00000000); set_tris_c(0b00010000); 
portb=0x00; portc=0x00;
RS=0; EN=0; RW=0;
delay_ms(1000);

lcd_init();
write_data(0b01000001); //character A

while(1){}
}

[b]//LCD Routines[/b]
void lcd_init(void)		[b]//Routine to initialise the lcd[/b]
{
	write_in(0b00000001); //clear display screen  			0x01
	write_in(0b00111000); //function set 2 lines and 5x7 matrix  	0x38
 	write_in(0b00001111); //display on, cursor on and blinking  	0x0f
      	write_in(0b00000110); //cursor move right, display shift disable  	0x06
    	write_in(0b10000000); //Force cursor to beginning to 1st line  	0x80
}

void write_in(unsigned char inst) 	[b]//Routine to write an instruction to LCD[/b]
{
   	RW=0; EN = 0; RS = 0;    //RS =0 for instruction mode  
   	LCD_PORT = inst;         
      	EN = 1;  delay_ms(20);
  	EN = 0;  delay_ms(20);
}

void write_data(unsigned char data)	[b]//Routine to write a data to LCD[/b]
{
     	RW=0; EN = 0; RS = 1;    //RS =1 for data mode  
   	LCD_PORT = data;         
      	EN = 1;   delay_ms(20);
  	EN = 0;   delay_ms(20);
}

[b]//=============PIC6F877 PIN ASSIGNMENT============[/b]
/*    PIN 		DES 	         FUNC 	PIN 		Des		FUNC
	;1 		MCLR 	Reset		40 		RB7 		DB7
	;2 		RA0 				39 		RB6 		DB6
	;3 		RA1 				38 		RB5 		DB5
	;4 		RA2 				37 		RB4 		DB4
	;5 		RA3 				36 		RB3 		DB3
	;6 		RA4 				35 		RB2 		DB2
	;7 		RA5 				34 		RB1 		DB1
	;8 		RE0 				33 		RB0 		DB0
	;9 		RE1 				32 		VDD 		5V
	;10 		RE2 				31 		VSS 		GND
	;11 		VDD 		5V		30 		RD7 	
	;12 		VSS 		GND		29 		RD6 	
	;13 		OSC1 	4MHz		28 		RD5 
	;14 		OSC2 	4MHz		27 		RD4
	;15 		RC0 		RS		26 		RC7
	;16 		RC1 		EN		25 		RC6
	;17 		RC2 		RW		24 		RC5
	;18 		RC3 		BUSY(led)	23 		RC4
	;19 		RD0 				22 		RD3
	;20 		RD1 				21 		RD2
*/
/*
[b]Code (Hex) 	Command to LCD Instruction Register[/b]
	80 		Force cursor to beginning to 1st line
	C0 		Force cursor to beginning to 2nd line
	38 		2 lines and 5x7 matrix
	1C 		Shift the entire display to the right
	18 		Shift the entire display to the left
	14 		Shift cursor position to right
	10 		Shift cursor position to left
	F 		Display on, cursor blinking
	E 		Display on, cursor blinking
	C 		Display on, cursor off
	A 		Display off, cursor on
	8 		Display off, cursor off
	7 		Shift display left
	5 		Shift display right
	6 		Increment cursor (shift cursor to right)
	4 		Decrement cursor (shift cursor to left)
	2 		Return home
	1 		Clear display screen
*/
 

Re: Help needed regarding 2x16 JHD162A LCD and PIC16f877 cod

Use the following code

Code:
#include<16f877a.h>

#USE delay(clock=4000000) //SETTING CLOCK FREQUENCY 
#FUSES XT,NOWDT,NOBROWNOUT,NOPROTECT,NOPUT //SETTING FUSES 

#include<lcd.c>

void main()
{
     
     delay_ms(100);
     lcd_init();
     delay_ms(100);
  
     printf(lcd_putc,"\fHello");
     while(1);

}

connection
//// #define LCD_ENABLE_PIN PIN_B0 ////
//// #define LCD_RS_PIN PIN_B1 ////
//// #define LCD_RW_PIN PIN_B2 ////
//// #define LCD_DATA4 PIN_B4 ////
//// #define LCD_DATA5 PIN_B5 ////
//// #define LCD_DATA6 PIN_B6 ////
//// #define LCD_DATA7 PIN_B7


There is no need to use 8 bit interfacing use 4 bit interfacing...
 

Re: Help needed regarding 2x16 JHD162A LCD and PIC16f877 cod

Hi karthi27,

Is the following statement doing what you expected:

"write_in(0b00001000); //Force cursor to beginning to 1st line 0x80"

0x80 == 0b10000000
 

Re: Help needed regarding 2x16 JHD162A LCD and PIC16f877 cod

matbob said:
Hi karthi27,

Is the following statement doing what you expected:

"write_in(0b00001000); //Force cursor to beginning to 1st line 0x80"

0x80 == 0b10000000

I changed it... but still no change in display...

I even added these lines in the main function
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

but this change didn't bring any change in the display...

Added after 4 minutes:

anandpv2009 said:
Use the following code

Code:
#include<16f877a.h>

#USE delay(clock=4000000) //SETTING CLOCK FREQUENCY 
#FUSES XT,NOWDT,NOBROWNOUT,NOPROTECT,NOPUT //SETTING FUSES 

#include<lcd.c>

void main()
{
     
     delay_ms(100);
     lcd_init();
     delay_ms(100);
  
     printf(lcd_putc,"\fHello");
     while(1);

}

connection
//// #define LCD_ENABLE_PIN PIN_B0 ////
//// #define LCD_RS_PIN PIN_B1 ////
//// #define LCD_RW_PIN PIN_B2 ////
//// #define LCD_DATA4 PIN_B4 ////
//// #define LCD_DATA5 PIN_B5 ////
//// #define LCD_DATA6 PIN_B6 ////
//// #define LCD_DATA7 PIN_B7


There is no need to use 8 bit interfacing use 4 bit interfacing...

I don't want to use LCD.c... already tried it and also flex_lcd.c from edaboard.
It doesn't work.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top