I am building a digital clock using an HD44780 LCD display, Picaxe 20M2 and a ds1307 RTC. I got the display working in 4-bit mode thanks to the help of others on the forum. My question is I have connected the LCD to pins B.0 - B.3 on the 20M2 and everything is working fine.
I can send text and commands and it works perfectly. However, once I connected the DS1307 to the SDA (b.5) and SCL (b.7) pins on portB and I can not read anything from the RTC and display it. I am guessing this has something to do with the fact I am using the pinsB= command to send data/commands to the LCD and the RTC is connected to 2 of those pins. I used the dirsB=%01011111 to set all pins but SDA and SCL as outputs. I understood that issuing a pinsB=%value would not affect the 2 pins configured as inputs, but I get no reading. I'm not sure if this is a limitation and I have to re-design around this, or there is a fix. Here is my code. Any suggestions would be much appreciated. I have also added to two 4K7 pullup resistors on the SDA and SCL lines.
The only thing that appears in the LCD is Time: and Datebelow it), but a blank space for what should be the second
I can send text and commands and it works perfectly. However, once I connected the DS1307 to the SDA (b.5) and SCL (b.7) pins on portB and I can not read anything from the RTC and display it. I am guessing this has something to do with the fact I am using the pinsB= command to send data/commands to the LCD and the RTC is connected to 2 of those pins. I used the dirsB=%01011111 to set all pins but SDA and SCL as outputs. I understood that issuing a pinsB=%value would not affect the 2 pins configured as inputs, but I get no reading. I'm not sure if this is a limitation and I have to re-design around this, or there is a fix. Here is my code. Any suggestions would be much appreciated. I have also added to two 4K7 pullup resistors on the SDA and SCL lines.
Code:
pause 100
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
'###################Define Sysmbols HD44780 pins
symbol LCD_ENABLE=c.4 'Enable pin on HD44780 LCD module
symbol LCD_RS=c.3 'Register Select pin on HD77480, HIGH=Data, LOW=Command
dirsB=%01011111
symbol outbyte =b0
symbol counter = b1
symbol bitcount = b2
symbol nibblecount=b3
'Time Variables
symbol seconds = b4
symbol mins = b5
symbol hour = b6
symbol day = b7
symbol date = b8
symbol month = b9
symbol year = b10
symbol control = b11 'Square wave output
'Set initial values for date and time
let seconds = $00
let mins = $00
let hour = $12
let day = $01
let date = $01
let month = $12
let year = $16
let control = %00010000
hi2cout 0, (seconds, mins, hour, day, date, month, year, control)
LOW LCD_ENABLE
LOW LCD_RS
'############Initialization sequence for HD44780 Module#############
for counter = 0 to 6
lookup counter ,($33, $32, $28, $10, $01, $06, $0E), outbyte
gosub WRITE_LCD_INST
pause 10
next counter
'#####################################################################
outbyte=$80
gosub WRITE_LCD_INST
eeprom 0,("Time: ")
eeprom 12,("Date: ")
main:
hi2cin 0, (seconds, mins, hour, day, date, month, year, control)
bcdtoascii seconds, b20, b21
b20 = b20 - $30
b21 = b21 - $30
outbyte=b21 'Test to see output of second but appears blank
gosub WRITE_LCD_DATA
for counter = 0 to 5
read counter,outbyte
gosub WRITE_LCD_DATA
next counter
outbyte=$C0
gosub WRITE_LCD_INST
for counter = 12 to 16
read counter,outbyte
gosub WRITE_LCD_DATA
next counter
end
WRITE_LCD_INST: 'Write Commands to LCD
low LCD_RS
outbyte=outbyte * 256 | outbyte / 16
for nibblecount= 1 to 2
pinsB=outbyte
pulsout LCD_ENABLE,1
pause 4
outbyte=outbyte / 16
next nibblecount
return
WRITE_LCD_DATA: 'Write Data to LCD
high LCD_RS
outbyte=outbyte * 256 | outbyte / 16
for nibblecount= 1 to 2
pinsB=outbyte
pulsout LCD_ENABLE,1
pause 4
outbyte=outbyte / 16
next nibblecount
return