Scenario:
Chip -- DS1302 RTC; Microcontroller -- Stamp, BS2; Display -- LK204-25
I am using a modified version of the Bit Bash technique that was written by Ben Lennard (Thank you, Ben). What I have so far is a display that (in the end) will display the time, date, outside temperature, wind speed, wind direction and humidity (a project that I would like to put together for a technical vocational high school). What I am looking for is PBasic code to write to and read from the DS1302. I would like to be able to read the time (am/pm or 24 hr) and date and display them on the display. Putting them on the display is no problem. I just need some code to initialize the RTC and read from it wonce it is running.
Below is a sample of code that I have used to simply put up some headings on the LK204-25 by editting Mr. Lennard's Bit Bash program. This progrqam does work except for an extra character that the WRITE leaves behind every time I write to the display with a heading (text). So, any sample code or any help that I can find, I would surely appreciate it.
Thanks in Advance,
Mark
'{$STAMP BS2}
'{$PBASIC 2.5}
'Data directive
Time DATA "12:00am ",0
Date DATA "06/17/2007",0
Temp DATA "Temp:",0
Wind_Speed DATA "Wind:",0
Wind_Dir DATA " Dir:",0
Humidity DATA " Hum:",0
'Constants definitions
SDA CON 1 'I2C Data line
SCL CON 0 'I2C Clock line
Display_Address CON $50 'Display address
Command CON 254 'To initialize display command
Clear CON 88 'Clear the display
Cursor CON 71 'Set cursor position
Line_Wrap_On CON 67
Line_Wrap_Off CON 68
'Variables definitions
LCDChar VAR Byte
I2C_data VAR Byte
MemAddress VAR Word
Title VAR Word
'DIRS=%0011111111111111
GOSUB StartI2C
'Initialze & clear display
I2C_Data = Display_Address 'Address the display
GOSUB Write_Data
I2C_Data = Command 'Display command
GOSUB Write_Data
I2C_Data = Clear 'Clear the display
GOSUB Write_Data
PAUSE 2000
I2C_Data = Command 'Display command
GOSUB Write_Data
I2C_Data = 84 'Auto line wrap on
GOSUB Write_Data
Main:
'Display Time:
I2C_Data = Command: GOSUB Write_Data
I2C_Data = Cursor: GOSUB Write_Data
I2C_Data = 1: GOSUB Write_Data
I2C_Data = 1: GOSUB Write_Data
MemAddress = Time
DO
READ MemAddress, LCDChar
MemAddress = MemAddress + 1
I2C_Data = LCDChar
GOSUB Write_Data
LOOP UNTIL (LCDChar = 0)
'Display Date:
I2C_Data = Command: GOSUB Write_Data
I2C_Data = Cursor: GOSUB Write_Data
I2C_Data = 11: GOSUB Write_Data
I2C_Data = 1: GOSUB Write_Data
MemAddress = Date
DO
READ MemAddress, LCDChar
MemAddress = MemAddress + 1
I2C_Data = LCDChar
GOSUB Write_Data
LOOP UNTIL (LCDChar = 0)
'Display Temp
I2C_Data = Command: GOSUB Write_Data
I2C_Data = Cursor: GOSUB Write_Data
I2C_Data = 1: GOSUB Write_Data
I2C_Data = 2: GOSUB Write_Data
MemAddress = Temp
DO
READ MemAddress, LCDChar
I2C_Data = LCDChar
GOSUB Write_Data
MemAddress = MemAddress + 1
LOOP UNTIL (LCDChar = 0)
'Display Wind Speed
I2C_Data = Command: GOSUB Write_Data
I2C_Data = Cursor: GOSUB Write_Data
I2C_Data = 1: GOSUB Write_Data
I2C_Data = 3: GOSUB Write_Data
MemAddress = Wind_Speed
DO
READ MemAddress, LCDChar
I2C_Data = LCDChar
GOSUB Write_Data
MemAddress = MemAddress + 1
LOOP UNTIL (LCDChar = 0)
'Display Wind Direction
I2C_Data = Command: GOSUB Write_Data
I2C_Data = Cursor: GOSUB Write_Data
I2C_Data = 12: GOSUB Write_Data
I2C_Data = 3: GOSUB Write_Data
MemAddress = Wind_Dir
DO
READ MemAddress, LCDChar
I2C_Data = LCDChar
GOSUB Write_Data
MemAddress = MemAddress + 1
LOOP UNTIL (LCDChar = 0)
'Display Humidity
I2C_Data = Command: GOSUB Write_Data
I2C_Data = Cursor: GOSUB Write_Data
I2C_Data = 1: GOSUB Write_Data
I2C_Data = 4: GOSUB Write_Data
MemAddress = Humidity
DO
READ MemAddress, LCDChar
I2C_Data = LCDChar
GOSUB Write_Data
MemAddress = MemAddress + 1
LOOP UNTIL (LCDChar = 0)
GOSUB StopI2C
END
'^^^^^^^^^^^^^^ I2C SUBROUTINES ^^^^^^^^^^^^^^
'Start Procedure. Set start condition on bus: SDA Hi-Lo while SCL Hi
StartI2C:
HIGH SDA: HIGH SCL: LOW SDA: LOW SCL: RETURN
'Stop Procedure. Set stop condition on bus: SDA Lo-Hi while SCL Hi
StopI2C:
LOW SDA: HIGH SCL: HIGH SDA: RETURN
'Write Address/Data Procedure
Write_Data:
SHIFTOUT SDA, SCL, MSBFIRST, [I2C_data]
'Check for Receiver Acknowledge
'RX_ACK:
HIGH SDA
'DIRS=%0011111011111011
HIGH SCL
'ack = IN2
LOW SCL
'DIRS=%0011111111111111
RETURN
Need code for DS1302 & BS2 Stamp
Hello Mark,
I am not sure if I can be of help here; but then I would like to suggest that you post this as well in the Parallax forum.
Best Regards,
I am not sure if I can be of help here; but then I would like to suggest that you post this as well in the Parallax forum.
Best Regards,
Raquel Malinis
Design and Development
Matrix Orbital
Design and Development
Matrix Orbital