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.

LCD With microcontroller.....

Status
Not open for further replies.

koolguy

Active Member
Hi,

I have JHD 162A LCD and i want to know the steps for using it with 877a..
i have seen many tutorial but i am not getting that what steps to follow i.e. initialization properly then writer ascii code to display need your help for starting it....

thanks
______
 
It's all in the tutorials....

Initialize the screen with..

Function set 0011 0011 (33) for 8 bit data OR 0010 0010 (22) for four bit data

Wait 15mS... Send function set ... Wait @10ms send function set again... Wait @10ms send function set again

Then send display config data... cursor, lines address increment type and so on...

Then the ascii data ie... ascii "1" = 0x31 and so on...

Most of the tutorials have a 16x2 screen....
 
Wait 15mS... Send function set ... Wait @10ms send function set again... Wait @10ms send function set again

yes i have seen this but why we send again and again many times?
 
Pass!!! Must be an internal thing.... Some screens only need one function set others need three...

I have used more than 5 different screens each with slightly different quirks... Setting 4 bit mode seems to be a challenge on some modules.
 
You need to send it three times because the display may have glitched and be in 4bit/8bit mode (unknown).

If it is in 8bit mode (or in 4bit mode but out of nibble sync), sending 3 times ensures the command was received as a correct 4bit nibble and after that time the display is synced to 4bit mode and can receive dual 4bit nibbles for each following command or data byte. :)
 
Hi,

Now the LCD is working fine with my simple code...
I am using portB for Data of 8 bit to LCD. when PORTB is given binary value i.e. ASCII the lcd show the char. but when i write this 'A' or 'H' the LCD show something else char then the char as per ADCII value.....
please clear how to do this..?
 
Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000

#define DATA PORTB
#define EN RC4
#define RS RC6
#define RW RC5
#define N 20
#define M 10
main(){


TRISB=0X00;
TRISC=0X00;

__delay_ms(N);
RS=0;
RW=0;
__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100;
__delay_ms(M);
EN=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100;
__delay_ms(M);
EN=0;
__delay_ms(M);


__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100;
__delay_ms(M);
EN=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100;
__delay_ms(M);
EN=0;
__delay_ms(M);



__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00110000;
__delay_ms(M);
EN=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B10000000;
__delay_ms(M);
EN=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B01100000;
__delay_ms(M);
EN=0;
__delay_ms(M);


__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00000000;
__delay_ms(M);
EN=0;
__delay_ms(M);

while(1){

	RS=1;
RW=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B10100001;
__delay_ms(M);
EN=0;
__delay_ms(M);



RS=1;
RW=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001010;
__delay_ms(M);
EN=0;
__delay_ms(M);





}
}
 
Ohh i just write that for example not seen ASCII ..anyway what the problem in code to write direct 'A' like this?
 
You are just not getting me!!
I was telling when i write like this PORTB='A'...the LCD shows something else character why???

Here is wiring RB7 to D7 to RB0 to D0 like this.......respectively..
 
WHAT DOES IT SHOW!!!! Can you describe it


I have changed your code as I think it was wrong..

This works..

C:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
 
#define DATA PORTB
#define EN RC4
#define RS RC6
#define RW RC5
#define N 20
#define M 10

main(){
	TRISB=0X00;
	TRISC=0X00;
 
	__delay_ms(N);
	RS=0;
	RW=0;
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA=0B00111000;	// 0x38  Init ( we only need the 0x30 )
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
	 
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA=0B00111000;	// 0x38 Init ( we only need the 0x30 )
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
 
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA=0B00111000;	// 0x38 8bit 2 lines
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
	 
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA=0B00000110; // Cursor move increase, no display shift
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
 
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA=0B00001100; // Display on, cursor off, not blinking
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
 
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA=0B00000001; // Clear screen curor to home
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
 
	while(1){
		RS=1;
		RW=0;
		__delay_ms(M);
 
		__delay_ms(M);
		EN=1;
		__delay_ms(M);
		DATA=0B01000001;   // Print A
		__delay_ms(M);
		EN=0;
		__delay_ms(M);
 
		RS=1;
		RW=0;
		__delay_ms(M);
 
		__delay_ms(M);
		EN=1;
		__delay_ms(M);
		DATA=0B01000010; // Print B
		__delay_ms(M);
		EN=0;
		__delay_ms(M);
 
	}
}

Very long piece of code... You need to optimize a little...

Here is MY version without all the repetitive code..

C:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
 
#define DATA PORTB
#define EN RC4
#define RS RC6
#define RW RC5
#define N 20
#define M 10

void LCDcmd(char x), LCDdata(char x);

main(){
	TRISB=0X00;
	TRISC=0X00;
 	LCDcmd(0x38); // init
	LCDcmd(0x38); // init
	LCDcmd(0x38); // Function set
 	LCDcmd(0x06); // Cursor move increase, no display shift
	LCDcmd(0x0C); // Display on, cursor off, not blinking
	LCDcmd(0x01); // Clear display. goto pos 1
 
	while(1){
		LCDdata('A'); // Print A
 		LCDdata('B'); // Print B
	}
}

void LCDcmd(char x)
	{
	__delay_ms(N);
	RS=0;
	RW=0;
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA = x;	// Command data
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
	}
void LCDdata(char x)
	{
	RS=1;
	RW=0;
	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA = x;  //  Print data
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
	}

Both pieces of code run as expected...
 
I have tryied the code using function as you have done but the problem was the same using 'A' or any other 'xyz' showing other char on LCD different from the required one as per ASCII value of char...
 
Have you got the LVP bit set in your config... Even though it's in the config setting..

If you write capital 'A' to the screen... What is the output.... If you tell me what is displayed I can help you further....

If we have a problem with...say... Bit 2 when we write A or b0100 0001 and bit 2 is faulty the display will receive E or b0100 0101 so the incorrect character is written....
 
Hi,

The LCD is working fine even i have display string using *...
I have connected the ADC to LCD while changing voltage showing all ASCII code on LCD...
for making it like voltmeter what should be done a look up table or
something else ( ADRESH*256+ADRESL)*5.0/1023)*10); ??
result = ADRESH;
result <<= 8;
result |= ADRESL;
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top