Author Topic: HD7780 AVR Library  (Read 6040 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #25 on: November 01, 2017, 09:22:33 am »
well I've used it for some time but I've kept everything in the project folder which means it just works but then I am constantly copying stuff.
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: HD7780 AVR Library
« Reply #26 on: November 01, 2017, 10:17:21 am »
well I've used it for some time but I've kept everything in the project folder which means it just works but then I am constantly copying stuff.
This is why I prefer git submodules. Project folder does contain copies of dependencies for the sake of the complex IDEs and source distributions, but in the source control everything appears only once.
 

Offline alank2

  • Super Contributor
  • ***
  • Posts: 2185
Re: HD7780 AVR Library
« Reply #27 on: November 01, 2017, 12:02:56 pm »
Yes and if I "add existing" it still can't find it! this is stupid, and IDE is supposed to make life easier, this is just being so complicated it defeats the object....

I hated AS7 when I first started using it.  Then I used Atollic TrueStudio and that takes confusing and non-intuitive to a whole new level.

Glad you got it working!
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #28 on: November 09, 2017, 08:46:37 am »
OK so I have the library working (well no more compilation errors involving it or my own headers and C files). I am writing my program but I don't see a way of putting a variable on the screen. Is there a way to do this? what I am trying to do is measure a sensor and then after some simple calculations that extract a meaningful number put that number on screen. I don't see this described in the instruction text, only how to "put character"
« Last Edit: November 09, 2017, 08:48:31 am by Simon »
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: HD7780 AVR Library
« Reply #29 on: November 09, 2017, 09:04:34 am »
OK so I have the library working (well no more compilation errors involving it or my own headers and C files). I am writing my program but I don't see a way of putting a variable on the screen. Is there a way to do this? what I am trying to do is measure a sensor and then after some simple calculations that extract a meaningful number put that number on screen. I don't see this described in the instruction text, only how to "put character"

Quite simply you use a function such as ftoa() or itoa() to convert a number to a string, and then print the string.  If you want to do fancy string formatting then use sprintf(), though be aware of the code size and run time overheads.

The other option is to add some optimised LCD print functions into your library to deal with numbers.
« Last Edit: November 09, 2017, 09:08:45 am by mikerj »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #30 on: November 09, 2017, 09:14:26 am »
I see, what are the functions atof() and atoi() part of ? are they part of the GCC for AVR libraries ?


I'm also getting this error: character constant too long for its type
for: lcd_putc('Flow too LOW');
so I guess that was meant for one character at a time. that will be painful for one character at a time but doable
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #31 on: November 09, 2017, 09:21:04 am »
atof() and atoi()  seem to do the opposite, convert text to number format variables. I'll have a dig around
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2328
  • Country: 00
Re: HD7780 AVR Library
« Reply #32 on: November 09, 2017, 10:55:34 am »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #33 on: November 09, 2017, 11:29:25 am »
ok but how does printf() help with another function that does not know of it's existence? (My knowledge of C is limited), I'm going on the help file that tells me how to use the LCD library, if it's is not written to cope with my situation how do I get it to work with printf()
« Last Edit: November 09, 2017, 11:31:09 am by Simon »
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: HD7780 AVR Library
« Reply #34 on: November 09, 2017, 11:48:33 am »
atof() and atoi()  seem to do the opposite, convert text to number format variables. I'll have a dig around

ftoa() and itoa().  You must have read my post just after I submitted it as I accidentally put the wrong functions in and then edited it.

printf() calls a function putch() to output a character.  The default behaviour of putch() varies, but it can be overridden by defining your own version of putch().  This allows you to use printf to write to any character based device, but again you must be aware of the memory and runtime overhead of printf (and sprintf) which can be very significant on a small 8 bit micro, especially when working with floating point values.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #35 on: November 09, 2017, 12:18:38 pm »
Ah I see, I tried googling the variable to charachter but drew a blank, now have named those functiontions information is plentiful.

I have had a look through the source files for the library and think i have found a put string function that should do the trick and avoid me having to call putc many many times:

Code: [Select]
/*************************************************************************
Display string
Input:    string to be displayed
Returns:  none
*************************************************************************/
void lcd_puts(const char *s)
  {
    register char c;

    while ((c=*s++))
      lcd_putc(c);
  }
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2328
  • Country: 00
Re: HD7780 AVR Library
« Reply #36 on: November 09, 2017, 12:19:07 pm »
You need to waste some time to learn

 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #37 on: November 09, 2017, 12:21:54 pm »
indeed which is one reason for doing this project in C instead of Arduino, I need to make something and don't quite know how to do it but it's an excuse to learn.

puts is not working as hoped.
 

Offline alank2

  • Super Contributor
  • ***
  • Posts: 2185
Re: HD7780 AVR Library
« Reply #38 on: November 09, 2017, 01:03:41 pm »
There are three functions (take a look in the H file):

void lcd_putc(char c);
void lcd_puts(const char *s);
void lcd_puts_P(const char *progmem_s);

lcd_putc is designed to put one character - lcd_putc('A');
lcd_puts is designed to put a null terminated string in sram to the display lcd_puts("Hello"); or lcd_puts(s1); where s1 is defined as char s1[20]; or similar.
lcd_puts_P is designed to put a null terminated string in flash to the display:

#include "avr/pgmspace.h"
const char MsgPounds                                                 [] PROGMEM = "Pounds";
lcd_puts_P(MsgPounds);

In the case of lcd_puts, you have to render the string first using a function like sprintf.  I typically create a global string like char s1[80]; or something and use it like this:
sprintf(s1,"%d",i1); //i1 is an integer
lcd_puts(s1);


You have to understand that the "%d" string above (3 bytes) is wasting your sram as well. That is why there is a sprintf_P function that allows you to replace the "%d" with a flash PROGMEM string:

const char MsgPercentUMinutes                                        [] PROGMEM = "%u Minutes";
sprintf_P(s1,MsgPercentUMinutes,15+currentsetting*15);
lcd_puts(s1);

Now the "%u Minutes" is in flash (taking no sram up), s1 is in sram and is reusable across many functions, and lcd_puts will put the results of s1 to the display.

Good luck!
« Last Edit: November 09, 2017, 01:06:59 pm by alank2 »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #39 on: November 09, 2017, 01:07:04 pm »
aha, wrong type of quote marks.....
 

Offline alank2

  • Super Contributor
  • ***
  • Posts: 2185
Re: HD7780 AVR Library
« Reply #40 on: November 09, 2017, 01:11:57 pm »
Single quotes are for a character (or byte):

lcd_putc(65);
lcd_putc('A');  //same thing

Double quotes create a null terminated string:

lcd_puts("Hello");

becomes H e l l o <0> in memory, 5 bytes for each letter and 1 byte for the null terminator.  What is sent to the function is not the 6 bytes, but a pointer to the 6 bytes which is why it is defined as having a char* type argument.  The * means pointer.  char argument = single character, char* argument = pointer to one or more characters.

 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: HD7780 AVR Library
« Reply #41 on: November 09, 2017, 01:21:39 pm »
atof() and atoi()  seem to do the opposite, convert text to number format variables. I'll have a dig around

ftoa() and itoa().  You must have read my post just after I submitted it as I accidentally put the wrong functions in and then edited it.

printf() calls a function putch() to output a character.  The default behaviour of putch() varies, but it can be overridden by defining your own version of putch().  This allows you to use printf to write to any character based device, but again you must be aware of the memory and runtime overhead of printf (and sprintf) which can be very significant on a small 8 bit micro, especially when working with floating point values.
Depending on libc implementation, putch() may call something else further down the line. The version of newlib included in ARM's distribution of GCC chains the calls eventually to _write(). For my STM32 HD44780 driver library I just implemented _write (in fact I have the file handle mechanism and the call dispatcher in place, but still the same story) and calls to fprintf() or write() can go straight to the LCD.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: HD7780 AVR Library
« Reply #42 on: November 09, 2017, 04:35:58 pm »
well AS seems to quite like sprintf(s1,"%d",i1);
 

Offline alank2

  • Super Contributor
  • ***
  • Posts: 2185
Re: HD7780 AVR Library
« Reply #43 on: November 09, 2017, 04:39:37 pm »
well AS seems to quite like sprintf(s1,"%d",i1);

It will, but consider that "%d" is burning 3 bytes of sram AND flash when it really only needed to use 3 bytes of flash.  That is what the PROGMEM and _P version of the function allow.  Not a big deal for 3 bytes, but get an entire project full of constant strings and it becomes a big deal very quickly.
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: HD7780 AVR Library
« Reply #44 on: November 09, 2017, 06:29:18 pm »
well AS seems to quite like sprintf(s1,"%d",i1);

It will, but consider that "%d" is burning 3 bytes of sram AND flash when it really only needed to use 3 bytes of flash.  That is what the PROGMEM and _P version of the function allow.  Not a big deal for 3 bytes, but get an entire project full of constant strings and it becomes a big deal very quickly.

A clever linker can squash all identical constant strings into one instance. Although if your code contains a lot of different strings you still run out of resources fast.
 

Offline apurvdate

  • Contributor
  • Posts: 43
  • Country: in
Re: HD7780 AVR Library
« Reply #45 on: November 10, 2017, 12:12:40 pm »
There used to be a "Watch" or "Quick Watch" functionality in AS6. When in debug mode you can see value in watch window. Its a no go if u want real time value display though..
I hope its there in AS7 also. FYI I haven't used AS for 2 years...

edit: posted reply n then understood your query.. silly me  :palm:
« Last Edit: November 10, 2017, 12:16:31 pm by apurvdate »
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: HD7780 AVR Library
« Reply #46 on: November 11, 2017, 11:47:40 am »
HD44780 is a prime example of technology which is implemented so simply and in "directly usable" way that, usually, it takes a lot more time to find a library, find out how it works, assess whether it's usable at all (libraries often tend to be completely broken by design), and then, finally, be able to do something with it - than what it takes just to directly write your code - call it a library if you want, but it's usually just a few lines.

This is not surprising: HD44780 is an old school "bus" device that directly accepts data and just does what you tell it to do, so kinda plug&play. At that time, it wasn't common to think in the modern stupid "hardware abstraction middleware driver blah blah" way ;). With today's complexity often requiring that, we have forgotten it doesn't always need to be that way.

As a semi-noob, when I first time interfaced with HD44780 in 2005, I spent only one (1) HOUR to actually write everything myself. This is because HD44780 interfacing is about 10 to 20 lines of code, all extremely trivial and well documented. I found this a lot easier than basic MCU things like intializing an AVR timer/counter to produce PWM, which took several hours the first time to get right  ::).
« Last Edit: November 11, 2017, 11:51:13 am by Siwastaja »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf