Discussion in "PIC Microcontroller Discussion" started by    arp    Dec 27, 2007.
Thu Dec 27 2007, 03:52 pm
#1
Dear Sir,

I am using 16x2 lcd module (HY-1602F6 printed on LCD MODULE PCB) with PIC16F876A.I am using PORTB.My connection is as follows:
EN -> RB3
RS -> RB2
R/W - > gnd(i want only write operation)

DB7......DB4(LCD data pin 11 to 14) -> PB7...PB4
Other LCD pins are as usual.
Crystal : 20MHz

After executing lcd routine :

My lcd display is not what i wanted to.I have seen only block of black characters.

Same lcd code(with little change i.e sending data with lower port bits) i have tested for other board where control lines were(RS,EN) from PORTA and DATA LINES were RD3...RD0. and crystal 4MHz And it's working perfectly OK.

I have attached the lcd code for review.Pls can anybody give me solution to this issue??
init_LCD() -> lcd initialization routine
putch() -> writting one char on lcd.this calls another routine called
lcd_write()
attached file in zip - init.txt and lcd.txt

pls Note : for 4MHz crystal LCD_CONTROL() code excludes those 4 lines of asm("nop").

rgds,

Arup

Attachment
Thu Dec 27 2007, 04:37 pm
#2
you are getting blocks of black color means.. LCD is not initialized.
check init_LCD routine..
the for loop execute the whole thing 3 times..
which is wrong..
the init sequence is..
first reset - 30H
second reset - 30H
third reset - 30H
set data width - 20H
--
then ur usual commands..
please take a look at the 4-bit LCD tutorial in tutorial section..

here is change needed in your code..


void init_LCD(void){
#if 1
   U08 temploopcnt,i;
    
	LCD_RS = 0;
	LCD_EN = 0;

	DelayMs(10);	// wait 10mSec after power applied,
	LCD_DATA = ((LCD_DATA & 0x0F) | 0x30);
	LCD_CONTROL();
	DelayMs(5); 
	LCD_CONTROL();
	DelayUs(200); 
	LCD_CONTROL();
	DelayUs(200); 
	LCD_DATA = ((LCD_DATA & 0x0F) | 0x20);
	LCD_CONTROL();
	DelayUs(200); 

	lcd_write(0x28); // Set interface length
	lcd_write(0x0C); // Display On, Cursor On
	lcd_clear();	// Clear screen
	lcd_write(0x6); // Set entry Mode

        DelayUs(140);
#endif
}


if you still getting black boxes. then increase the delay in init routine.. and in lcd_write routine..
Fri Dec 28 2007, 10:13 am
#3
dear Mr. Ajay,

