> Hi Mike,
>
> That was simple, and not only did it compile, but my LCD display still works.
>
> Thank you so much and thanks for all the other answers!
>
> Bob
>
> ________________________________________
> From:
.....piclist-bounces
RemoveMEmit.edu <
RemoveMEpiclist-bounces
spamBeGonemit.edu> on behalf of Mike
> Sent: Thursday, July 30, 2020 2:36 PM
> To:
spamBeGonepiclist@spam@
spam_OUTmit.edu
> Subject: Re: [PIC] Simple GCC question
>
> I strongly suspect the non-constant value GCC is complaining about is
> the return value from Lcd_create(). Since the lcd structure is being
> initialased via a function call you cannot do this outside of a
> function. You can however define an instance of the lcd struct outside
> of a function, and then initialise it later.
>
> Something like this should work:
>
> main.c
>
> #include <lcd.h>
>
> /* These can be initialised outside a function since the initialisers are constant */
> Lcd_PortType ports[] = {LCD_D4_GPIO_Port, LCD_D5_GPIO_Port, LCD_D6_GPIO_Port, LCD_D7_GPIO_Port};
> Lcd_PinType pins[] = {LCD_D4_Pin, LCD_D5_Pin, LCD_D6_Pin, LCD_D7_Pin};
> /* You can only define an instance of Lcd_HandleTypeDef here, since the initialiser is a function */
> Lcd_HandleTypeDef lcd;
>
> void main(void)
> {
> /* Initialise the lcd here */
> lcd = Lcd_create(ports, pins, LCD_RS_GPIO_Port, LCD_RS_Pin, LCD_EN_GPIO_Port, LCD_EN_Pin, LCD_4_BIT_MODE);
>
> /* Other stuff */
> for(;;);
> }
>
>
> mymodule.c
>
> #include <lcd.h>
>
> /* Declare the lcd struct defined in main */
> extern Lcd_HandleTypeDef lcd;
>
> void myfunction(void)
> {
> Lcd_clear(&lcd);
> }
>
>
> This is the simplest way I could show this, but using global variables
> isn't typically the nicest way to do things.
>
> Regards
>
> Mike
>
>
> On 30/07/2020 17:26, Bob Blick wrote:
>> I'm using a nice little HD44780 LCD library in an STM32 project, it works great but I'm stuck with a variable scope problem that I can only seem to make worse because GCC is a bit stricter than I want it to be at this point. Sorry if the code example doesn't wordwrap properly.
>>
>> If, somewhere in main() I create an instance of the LCD like this:
>> Lcd_PortType ports[] = {LCD_D4_GPIO_Port, LCD_D5_GPIO_Port, LCD_D6_GPIO_Port, LCD_D7_GPIO_Port};
>> Lcd_PinType pins[] = {LCD_D4_Pin, LCD_D5_Pin, LCD_D6_Pin, LCD_D7_Pin};
>> Lcd_HandleTypeDef lcd = Lcd_create(ports, pins, LCD_RS_GPIO_Port, LCD_RS_Pin, LCD_EN_GPIO_Port, LCD_EN_Pin, LCD_4_BIT_MODE);
>>
>> then I can use it like this:
>> Lcd_cursor(&lcd, 1,6);
>>
>> but of course I can't do that from within another function since "lcd" only exists in main()
>>
>> If I try to make it all global by creating lcd outside of main(), GCC doesn't like that because initializer elements must be constants and it doesn't consider "ports" and "pins" to be constants.
>>
>> Not being a real C programmer this has stopped me in my tracks. If I was stuck on a deserted island I would use this library as a basis for something with ports and pins hardcoded, but I'm hoping a real expert would give me some gentle help, which will certainly educate me about doing things the correct way and also get me past this little hurdle.
>>
>> Thanks, Bob
>