The LCD Modules I use are 4x20 "I2C". These are made from a regular 8-bit parallel module with "backpak" that uses PCF8574 I2C expander. These are cheap chinese manufactured displays that usually cost between $5-$8 ea, depending upon the source (Ebay/AliExpress/Amazon, etc.
The MSSP module actually controls the pin direction (since I2C is bidirectional). We only need to set the "initial state" to IN. Then after the module is initialized, it changes the direction on-the-fly as required. Since the default pin direction of all I/O pins is IN, on this patrticular chip, setting the direction to IN (as in the above code) is likely not even necessary. We do it as "good practice" to assure the pin starts as an input before initalizing the MSSP module.
Also look in the InitPPS sub in the code I posted. These lines show that both the IC2 Input and output signal (SDA) is assigned to the same pin. Same with the clock signal (SCL)
Last edit: William Roth 2017-11-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks William. The setting of the port to input makes sense to me now that you explained it, I was still thinking Tx and Rcv ports, but you set me straight that I2C is a bi-directional com.
I ordered the 4 line LCD with the piggy back I2C interface for about $8.
Again, thanks all the help, chips (PIC18F27K40) should be in Monday and I will send you the info on version/date code.
Last edit: Paul Haug 2017-11-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
William,
My 18F27K40's arrived today but I cannot find an rev #. (Found it Rev a002) There is an e3 in a small cicle, and 164760B on the pack. If the rev # is embeded in the chip memory, not sure how to read it using MPLAB IPE v3.55 and GBC V0.98.01.
By the way, your code worked right away with the18F27K40. Many thanks.
Paul
Last edit: Paul Haug 2017-11-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Most folks do not do this, and sometimes I forget. But with a relatively new device it is always a good idea to download the errata sheet and have a look. This chip is now at A03 or higher.
One thing of note in the errata sheet is that the flash memory endurance is 1k cycles as opposed to the 10K cycles specified in the datasheet. dont think I have ever programmed a chip 1,000 times but I may have come close.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
William,
The code you supplied works great and I will use it as the bases of my code, many thanks, but a couple of questions about the LCD part of the code. I received my I2C lcd units and it works great with your code.
#define LCD_IO 10
#define LCD_I2C_Address_1 0x7E
What are these two statements details ?
I did find this in Evan sample code in GCB@syn, so that explains the LCD_IO as device type, guess I lucked out and mine is a type 10.
'''This uses the GCB hardware implementation of IC2 for Microchip devices.
'''Two types are supported as shown below. This example is using "#define LCD_IO 10"
'''- Set LCD_I0 to 10 for the YwRobot LCD1602 IIC V1 or the Sainsmart LCD_PIC I2C adapter.
'''- Set LCD_I0 to 12 for the Ywmjkdz I2C adapter with pot bent over top of chip.
'''- Use the following to address a diferent I2C device.
'''- #define LCD_I2C_Address 0x4e 'This is the default value, change as appropiate
'''@author EvanV
.
.
So now I want to understand the Address part.
I also searched [GCB@syn greatcowbasic include] but there are tons of GLCD includes not sure wher to go.
Last edit: Paul Haug 2017-11-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
All I2C devices have an address, This is how IC2 can comminicate with multiple devices on the same bus. 0x7E is the unique 7-bit address for your LCD display. IF you look on the backpack board there are three pads that can be set to change the Address. To use 2 or more I2C LCD displays with the same microcontroller, each display needs a different address. More detail is provided in the PCF8574 Datasheet in regards to setting the address.
#define LCD_I2C_Address 0x7E
Creates a constantat at compile time to tell the code to use address 0x7E as the address for the LCD Display Module.
Hi Paul,
Here is an example.
Also look in the InitPPS sub in the code I posted. These lines show that both the IC2 Input and output signal (SDA) is assigned to the same pin. Same with the clock signal (SCL)
Last edit: William Roth 2017-11-04
Thanks William. The setting of the port to input makes sense to me now that you explained it, I was still thinking Tx and Rcv ports, but you set me straight that I2C is a bi-directional com.
I ordered the 4 line LCD with the piggy back I2C interface for about $8.
Again, thanks all the help, chips (PIC18F27K40) should be in Monday and I will send you the info on version/date code.
Last edit: Paul Haug 2017-11-04
William,
My 18F27K40's arrived today but I cannot find an rev #. (Found it Rev a002) There is an e3 in a small cicle, and 164760B on the pack. If the rev # is embeded in the chip memory, not sure how to read it using MPLAB IPE v3.55 and GBC V0.98.01.
By the way, your code worked right away with the18F27K40. Many thanks.
Paul
Last edit: Paul Haug 2017-11-07
OOPS, found it Device ID Revision = a002
Ordered from Mouser
OK thanks. Same as mine.
Most folks do not do this, and sometimes I forget. But with a relatively new device it is always a good idea to download the errata sheet and have a look. This chip is now at A03 or higher.
One thing of note in the errata sheet is that the flash memory endurance is 1k cycles as opposed to the 10K cycles specified in the datasheet. dont think I have ever programmed a chip 1,000 times but I may have come close.
William,
The code you supplied works great and I will use it as the bases of my code, many thanks, but a couple of questions about the LCD part of the code. I received my I2C lcd units and it works great with your code.
#define LCD_IO 10
#define LCD_I2C_Address_1 0x7E
What are these two statements details ?
I did find this in Evan sample code in GCB@syn, so that explains the LCD_IO as device type, guess I lucked out and mine is a type 10.
'''This uses the GCB hardware implementation of IC2 for Microchip devices.
'''Two types are supported as shown below. This example is using "#define LCD_IO 10"
'''- Set LCD_I0 to 10 for the YwRobot LCD1602 IIC V1 or the Sainsmart LCD_PIC I2C adapter.
'''- Set LCD_I0 to 12 for the Ywmjkdz I2C adapter with pot bent over top of chip.
'''- Use the following to address a diferent I2C device.
'''- #define LCD_I2C_Address 0x4e 'This is the default value, change as appropiate
'''@author EvanV
.
.
So now I want to understand the Address part.
I also searched [GCB@syn greatcowbasic include] but there are tons of GLCD includes not sure wher to go.
Last edit: Paul Haug 2017-11-10
All I2C devices have an address, This is how IC2 can comminicate with multiple devices on the same bus. 0x7E is the unique 7-bit address for your LCD display. IF you look on the backpack board there are three pads that can be set to change the Address. To use 2 or more I2C LCD displays with the same microcontroller, each display needs a different address. More detail is provided in the PCF8574 Datasheet in regards to setting the address.
Creates a constantat at compile time to tell the code to use address 0x7E as the address for the LCD Display Module.
There may be more information in the HELP.
http://gcbasic.sourceforge.net/help/_lcd_io_10.html
Last edit: William Roth 2017-11-10
Thanks, makes perfect sense, I forgot I2C devices have addresses for multiple devices on the same serial buss.
Last edit: Paul Haug 2017-11-10