yes , i did that too in initialize ..i.e
30H .then Control signal delay 10 ms
30H .then Control signal delay 5 ms
30H .then Control signal delay 1 ms
20H .then Control signal delay 200 us
My initialization is like that..............
void init_LCD(void){

for(i=0;i<1;i++){

DelayMs(15); // wait 15mSec
LCD_DATA = ((LCD_DATA & 0x0F) | 0x30);
LCD_CONTROL();
DelayMs(10); // 10ms delay
LCD_DATA = ((LCD_DATA & 0x0F) | 0x30);
LCD_CONTROL();
DelayMs(5); // 20ms delay
LCD_DATA = ((LCD_DATA & 0x0F) | 0x30);
LCD_CONTROL();
DelayMs(2);
LCD_DATA = ((LCD_DATA & 0x0F) | 0x20);
LCD_CONTROL();
DelayUs(200);
}
}
still display in same condition.
In the display module pcb "HY-1602F6" is printed. If this is the module no then do you have doc. of that.
Right now I am considering LCD connection as follows:
pin 1 : GND
pin2 : +5V
pin3 : Contrast voltage (thro' POT)
pin4 : RS
pin5 : R/W -> GND
pin6 : EN
pin7 : NC
pin8 : NC
pin9 : NC
pin10: NC
pin11: DB4
pin12: DB5
pin13: DB6
pin14: DB7
pin15: +5V
pin16 : GND


regards,
arup



Fri Dec 28 2007, 01:09 pm
#4
most of the char based LCDs are based on HD44780 controller.. the only change is the working frequency of controller.
Try to increase the delay in every place.. the only problem in software reset is the time delay... also your clock frequency is too hight.. so better try increasing the delay will surely work.
Sat Dec 29 2007, 12:53 pm
#5
Dear Mr. Ajay ,

The issue is solved now.I was downloading the hex file thru MPLAB ICD2 programmer in low voltage mode.So RB3 is not usable as general purpose I/O.But I used RB3 as EN signal in my code.
Issue is solved like this -> Now i hv downloaded the hex file in high voltage mode. the problem vanished!!!!
The code is same what i have attached in my first post.


Thanks,
Arup
Sat Dec 29 2007, 01:26 pm
#6
you're welcome...
also thank you for bringing a nice issue of low voltage programming.. i was not aware of this...
Wed Dec 24 2008, 11:57 am
#7
Dear ARP,
I too is suffering from the same problem and not able to have the text tah t wan on display .
I am using the same same all as urs will u plz help me.i have attach my code...
Wed Dec 24 2008, 12:15 pm
#8


most of the char based LCDs are based on HD44780 controller.. the only change is the working frequency of controller.
Try to increase the delay in every place.. the only problem in software reset is the time delay... also your clock frequency is too hight.. so better try increasing the delay will surely work.

Ajay


mR aJAY,
PROBLEM IS THAT I AM NEW TO THIS SITE SO NNOT KNOWN WHR TO POST AND HOW.....NOW COMES THE PROBLEM AS I MENTIONED I AM SUFFERING FROM THE SAME PROBLEM AS OF arp I HAV FORWARDE THE CODE TO BOTH OF U WILL U PLZ HAVE HELPING HAND
Thu Dec 25 2008, 02:56 am
#9
ali, here is your program..
Problem is in LCD reset routine, you are calling LCD_CMD routine after sending data on lcd port.
rather during software reset you just need to send pulse on enable pin. take a look at lcd tutorial and check the reset routine.

;LCD text demo - 4 bit mode
;Nigel Goodwin 2002

			LIST		P = 16F886				;tell assembler what chip we are using
			#INCLUDE 	"P16F886.INC"			;include the defaults for the chip
			ERRORLEVEL	-302,	-305,	-205	;suppress bank selection messages

;__config 	0x3D18			;sets the configuration settings (oscillator type etc.)
CBLOCK		0x20			;start of general purpose registers
			COUNT			;used in looping routines
			COUNT1			;used in delay routine
			COUNTA			;used in delay routine
			COUNTB			;used in delay routine
			COUNTC			;used in delay routine
			TMP1			;temporary storage
			TMP2
			TEMPLCD			;temp store for 4 bit mode
ENDC

LCD_PORT	EQU		PORTC
LCD_TRIS	EQU		TRISC

#DEFINE		LCD_RS	PORTB, 2		;LCD handshake lines
#DEFINE		LCD_RW	PORTB, 1
#DEFINE		LCD_E	PORTB, 0
#DEFINE		CARRY   STATUS, C
#DEFINE		ZERO    STATUS, Z

			ORG		0000H
INITIALISE
            banksel	PORTA
			CLRF	COUNT
			CLRF	PORTA
			CLRF	PORTB
			CLRF	PORTC
SETPORTS
			banksel	PORTA			;select bank 0
			CALL	DELAY100		;wait for LCD to settle
			CALL	DELAY100
			NOP
			CALL	LCD_INIT		;setup LCD
			NOP
			banksel	TRISA			;select bank 1
			MOVLW	H'00'			;make all pins outputs
			MOVWF	LCD_TRIS
            MOVLW	H'07'
 			MOVWF	TRISB
			CALL	LCD_LINE1		;move to 1ST row, first column
			CLRF	COUNT			;set counter register to zero
MESSAGE
			MOVF	COUNT, W		;put counter value in W
			CALL    TEXT			;get a character from the text table
			XORLW	H'00'			;is it a zero?
			BTFSC	ZERO
			GOTO    NEXTMESSAGE
			CALL    LCD_CHAR
			CALL	DELAY100
			INCF	COUNT, F
			GOTO    MESSAGE
NEXTMESSAGE	
			CALL	LCD_LINE2		;move to 2nd row, first column
			CLRF	COUNT			;set counter register to zero
MESSAGE2
			MOVF	COUNT, W		;put counter value in W
			CALL	TEXT2			;get a character from the text table
			XORLW	H'00'			;is it a zero?
			BTFSC	ZERO
			GOTO	ENDMESSAGE
			CALL	LCD_CHAR
			INCF	COUNT, F
			GOTO 	MESSAGE2
ENDMESSAGE	
		
STOP		GOTO	STOP			;endless loop

;Subroutines and text tables
;LCD routines
;Initialise LCD		
LCD_INIT
			NOP
			CALL    LCD_RESET
			MOVLW	H'20'			;Set 4 bit mode
			CALL	LCD_CMD
			MOVLW	H'28'			;Set display shift'
			CALL	LCD_CMD
			MOVLW	H'0C'			;Set display on/off and cursor command
			CALL	LCD_CMD
			NOP
			CALL	LCD_CLR			;clear display
			MOVLW	H'06'
			CALL	LCD_CMD			;Set entry mode
			MOVLW	H'80'			;Set display character mode
			CALL	LCD_CMD
			MOVLW	H'02'			;Set cursor to home
			CALL	LCD_CMD
			NOP
			RETLW	H'00'
LCD_RESET
			banksel TRISB
            MOVLW	H'00'
 			MOVWF	TRISB
			MOVLW	H'0E'
			MOVWF	ADCON1
			MOVLW	H'FF'
  ;			MOVWF	LCD_PORT
			CALL	LCD_CMD
			CALL	PULSE_E			;Pulse the E line high
			CALL	DELAY100

			MOVLW	H'38'
;			MOVWF	LCD_PORT	
			CALL	LCD_CMD
			MOVLW	H'30'
;  			MOVWF	LCD_PORT
			CALL	LCD_CMD
			CALL	PULSE_E			;Pulse the E line high
			CALL	DELAY100
			NOP
			MOVLW	H'30'
;  			MOVWF	LCD_PORT
			CALL	LCD_CMD
			CALL	PULSE_E			;Pulse the E line high
			CALL	DELAY100
			NOP
			MOVLW	H'30'
;  			MOVWF	LCD_PORT
			CALL	LCD_CMD
			CALL	PULSE_E			;Pulse the E line high
			CALL	DELAY100
			NOP
;			MOVLW	H'83'
;			MOVWF	LCD_PORT	
			MOVLW	H'02'
;  			MOVWF	LCD_PORT
			CALL	LCD_CMD
			CALL	DELAY50
			RETLW	H'00'
; command set routine
LCD_CMD	
            banksel	PORTA
			MOVWF	TEMPLCD
			SWAPF	TEMPLCD, W		;send upper nibble
			ANDLW 	H'0F'			;clear upper 4 bits of W
			MOVWF	LCD_PORT
			BCF		LCD_RS			;RS line to 0
			CALL	PULSE_E			;Pulse the E line high
			MOVF	TEMPLCD, W		;send lower nibble
			ANDLW	H'0F'			;clear upper 4 bits of W
			MOVWF	LCD_PORT
			BCF		LCD_RS			;RS line to 0
			CALL	PULSE_E			;Pulse the E line high
			CALL 	DELAY50
			RETLW	H'00'

LCD_CHARD	
			ADDLW	H'30'
LCD_CHAR
            banksel	PORTA
			MOVWF	TEMPLCD
			SWAPF	TEMPLCD, W		;send upper nibble
			ANDLW	H'0F'			;clear upper 4 bits of W
			MOVWF	LCD_PORT
			BSF		LCD_RS			;RS line to 1
			CALL	PULSE_E			;Pulse the E line high
			MOVF	TEMPLCD, W		;send lower nibble
			ANDLW	H'0F'			;clear upper 4 bits of W
			MOVWF	LCD_PORT
			BSF		LCD_RS			;RS line to 1
			CALL	PULSE_E			;Pulse the E line high
			CALL 	DELAY50
			RETLW	H'00'
LCD_LINE1
			MOVLW	H'80'			;move to 1st row, first column
			CALL	LCD_CMD
			RETLW	0x00
LCD_LINE2
			MOVLW	H'C0'			;move to 2nd row, first column
			CALL	LCD_CMD
			RETLW	H'00'
LCD_CURON
			MOVLW	H'0D'			;Set display on/off and cursor command
			CALL	LCD_CMD
			RETLW	H'00'
LCD_CUROFF	
			MOVLW	H'0C'			;Set display on/off and cursor command
			CALL	LCD_CMD
			RETLW	H'00'
LCD_CLR	
			MOVLW	H'01'			;Clear display
			CALL	LCD_CMD
			RETLW	H'00'
DELAY255
			MOVLW	H'FF'		;delay 255 mS
			GOTO	D0
DELAY100
			MOVLW	D'100'		;delay 100 mS
			GOTO	D0
DELAY50	
			MOVLW	D'100'		;delay 50 mS
			GOTO	D0
DELAY20			
			MOVLW	D'100'		;delay 20 mS
			GOTO	D0
DELAY5	
			MOVLW	H'10'		;delay 5 ms (4 MHz clock)
D0		
			MOVWF	COUNT1
D1			
			MOVLW	H'C7'		;delay 1mS
			MOVWF	COUNTA
			MOVLW	H'01'
			MOVWF	COUNTB
DELAY_0
			DECFSZ	COUNTA, F
			GOTO	$+2
			DECFSZ	COUNTB, F
			GOTO  	DELAY_0
			DECFSZ	COUNT1, F
			GOTO 	D1
			RETLW	H'00'
PULSE_E
			BSF		LCD_E
			NOP
			BCF		LCD_E
			RETLW	H'00'
;end of LCD routines
TEXT
			ADDWF	PCL, f
			RETLW	'H'
			RETLW	'e'
			RETLW	'l'
			RETLW	'l'
			RETLW	'o'
			RETLW	H'00'
TEXT2
			ADDWF   PCL, f
            RETLW   'R'
            RETLW   'e'
            RETLW   'a'
            RETLW   'd'
            RETLW   'y'
            RETLW   '.'
            RETLW   '.'
            RETLW   '.'
            RETLW   H'00'
LCD_HEX
			MOVWF	TMP1
			SWAPF	TMP1, W
			ANDLW	H'0F'
			CALL	HEX_TABLE
			CALL	LCD_CHAR
			MOVF	TMP1, W
			ANDLW	H'0F'
			CALL	HEX_TABLE
			CALL	LCD_CHAR
			RETLW	H'00'
HEX_TABLE
		  	ADDWF   PCL, f
           	RETLW   H'30'
           	RETLW   H'31'
           	RETLW   H'32'
           	RETLW   H'33'
          	RETLW   H'34'
           	RETLW   H'35'
           	RETLW   H'36'
           	RETLW   H'37'
           	RETLW   H'38'
           	RETLW   H'39'
           	RETLW   H'41'
           	RETLW   H'42'
           	RETLW   H'43'
           	RETLW   H'44'
           	RETLW   H'45'
           	RETLW   H'46'
END      
Tue Jan 06 2009, 10:23 am
#10
may i have the code from ajay or arp who have solved the prolem as i have that will definetly help me in solving my problem May i receive that code on my personnel mail id [email protected] arp frwd that code it will help me to iniatialised my lcd in given time

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am