LCD With microcontroller.....

Discussion in 'Embedded Systems and Microcontrollers' started by RRITESH KAKKAR, Mar 31, 2013.

  1. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    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
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    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?
     
    Eric007 likes this.
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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"
     
  4. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    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..?
     
  5. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    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.

    Code ( (Unknown Language)):
    1.  
    2. serout GPIO.1,T9600,["Wherever you go,"] ' Send the string "Wherever you go,".
    3.  
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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?
     
  8. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
  9. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Code ( (Unknown Language)):
    1. #include <htc.h>
    2. __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
    3. #define _XTAL_FREQ 20000000
    4.  
    5. #define DATA PORTB
    6. #define EN RC4
    7. #define RS RC6
    8. #define RW RC5
    9. #define N 20
    10. #define M 10
    11. main(){
    12.  
    13.  
    14. TRISB=0X00;
    15. TRISC=0X00;
    16.  
    17. __delay_ms(N);
    18. RS=0;
    19. RW=0;
    20. __delay_ms(M);
    21. EN=1;
    22. __delay_ms(M);
    23. DATA=0B00001100;
    24. __delay_ms(M);
    25. EN=0;
    26. __delay_ms(M);
    27.  
    28. __delay_ms(M);
    29. EN=1;
    30. __delay_ms(M);
    31. DATA=0B00001100;
    32. __delay_ms(M);
    33. EN=0;
    34. __delay_ms(M);
    35.  
    36.  
    37. __delay_ms(M);
    38. EN=1;
    39. __delay_ms(M);
    40. DATA=0B00001100;
    41. __delay_ms(M);
    42. EN=0;
    43. __delay_ms(M);
    44.  
    45. __delay_ms(M);
    46. EN=1;
    47. __delay_ms(M);
    48. DATA=0B00001100;
    49. __delay_ms(M);
    50. EN=0;
    51. __delay_ms(M);
    52.  
    53.  
    54.  
    55. __delay_ms(M);
    56. EN=1;
    57. __delay_ms(M);
    58. DATA=0B00110000;
    59. __delay_ms(M);
    60. EN=0;
    61. __delay_ms(M);
    62.  
    63. __delay_ms(M);
    64. EN=1;
    65. __delay_ms(M);
    66. DATA=0B10000000;
    67. __delay_ms(M);
    68. EN=0;
    69. __delay_ms(M);
    70.  
    71. __delay_ms(M);
    72. EN=1;
    73. __delay_ms(M);
    74. DATA=0B01100000;
    75. __delay_ms(M);
    76. EN=0;
    77. __delay_ms(M);
    78.  
    79.  
    80. __delay_ms(M);
    81. EN=1;
    82. __delay_ms(M);
    83. DATA=0B00000000;
    84. __delay_ms(M);
    85. EN=0;
    86. __delay_ms(M);
    87.  
    88. while(1){
    89.  
    90.     RS=1;
    91. RW=0;
    92. __delay_ms(M);
    93.  
    94. __delay_ms(M);
    95. EN=1;
    96. __delay_ms(M);
    97. DATA=0B10100001;
    98. __delay_ms(M);
    99. EN=0;
    100. __delay_ms(M);
    101.  
    102.  
    103.  
    104. RS=1;
    105. RW=0;
    106. __delay_ms(M);
    107.  
    108. __delay_ms(M);
    109. EN=1;
    110. __delay_ms(M);
    111. DATA=0B00001010;
    112. __delay_ms(M);
    113. EN=0;
    114. __delay_ms(M);
    115.  
    116.  
    117.  
    118.  
    119.  
    120. }
    121. }
    122.  
     
  10. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Hi,
    Please explain this also i found while searching....


    Code ( (Unknown Language)):
    1. #if defined(WDTE_OFF)
    2. __CONFIG(WDTE_OFF & LVP_OFF);
    3. #elif defined (WDTDIS)
    4. __CONFIG(WDTDIS & LVPDIS);
    5. #endif
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    [​IMG]
    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
     
  13. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Code ( (Unknown Language)):
    1. #include <htc.h>
    2. __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
    3. #define _XTAL_FREQ 20000000
    4.  
    5. #define DATA PORTB
    6. #define EN RC4
    7. #define RS RC6
    8. #define RW RC5
    9. #define N 20
    10. #define M 10
    11. main(){
    12.  
    13.  
    14. TRISB=0X00;
    15. TRISC=0X00;
    16.  
    17. __delay_ms(N); // power up delay
    18. RS=0;
    19. RW=0;
    20. __delay_ms(M);
    21. EN=1;
    22. __delay_ms(M);
    23. DATA=0B00001100;  function set 8 bit mode
    24. __delay_ms(M);
    25. EN=0;
    26. __delay_ms(M);
    27.  
    28. __delay_ms(M);
    29. EN=1;
    30. __delay_ms(M);
    31. DATA=0B00001100; // again function set as per datasheet
    32. __delay_ms(M);
    33. EN=0;
    34. __delay_ms(M);
    35.  
    36.  
    37. __delay_ms(M);
    38. EN=1;
    39. __delay_ms(M);
    40. DATA=0B00001100; // function set
    41. __delay_ms(M);
    42. EN=0;
    43. __delay_ms(M);
    44.  
    45. __delay_ms(M);
    46. EN=1;
    47. __delay_ms(M);
    48. DATA=0B00001100; // lcd_set cursor shift,etc
    49. __delay_ms(M);
    50. EN=0;
    51. __delay_ms(M);
    52.  
    53.  
    54.  
    55. __delay_ms(M);
    56. EN=1;
    57. __delay_ms(M);
    58. DATA=0B00110000;//setting
    59. __delay_ms(M);
    60. EN=0;
    61. __delay_ms(M);
    62.  
    63. __delay_ms(M);
    64. EN=1;
    65. __delay_ms(M);
    66. DATA=0B10000000;
    67. __delay_ms(M);
    68. EN=0;
    69. __delay_ms(M);
    70.  
    71. __delay_ms(M);
    72. EN=1;
    73. __delay_ms(M);
    74. DATA=0B01100000;
    75. __delay_ms(M);
    76. EN=0;
    77. __delay_ms(M);
    78.  
    79.  
    80. __delay_ms(M);
    81. EN=1;
    82. __delay_ms(M);
    83. DATA=0B00000000; // clear display
    84. __delay_ms(M);
    85. EN=0;
    86. __delay_ms(M);
    87.  
    88. 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
    89.  
    90.     RS=1;
    91. RW=0;
    92. __delay_ms(M);
    93.  
    94. __delay_ms(M);
    95. EN=1;
    96. __delay_ms(M);
    97. DATA='A';    //The problem is here i want to write A so, i do this 'A' for ascii value of it
    98. __delay_ms(M);
    99. EN=0;
    100. __delay_ms(M);
    101.  
    102.  
    103.  
    104. RS=1;
    105. RW=0;
    106. __delay_ms(M);
    107.  
    108. __delay_ms(M);
    109. EN=1;
    110. __delay_ms(M);
    111. DATA='C';
    112. __delay_ms(M);
    113. EN=0;
    114. __delay_ms(M);
    115.  
    116.  
    117.  
    118.  
    119.  
    120. }
    121. }
    You can see it when i write DATA='A'; some default char comes on LCD apart from required..!!
     
    Last edited: Apr 5, 2013
  14. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    And what was wrong with the example I gave you. Did you even LOOK at it
     
  15. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    i have edited it...........
     
  16. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Well can you please unedit everything. And go back to the original example (please)
     
  17. RamaD

    Active Member

    Dec 4, 2009
    254
    33
    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: Apr 9, 2013
  18. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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?
     
  19. RRITESH KAKKAR

    Thread Starter Senior Member

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

    Yes yes...
     
    Last edited: Apr 9, 2013
  20. RamaD

    Active Member

    Dec 4, 2009
    254
    33
    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.
     
Loading...