Wired LCD characters

Discussion in 'Programmer's Corner' started by R!f@@, Apr 29, 2014.

  1. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    This is a new problem and I am running out of ideas.

    My VA meter is functioning as I wanted except for the proper display part.
    That is the wrong messages are coming.

    At first I used around 4 msgs and it worked fine.

    The VA part uses pointers and "char *Vout" to take out the calculated voltage character by character and display them on LCD.

    I removed the over load since I figured I will have current limit which is aslo an overload protection already build in. So I went for over heat shut down.
    This part also works and displays proper msgs till it cools down.
    All good.

    Problem occurs when I added extra 4 msgs at startup of the supply which is only one time.

    It was there before but as the code grew the LCD started giving out wrong display all thru out.

    The displayed voltage or current shows wrong characters now.

    I can fix this if I do not use the start up msgs.
    The 4 first time msg that shows the model, spec, owner and version is creating the problem.
    If I comment out the " Display_Model();"
    which is
    Code ( (Unknown Language)):
    1.  
    2. char txt1[] = "EvilWorks PS600W";
    3. char txt2[] = "0-23V,0-8(10)A";
    4. char *Vout = "00.00";
    5. char *Iout = "00.00";
    6.  
    7. // Model Information and spec
    8. void Display_Model(){
    9.      Lcd_Out(1,1,txt1);
    10.      Delay_ms(400);                  //Delay 400ms
    11.      Lcd_Out(2,2,txt2);              //Display spec on 2nd Row.
    12.      Delay_ms(5000);                 //Wait for 5 seconds.
    13.      Lcd_Cmd(_LCD_CLEAR);            //Clear LCD.
    14.      Delay_ms(250);                  //Wait for 250ms.
    15.      Lcd_Out(1,1,"R!f@@ (XXXXXX)"); //Display text2.
    16.      Lcd_Out(2,1,"Software Ver3.0"); //Display text3.
    17.      Delay_ms(5000);                 //Wait for 5 seconds.
    18.      Lcd_Cmd(_LCD_CLEAR);            //Clear LCD
    19. }
    Every Msg works flawlessly.

    If I add them this thing is going berserk.

    I dunno why this is happening. I tried uninstalling and installing the mikroC too. But did not help. I tried other pic's, still same.

    I know the PIC is fine cause when I remove the the above 4 msg's all's well.
    Even the 4 Msg's are not working, and this drives me nuts.
    Atleast they should show, right.

    I searched for a long time and read all night long and I could not figure out why.

    RB and t0 said something about assigning space for the msg's.
    But I still could not figure this out.

    This is the final road bump with this project.

    I need advice on this

    Thanks so far for all of you who helped me to get this far.
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,392
    497
    Lcd_Out(1,1,"R!f@@ (XXXXXX)"); //Display text2.
    Lcd_Out(2,1,"Software Ver3.0"); //Display text3.

    These two don't have delay between them.
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,392
    497
    It is unclear to me where txt1 and txt2 are declared. Are they global variables?
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Those definitions appears in the very first and second lines of the posted code.
     
  5. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,392
    497
    Yes, I saw that. But that puts them outside of the user defined function. So since they are not declared in any of the user defined functions, that leaves only two places for them: main{} and global variables. I was asking which one of the two they are.
     
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I don't do the LCD clearing the way you do.

    Of all the commands on the Hitachi 44780 LCD chip, the "clear" command takes the longest. Wiki says 1.52mS required.

    Since you have recently had issues with the timing and PIC osc speed in the compiler, it's possible this might be the problem. You should check that. A simple ay is to use this code;
    Code ( (Unknown Language)):
    1.  
    2. while(1)
    3. {
    4.   Delay_mS(900);  // flash LEDs at 1 second freq
    5.   LATB = 0xFF;  
    6.   Delay_mS(100);
    7.   LATB = 0x00;
    8. }
    And compare to a watch or ticking clock etc. It will be very obvious if the LEDs are not flashing at 1Hz.

    You could also force a delay after _CD_CLEAR by adding;
    Delay_mS(10);
    after each time you clear the LCD. That will show if it is a timing issue.

    Other things; MikroC uses RAM for the text strings anyway, so there is no need to declare the text as a global string if you only display it once.
    Just do it inline;
    Lcd_Out(1,1,"EvilWorks PS600W");
    for simpler code and the same RAM usage. :)
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  8. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    Did every thing

    What RB said, still same.
    what t0 showed, still same.


    What I do not understand is if the msg are few all is well.

    I can get the start-up to work if I do not use the over heat msg's.

    I stepped through the code and yet the RAM window shows proper address as the watch window and both show's what the proper characters and the proper msg's are there. It's this friggin LCD not showing any thing.
    Do I need more memory PIC ?
     
  9. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    No, it's probably a code bug.

    At this point if you are not going to use the debugger you will only find the problem if you strip the code down. Comment out stuff that is not the display code. Try to find out what is trashing the RAM areas where your text strings are displayed. It is probably some pointer error or array writing error.
     
    Brian Griffin likes this.
  10. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    I did use the debugger but I may be not good at it.
    I will try again
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Well that link may work but I have two problems:

    First it violates containment by first exposing a local static variable to the outside world. Not the worst of things to do but asking for trouble as it is not a recommended practice.

    Next, more seriously, this is used to save RAM, but sticks some reserved RAM in a place where is is not accessible to the rest of the program. Unless explicitly called you can't get a pointer to this buffer.

    I would much prefer to make a separate global buffer to use for tasks such as this. Yes, globals are bad but as long as you follow the simple rule of "use it and be done with it" it works fine. For LCD stuff I make one buffer a line width (+1 for the /0) and pass that around everywhere.

    The K&R "C Programming Language" specifically covers buffer copying with a marvelous bit of zen code:

    Code ( (Unknown Language)):
    1. //from memory (mistakes are mine not theirs)
    2. codetxt_to_ramtxt(char* dest, const char* source)
    3. {
    4.  while(*dest++ = *source++);  // copy everything until the trailing zero is found
    5. }
     
    Last edited: May 1, 2014
  12. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    Will this work?
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    That depends on what "this" is.
     
  14. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    ur example.
    What is it u thought ?
     
  15. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Final answer: I do not make it a habbit to post ideas I do not think will work.
     
  16. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    still.. it did not work.
     
  17. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    When you say the display goes berserk, what do you mean? Displays seemingly random characters?

    Are you modifying the pointers at all?

    Without seeing the rest of your code, it's hard to debug, however, you seem to want to keep this under lock and key, so our analysis is limited.
     
  18. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Check the edit. I left out the stars.
     
Loading...