I'm getting my feet wet with I2C and LCD's using a PIC12f683. After combing through numerous posts, I cobbled together some test code modified from a posted reply to an earlier OP of mine. The code is as follows):
#Chip 12F683, 8
#Config OSC = INTOSCIO, MCLRE = Off
#define I2C_MODE Master
#define I2C_DATA GPIO.4
#define I2C_CLOCK GPIO.2
#define I2C_DISABLE_INTERRUPTS ON
#define LCD_IO 10
#define LCD_I2C_Address_1 0x3F 'I2C Address: It's either 0x27 or 0x3F
Do
Clearline 0
Print "hello"
wait 10 ms
Loop
Sub Clearline (In LCD_TMP)
Locate LCD_TMP,0
LCDSPACE 19
Locate LCD_TMP,0
End Sub
I've tried both addresses shown in that listing, with no display. I've played with contrast/backlight via a the POT on the I2C module, still no display seen. I'd appreciate any help or thoughts.
Last edit: Dave B 2016-04-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
William: The LCD has proper backlight when power is applied, and has an adjustment POT which functions properly. the LCD does not have SDO or SDI as such. It has clock, data, power, and ground lines. the PIC does not implement I2C in hardware, I have to use the GCB software I2C routines. Please refer to your first reply to my OP at https://sourceforge.net/p/gcbasic/discussion/629990/thread/f5c46211/ to see the source of the above (modified) code. Did the LCD you used in that example have the lines specifically labeled as you mention above?
Anobium: Yes, i have read through a number of dems, not only from this site and the GCB docs, but several others found from a Google search. The code above is more or less a copy/paste from Williams reply to another OP of mine (referenced above), then modified for my specific PIC (which doesn't use ports as such, but GPIO pins). I do not have a serial terminal.
I will be back in my shop Monday, and as I get time i will resume my efforts. Thank you for your replies.
Last edit: Dave B 2016-05-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great. Verify you have I2C connnectivity first, make sure you have pull up resistors, use the demostration for I2C discovery. I am assuming you have the latest version of Great Cow BASIC - if not, install it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How do I verify connectivity with no terminal or other means of display, other than the LCD with which I have (apparently) so far been unable to communicate? I will try the discovery code, but instead of sending to terminal I will try writting to EEPROM (another thing I haven't been able to do successfully, although it should be incredibly straight-forward....)
Last edit: Dave B 2016-05-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, progress. I modified the I2C discovery demo from the GCB docs to write the device ID to eeprom and flash an LED, since I do not have a serial terminal. It came back with a device ID of "7E". here is the modified code:
' I2C Overview - using the ChipIno board, see here for information
#chip 12f683, 8
#config MCLRE_ON
' Define I2C settings
#define I2C_MODE Master
#define I2C_DATA gpio.4
#define I2C_CLOCK gpio.2
#define I2C_DISABLE_INTERRUPTS ON
#define led gpio.0
wait 100 ms
dim DeviceID as byte
for DeviceID = 0 to 255
I2CStart
I2CSend ( deviceID )
I2CSend ( 0 )
I2CSend ( 0 )
i2cstop
if I2CSendState = True then
EPWrite 0,DeviceID
set led on
wait 250 ms
set led off
wait 250 ms
set led on
wait 250 ms
set led off
wait 250 ms
set led on
wait 250 ms
set led off
end if
next
End
However, when I modified that code to send to the LCD by adding the line "print "you found me", DeviceID" just below the eeprom write, I got the following errors during compile:
lcd.h (385): Error: SYSLCDTEMP.1 is not a valid I/O pin or port
lcd.h (386): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (396): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (470): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (471): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (472): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (473): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (847): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (897): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (898): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (899): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (900): Error: SYSLCDTEMP.0 is not a valid I/O pin or port*
Last edit: Dave B 2016-05-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, I figured out at least part of my problem, and had one successful execution of the code below. Subsequent executions just turn off the LED backlight, and I see nothing displayed on the LCD, even with adjustment of the contrast POT on the LCD's I2C module.
Why would it work fine once, then start turning off the LED backlight???? I'm obviously still missing something...
' I2C Overview - using the ChipIno board, see here for information
#chip 12f683, 8
#config MCLRE_ON
' Define I2C settings
#define I2C_MODE Master
#define I2C_DATA gpio.4
#define I2C_CLOCK gpio.2
#define I2C_DISABLE_INTERRUPTS ON
#define led gpio.0
dim stuff as String
wait 100 ms
dim DeviceID as byte
for DeviceID = 0 to 255
I2CStart
I2CSend ( deviceID )
I2CSend ( 0 )
I2CSend ( 0 )
i2cstop
if I2CSendState = True then
#define LCD_IO 12
#define LCD_I2C_Address_1 DeviceID
EPWrite 0,DeviceID
print "You found me"
set led on
wait 250 ms
set led off
wait 250 ms
set led on
wait 250 ms
set led off
wait 250 ms
set led on
wait 250 ms
set led off
end if
next
End
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, I tried one more thing, I tied the backlight LED's kathode directly to ground to keep it turned on. still no display seen. For the life of me i can't figire out why that code would work fine the very first time, then does nothing but turn off the LED since. I'm setting this aside before I remove what little hair I have left.
Last edit: Dave B 2016-05-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Let us not be trying to set device IDs on the fly using a Constant. A Constant cannot be changed.
So, let us use the LED. When device is found.... if it is found.. the eeprom will be update in the cod attached.
So.... if you do not have the CLOCK and/or the DATA line pulled high - you will get no results. Do you have the lines pulled high?
Now, when you read the EEPROM and it is zero... it found nothing. Otherwise you have located a device. You may want to adapt the code so when it finds the device it exits the the loop and sets the LED on
Ok, new wrinkle here. I want to add some display to an existing, working, program, but I'm running into a mystery. The code is below. Basically, anything I tell it to print to the LCD BEFORE the "InitTimer1" line prints fine, nothing prints to the LCD after that line. I haven't found squat in searches to answer this one.
#Chip 12F683, 8#Config OSC = INTOSCIO, MCLRE = Off#define I2C_MODE Master#define I2C_DATA GPIO.4#define I2C_CLOCK GPIO.2#define I2C_DISABLE_INTERRUPTS ON#define LCD_IO 10#define LCD_I2C_Address_1 0x7Elocate0,0:print"program start"InitTimer1ExtOsc,PS1_1'initialize timer1 for externallocate1,0:print"timer initialized"'clock and no prescaledimpulsecountasword'define pulse count variabledimdummyasWord'define dummy variable#define led GPIO.1 'set LED output pindirledout'set LED pin for output'Pulse LED briefly to indicate Start-uplocate2,0:print"pulsing LED"fordummy=1to5setledonwait35mssetledoffwait35msnextdummymain:'check for possible control pulse burstcleartimer1'clear timer datastarttimer1'begin counting operationwait50ms'count for 50 milli-seconds'if possible burst detected, then branch off to control'burst detection routineifTimer1>800andtimer1<1100thengotocountpulsesendifgotomaincountpulses:'Take longer count of incoming pulsescleartimer1'clear timer datastartTimer1'begin counting pulseswait100ms'do so for 250 milli-secondsstopTimer1'stop countingpulsecount=timer1*10'multiply pulse count by 4 to'get actual countclearline1locate1,0:printpulsecount'check to see if pulsecount'reasonably matches one of the control tones;'if it does, check for second tone, and if match found,'turn LED either on or offif20100>pulsecountandpulsecount>19900thenwait500mscleartimer1'clear timer datastartTimer1'begin counting pulseswait100ms'do so for 250 milli-secondsstopTimer1'stop countingpulsecount=timer1*10'multiply pulse count by 4 to'get actual countif18100>pulsecountandpulsecount>17900thensetledonclearline3locate3,0:print"transmit on "endifendifif18100>pulsecountandpulsecount>17900thenwait500mscleartimer1'clear timer datastartTimer1'begin counting pulseswait100ms'do so for 250 milli-secondsstopTimer1'stop countingpulsecount=timer1*10'multiply pulse count by 4 to'get actual countif20100>pulsecountandpulsecount>19900thensetledoffclearline3locate3,0:print"transmit off"endifendif'return to checking for additional control pulse burstsgotomainSubClearline(InLCD_TMP)LocateLCD_TMP,0LCDSPACE19LocateLCD_TMP,0EndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Solved my own problem by looking at demo code posted by William Roth as a reply to an OP of mine, here: https://sourceforge.net/p/gcbasic/discussion/629990/thread/f5c46211/ Basically I added the "cleartimer" line immediately after initializing the timer. I have no idea why that's needed, but as long as its working.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm getting my feet wet with I2C and LCD's using a PIC12f683. After combing through numerous posts, I cobbled together some test code modified from a posted reply to an earlier OP of mine. The code is as follows):
the LCD I'm using is here: http://www.ebay.com/itm/321923408888?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
I've tried both addresses shown in that listing, with no display. I've played with contrast/backlight via a the POT on the I2C module, still no display seen. I'd appreciate any help or thoughts.
Last edit: Dave B 2016-04-30
Have you looked through the demonstrations? There a number of demos that show how these adapters work.
Do you have a serial terminal? You can then try ic2 discovery.
Does the backlight come on when 5V is applied ?
Make sure that:
SDO on the LCD connects to SDI on the PIC
SDI on The LCD connscts to SDO on the PIC
The default address should be correct for that LCD, but the discovery code mentioned by Anobium will tell you assumng the connections are correct.
William: The LCD has proper backlight when power is applied, and has an adjustment POT which functions properly. the LCD does not have SDO or SDI as such. It has clock, data, power, and ground lines. the PIC does not implement I2C in hardware, I have to use the GCB software I2C routines. Please refer to your first reply to my OP at https://sourceforge.net/p/gcbasic/discussion/629990/thread/f5c46211/ to see the source of the above (modified) code. Did the LCD you used in that example have the lines specifically labeled as you mention above?
Anobium: Yes, i have read through a number of dems, not only from this site and the GCB docs, but several others found from a Google search. The code above is more or less a copy/paste from Williams reply to another OP of mine (referenced above), then modified for my specific PIC (which doesn't use ports as such, but GPIO pins). I do not have a serial terminal.
I will be back in my shop Monday, and as I get time i will resume my efforts. Thank you for your replies.
Last edit: Dave B 2016-05-06
Great. Verify you have I2C connnectivity first, make sure you have pull up resistors, use the demostration for I2C discovery. I am assuming you have the latest version of Great Cow BASIC - if not, install it.
How do I verify connectivity with no terminal or other means of display, other than the LCD with which I have (apparently) so far been unable to communicate? I will try the discovery code, but instead of sending to terminal I will try writting to EEPROM (another thing I haven't been able to do successfully, although it should be incredibly straight-forward....)
Last edit: Dave B 2016-05-06
Ok, progress. I modified the I2C discovery demo from the GCB docs to write the device ID to eeprom and flash an LED, since I do not have a serial terminal. It came back with a device ID of "7E". here is the modified code:
However, when I modified that code to send to the LCD by adding the line "print "you found me", DeviceID" just below the eeprom write, I got the following errors during compile:
*Great Cow BASIC (0.95 2016-02-24)
Compiling C:\GreatCowBasic\GreatCowBasic\My Projects\I2C Demo.gcb ...
Errors have been found:
lcd.h (385): Error: SYSLCDTEMP.1 is not a valid I/O pin or port
lcd.h (386): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (396): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (470): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (471): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (472): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (473): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (847): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (897): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (898): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (899): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (900): Error: SYSLCDTEMP.0 is not a valid I/O pin or port*
Last edit: Dave B 2016-05-02
Ok, I figured out at least part of my problem, and had one successful execution of the code below. Subsequent executions just turn off the LED backlight, and I see nothing displayed on the LCD, even with adjustment of the contrast POT on the LCD's I2C module.
Why would it work fine once, then start turning off the LED backlight???? I'm obviously still missing something...
Ok, I tried one more thing, I tied the backlight LED's kathode directly to ground to keep it turned on. still no display seen. For the life of me i can't figire out why that code would work fine the very first time, then does nothing but turn off the LED since. I'm setting this aside before I remove what little hair I have left.
Last edit: Dave B 2016-05-10
You have me puzzled but here goes.
Let us not be trying to set device IDs on the fly using a Constant. A Constant cannot be changed.
So, let us use the LED. When device is found.... if it is found.. the eeprom will be update in the cod attached.
So.... if you do not have the CLOCK and/or the DATA line pulled high - you will get no results. Do you have the lines pulled high?
Now, when you read the EEPROM and it is zero... it found nothing. Otherwise you have located a device. You may want to adapt the code so when it finds the device it exits the the loop and sets the LED on
I think the problem was in setting the constant on the fly. I put together a different test program, and it is working fine now.
Ok, new wrinkle here. I want to add some display to an existing, working, program, but I'm running into a mystery. The code is below. Basically, anything I tell it to print to the LCD BEFORE the "InitTimer1" line prints fine, nothing prints to the LCD after that line. I haven't found squat in searches to answer this one.
Solved my own problem by looking at demo code posted by William Roth as a reply to an OP of mine, here: https://sourceforge.net/p/gcbasic/discussion/629990/thread/f5c46211/ Basically I added the "cleartimer" line immediately after initializing the timer. I have no idea why that's needed, but as long as its working.