Structure in Module and choice in Program, again...

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
hbruno
Posts: 5
Joined: Mon Sep 28, 2009 9:52 pm

Structure in Module and choice in Program, again...

Post by hbruno » Sat Nov 06, 2010 10:06 pm

Hello all,
I try my luck on this forum, as on "User Modules", 75 people have read my post, but 0 replies.
i want to make a module for drive a LCD with a PCF8574(A) (in 4bit mode).
My module is finished but, now, I want the user to choose how he wants to wire the circuit PCF8574 with the LCD.
In my module, i declare the wiring like that :
Code:

Code: Select all

Public Structure HD44780_ 
   dLCD As Byte      ' PCF8574 
   BL As dLCD.7      ' P7 (Broche 12) 
   EN As dLCD.6      ' P6 (Broche 11)        
   RS As dLCD.5      ' P5 (Broche 10) 
   RW As dLCD.4      ' P4 (Broche 9) 
   D7 As dLCD.3      ' P3 (Broche 7) 
   D6 As dLCD.2      ' P2 (Broche 6) 
   D5 As dLCD.1      ' P1 (Broche 5) 
   D4 As dLCD.0      ' P0 (Broche 4) 
End Structure 
Dim I2CLCD As HD44780_ 


With use of "I2CLCD.EN", for example, i can access to the Enable bit without knowing how is wire.
How write, in program, the choice for user (#option, #define, else...) ?

PS: i hope you understand my poor english.
Bruno

2brain
Posts: 18
Joined: Fri Jan 22, 2010 1:04 pm
Location: Hong Kong

Structure in Module

Post by 2brain » Sun Nov 07, 2010 3:18 am

You could try looking at the LCD.bas which supports the HD44780 and has #options and #defines for LCD lines. Not sure what the PCF8574(A) has to do with anything other than being an I/O expander, if you look in the LCD Help file you can see the display is wired for 4 data bits.

hbruno
Posts: 5
Joined: Mon Sep 28, 2009 9:52 pm

Re: Structure in Module

Post by hbruno » Sun Nov 07, 2010 9:53 am

2brain wrote:You could try looking at the LCD.bas which supports the HD44780 and has #options and #defines for LCD lines. Not sure what the PCF8574(A) has to do with anything other than being an I/O expander, if you look in the LCD Help file you can see the display is wired for 4 data bits.
Hi 2brain,
you do not understand the purpose of my module. With the PCF8574, I can drive the LCD with 2 wire. Besides the advantage of using only 2 wire, I can also deport the display.

Image

So my question remains, how to declare the "Options" (BL, EN, RS, RW, D7 - D4) from my structure in my program ...

2brain
Posts: 18
Joined: Fri Jan 22, 2010 1:04 pm
Location: Hong Kong

Module

Post by 2brain » Sun Nov 07, 2010 1:04 pm

The #option and # define are parts of the compiler preprocessor, so look at the Language Reference - preprocessor help.

If you look at the LCD.bas module you should see how they are used.

hbruno
Posts: 5
Joined: Mon Sep 28, 2009 9:52 pm

Post by hbruno » Sun Nov 07, 2010 11:40 pm

there is no structure in LCD.bas
I read all the documentation at Language Reference - preprocessor Help.
There's no indication for passed Structure between Program and Module. :( .
I use #option or #define in other module with success, but, here, i'm blocked...

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Mon Nov 08, 2010 11:01 am

This seems to work ok here (SF 2.2.0.4)

Code: Select all

program test

#option LCD_BL_PIN  = 7
#option LCD_ENA_PIN = 6
#option LCD_RS_PIN  = 5
#option LCD_RW_PIN  = 4
#option LCD_D7_PIN  = 3
#option LCD_D6_PIN  = 2
#option LCD_D5_PIN  = 1
#option LCD_D4_PIN  = 0

Public Structure HD44780_
   dLCD As Byte      ' PCF8574
   BL As dLCD.LCD_BL_PIN      ' P7 (Broche 12)
   EN As dLCD.LCD_ENA_PIN      ' P6 (Broche 11)
   RS As dLCD.LCD_RS_PIN      ' P5 (Broche 10)
   RW As dLCD.LCD_RW_PIN      ' P4 (Broche 9)
   D7 As dLCD.LCD_D7_PIN      ' P3 (Broche 7)
   D6 As dLCD.LCD_D6_PIN      ' P2 (Broche 6)
   D5 As dLCD.LCD_D5_PIN      ' P1 (Broche 5)
   D4 As dLCD.LCD_D4_PIN      ' P0 (Broche 4)
End Structure
public Dim I2CLCD As HD44780_

// clear byte
I2CLCD.dLCD = 0

// set bits in structure
I2CLCD.BL = 1
I2CLCD.BL = 0

I2CLCD.EN = 1

I2CLCD.RW = 1
I2CLCD.RW = 0

I2CLCD.EN = 0

It also worked when I moved the structure definition/declaration into another module and included that here as well.

hbruno
Posts: 5
Joined: Mon Sep 28, 2009 9:52 pm

Post by hbruno » Mon Nov 08, 2010 9:19 pm

Thank you very much Jerry, you are my savior. indeed, it is the right solution. :D
I had not thought about using tampons variables, I always tried to directly address the elements of the structure declared in the module. thank you again.
I'll soon be able to publish this module in the wiki.

Mikeclx
Posts: 20
Joined: Mon Feb 09, 2009 5:36 am
Location: New Zealand

Re: Structure in Module and choice in Program, again...

Post by Mikeclx » Tue Jun 28, 2016 12:23 pm

Did anyone get this going? Im trying to do the same thing but i cannot see how this links the LCD module to the I2C bits or in fact how to do that, Do i have to start from scratch or is there a way to get the bits out of the existing LCD module and just poke them out I2C?

Thanks for any assistance,

Mike

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Structure in Module and choice in Program, again...

Post by Jerry Messina » Tue Jun 28, 2016 12:52 pm

It doesn't look like hbruno ever posted anything on the wiki, so I don't know if he ever got it working or not.
but i cannot see how this links the LCD module to the I2C bits
It doesn't really. The lcd.bas module is written to interface to the display using port IO pins. All that structure does is translate setting IO pins to setting bits in a byte... you'd have to replace all the hardware access instructions in lcd.bas with I2C calls to send the byte out to the PCF8574.

Mikeclx
Posts: 20
Joined: Mon Feb 09, 2009 5:36 am
Location: New Zealand

Re: Structure in Module and choice in Program, again...

Post by Mikeclx » Tue Jun 28, 2016 11:22 pm

Thanks for the reply, Yes that's what i was hoping to do, just get the bits in a byte set instead of IO pins and then my program could deal with sending that byte out to the I2C every time it changed.
Ill see what i can come up with, maybe an I2CLCD.Bas module as you suggest, as the backpack for the LCD's is very cheap and reduces the IO count to 2, can even use the 2 pins for other I2C things as well. So a very handy module when you have lots of other things to do with the IO pins.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Structure in Module and choice in Program, again...

Post by Jerry Messina » Wed Jun 29, 2016 9:44 am

Let us know what you come up with Mike. I'm sure it'd be a popular item for all the LCD backpacks.

Just FYI (in case you haven't seen them) there are a number of LCD's that have I2C/SPI builtin, like the EA DOG series.

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: Structure in Module and choice in Program, again...

Post by bitfogav » Mon Jun 15, 2020 10:00 pm

I have uploaded a new module for the PCF8574 and LCD

https://www.sfcompiler.co.uk/wiki/pmwik ... LCDPCF8574

Mikeclx
Posts: 20
Joined: Mon Feb 09, 2009 5:36 am
Location: New Zealand

Re: Structure in Module and choice in Program, again...

Post by Mikeclx » Wed May 03, 2023 5:23 am

Awesome, thanks i have been away from SF for a while but have a few projects im going to do on it and might even get this one going :D

Post Reply