LCD With microcontroller.....

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
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
 

spinnaker

Joined Oct 29, 2009
7,830
If you can't follow the tutorials, how do you think anyone here can explain any better? You are going to have to show exactly where your issues are. What is a 877a? If it is a pic that you have been working on then you should list the full number.

What compiler are you using? If is is the htc compiler, then they should have an lcd library.

Why do you always supply the bare minimum of information when you post?
 

t06afre

Joined May 11, 2009
5,934
It is an example in the HI-Tech C example folder. That is a very good starting point. But it is important that you study this code. And make modifications that fit your setup. Start by using 8 bit data transfer to the LCD. As a tip. If you use time delays in your main.c program. You must remember to define XTAL frequency correct in both the lcd.c and main.c files. This is also a chance to kind of redeem your self. Please have that in your mind before you ask for help on this topic
By the way the path to the example will be something like this
"C:\Program Files\HI-TECH Software\PICC\9.83\samples\LCDemo"
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
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..?
 

tracecom

Joined Apr 16, 2010
3,944
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..?
I know nothing about C, but in PicBasicPro, you must enclose literal strings inside quotation marks. The following is using serial data, so it may not apply to your case. It's just a feeble attempt to help.

Rich (BB code):
serout GPIO.1,T9600,["Wherever you go,"] ' Send the string "Wherever you go,".
 

t06afre

Joined May 11, 2009
5,934
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..?
Not easy to understand. Does it work then you write a string like 'Hollo world" but not then you just write a single char. Please elaborate and post your code also
 

ErnieM

Joined Apr 24, 2011
8,377
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..?
Post some code. While it may seem clear to you we need to see the code.

Don't describe the code, post the code.

While you're at it, see if you can also include the dot h file where you get your LCD functions from. I suspect in one case you are giving the function an ASCII value, and the other case a pointer to an ASCII value, but i cannot tell that for sure unless you....

POST THE CODE

got it?
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Rich (BB 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);





}
}
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Hi,
Please explain this also i found while searching....


Rich (BB code):
#if defined(WDTE_OFF)
__CONFIG(WDTE_OFF & LVP_OFF);
#elif defined (WDTDIS)
__CONFIG(WDTDIS & LVPDIS);
#endif
 

ErnieM

Joined Apr 24, 2011
8,377
Perhaps I was not clear. Post the code OF THE PROBLEM YOU ARE DESCRIBING.

When you state "but when i write this 'A' or 'H' the LCD show something else" then you should show the code where you write 'A' or 'H' the LCD.

It's nice to show the part that works, but also show the part that doesn't work.

AND FER GODS SAKE USE SOME TABS so your code is readable.
 

t06afre

Joined May 11, 2009
5,934

Darn it! Why do you make it so darn difficult for your self. You are wearing out everybody that try to help you completely out:mad:. I kindly pointed you out in the correct direction in post 3, even gave you some pointers. Because I know that this example works well. But clearly my efforts were in vain. I do not think you even looked at it, shame on you!. I do not know what that code of your do. As I get splitting headache then reading it. You'd better get your act together, starting this second
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Rich (BB 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); // power up delay
RS=0;
RW=0;
__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100;  function set 8 bit mode
__delay_ms(M);
EN=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100; // again function set as per datasheet
__delay_ms(M);
EN=0;
__delay_ms(M);


__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100; // function set
__delay_ms(M);
EN=0;
__delay_ms(M);

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00001100; // lcd_set cursor shift,etc
__delay_ms(M);
EN=0;
__delay_ms(M);



__delay_ms(M);
EN=1;
__delay_ms(M);
DATA=0B00110000;//setting
__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; // clear display
__delay_ms(M);
EN=0;
__delay_ms(M);

while(1){ // here the problem start when i use binary format of ascii it work well but using 'A' for getting ascii value error come on lcd

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

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA='A';    //The problem is here i want to write A so, i do this 'A' for ascii value of it
__delay_ms(M);
EN=0;
__delay_ms(M);



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

__delay_ms(M);
EN=1;
__delay_ms(M);
DATA='C';
__delay_ms(M);
EN=0;
__delay_ms(M);





}
}
You can see it when i write DATA='A'; some default char comes on LCD apart from required..!!
 
Last edited:

RamaD

Joined Dec 4, 2009
328
I tried figuring out what you are saying.
Do you mean to say

DATA='A'; //The problem is here i want to write A so, i do this 'A' for ascii value of it
puts A and some other char on LCD

and
DATA=0b01000001; //The problem is here i want to write A so, i do this 'A' for ascii value of it
works ok?

And, please follow the advice given by members!
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
Here is my understanding of your issue.

When you wish to print 'A':

if you use 0B10100001 it prints 'A' correct
if you use 'A' it prints gibbirish and is incorrect


What is curious is 0B10100001 is not the code for the letter 'A' but some other (non english?) character.

I have no idea why the code that "works" is working.

I have no idea why the code that is "not working" does not work.

I would suspect a hardware wiring issue.

How did you discover the codes that work?
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
I have connected the RB7 to D7 and RB0 to D0 like this............

Here is my understanding of your issue.

When you wish to print 'A':

if you use 0B10100001 it prints 'A' correct
if you use 'A' it prints gibbirish and is incorrect
Yes yes...
 
Last edited:

RamaD

Joined Dec 4, 2009
328
Stop the code at the instruction next to the instruction - DATA=0B10100001, and check D7 to D0 on the LCD terminals. It should be the data that you had output. This should clear your problem.
For the kind of large delays that you are using, you are unlikely to have timing issues.
 
Top