LCD and RS1302
mverhoeven
Posts: 1
I successfully connected to·my Basic Stamp2 and LCD 2*20 and a Timer IC RS1302
I want to get the time on the display, but that doesn't work.
I do not know how to bring the content from Seconds,Minutes,Hours,Date,Month,Year,Year into the var "Char".
Can sombody help
thanks
Marcel
Here is my code:
' =========================================================================
' File...... LCD 2 x20 and Date_Time.bs2
' Purpose... Parallel LCD Display and Date and Time
' Author.... Marcel Verhoeven
' E-mail.... marcel.verhoeven3@telenet.be
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
E PIN 0 ' Enable Pin For LCD
RW PIN 2 ' R/W Pin For LCD
RS PIN 3 ' LCD Register Select
' 0 = Instruction, 1 = Text
'
[noparse][[/noparse] Variables ]
char VAR Byte ' Character To Send To LCD
inst VAR char ' Induction To Send To LCD
index VAR Word ' Character Pointer
temp VAR Byte ' Temp Variable
'
[noparse][[/noparse] EEPROM Data ]
DATA "Marcel en Kristien· Veldegemsestraat 110" ' Message To Send To LCD
' Date and time:· DS1302_1.BS2. *
'***************************************************************************
DATA (49)
RTCCmd VAR Byte
Clk CON 8
Dta CON 9
RTCReset CON 10
Seconds VAR Byte
Minutes VAR Byte
Hours VAR Byte
Date VAR Byte
Month VAR Byte
Year VAR Byte
I VAR Byte
'Define Constants
SecReg CON %00000
MinReg CON %00001
HrsReg CON %00010
DateReg CON %00011
MonReg CON %00100
YrReg CON %00110
CtrlReg CON %00111
BrstReg CON %11111
'
[noparse][[/noparse] Initialization LCD (PIN= 0---7) and RS1302(Pin= 8,9,10 ]
Initialize:
LOW RW ' Set LCD To Write Mode
OUTS = %0000000000000000 ' Set All Output Low
DIRS = %0000011111111111 ' Set I/O Direction
GOSUB Init_Lcd ' Initialize The LCD Display
'
[noparse][[/noparse] Program Code LCD Main ]
Main:
FOR temp = 0 TO 39 ' 28 Characters
IF temp = 20 THEN ' Check For End Of Line
GOSUB Next_Line ' Jump To Next Line
ENDIF
READ temp, char ' Read Next Character From EEPROM
GOSUB Send_Text ' Send Character To LCD Display
NEXT
PAUSE 3000
Inst = %00000001 ' Clears LCD
GOSUB Send_Inst
GOSUB Date_time
GOTO Main
END
'
[noparse][[/noparse] Subroutines LCD Init]
Init_Lcd:
Inst = %00000001 ' Clears LCD
GOSUB Send_Inst
PAUSE 200
OUTS = %00110000 ' Reset The LCD
PULSOUT E,1 ' Send Command Three Times
PAUSE 10
PULSOUT E,1
PAUSE 10
PULSOUT E,1
PAUSE 10
OUTS = %00100000 ' Set To 4-bit Operation
PULSOUT E,1
Inst = %00101000 ' Function Set (2-Line Mode)
GOSUB Send_Inst
Inst = %00001110 ' Turn On Cursor
GOSUB Send_Inst
Inst = %00000110 ' Set Auto-Increment
GOSUB Send_Inst
Inst = %00000001 ' Clears LCD
GOSUB Send_Inst
Inst = 14 ' Set Cursor To Underline
GOSUB Send_Inst
RETURN
'
[noparse][[/noparse] Subroutines LCD Send Instruction]
Send_Inst:
LOW RS ' Set Instruction Mode
OUTB = Inst.HIGHNIB ' Send High Nibble
PULSOUT E,1
OUTB = Inst.LOWNIB ' Send Low Nibble
PULSOUT E,1
HIGH RS ' Set LCD Back To Text Mode
RETURN
'
[noparse][[/noparse] Subroutines LCD Send text]
Send_Text:
OUTB = Char.HIGHNIB ' Send High Nibble
PULSOUT E,1
OUTB = char.LOWNIB ' Send Low Nibble
PULSOUT E,1
PAUSE 100
RETURN
'
[noparse][[/noparse] Subroutines LCD Next Line]
Next_Line:
Inst = 128+64 ' Move Cursor To Line 2
GOSUB Send_Inst
RETURN
'
[noparse][[/noparse] Subroutines Date and Time RS1302]
Date_Time:
GOSUB ReadRTCBurst
DEBUG HOME, "Tijd:· ", DEC Hours.HIGHNIB,DEC Hours.LOWNIB,":",DEC Minutes.HIGHNIB
DEBUG DEC Minutes.LOWNIB,":",DEC Seconds.HIGHNIB,DEC Seconds.LOWNIB, CR
DEBUG "Datum: ",DEC Date.HIGHNIB, DEC Date.LOWNIB,"/"
DEBUG DEC Month.HIGHNIB,DEC Month.LOWNIB,"/",DEC Year.HIGHNIB, DEC Year.LOWNIB,CR
RETURN
'
[noparse][[/noparse] Subroutines Date and Time RS1302 ReadRTCBurst]
ReadRTCBurst:
HIGH RTCReset
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Year,Year]
LOW RTCReset
RETURN
I want to get the time on the display, but that doesn't work.
I do not know how to bring the content from Seconds,Minutes,Hours,Date,Month,Year,Year into the var "Char".
Can sombody help
thanks
Marcel
Here is my code:
' =========================================================================
' File...... LCD 2 x20 and Date_Time.bs2
' Purpose... Parallel LCD Display and Date and Time
' Author.... Marcel Verhoeven
' E-mail.... marcel.verhoeven3@telenet.be
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
E PIN 0 ' Enable Pin For LCD
RW PIN 2 ' R/W Pin For LCD
RS PIN 3 ' LCD Register Select
' 0 = Instruction, 1 = Text
'
[noparse][[/noparse] Variables ]
char VAR Byte ' Character To Send To LCD
inst VAR char ' Induction To Send To LCD
index VAR Word ' Character Pointer
temp VAR Byte ' Temp Variable
'
[noparse][[/noparse] EEPROM Data ]
DATA "Marcel en Kristien· Veldegemsestraat 110" ' Message To Send To LCD
' Date and time:· DS1302_1.BS2. *
'***************************************************************************
DATA (49)
RTCCmd VAR Byte
Clk CON 8
Dta CON 9
RTCReset CON 10
Seconds VAR Byte
Minutes VAR Byte
Hours VAR Byte
Date VAR Byte
Month VAR Byte
Year VAR Byte
I VAR Byte
'Define Constants
SecReg CON %00000
MinReg CON %00001
HrsReg CON %00010
DateReg CON %00011
MonReg CON %00100
YrReg CON %00110
CtrlReg CON %00111
BrstReg CON %11111
'
[noparse][[/noparse] Initialization LCD (PIN= 0---7) and RS1302(Pin= 8,9,10 ]
Initialize:
LOW RW ' Set LCD To Write Mode
OUTS = %0000000000000000 ' Set All Output Low
DIRS = %0000011111111111 ' Set I/O Direction
GOSUB Init_Lcd ' Initialize The LCD Display
'
[noparse][[/noparse] Program Code LCD Main ]
Main:
FOR temp = 0 TO 39 ' 28 Characters
IF temp = 20 THEN ' Check For End Of Line
GOSUB Next_Line ' Jump To Next Line
ENDIF
READ temp, char ' Read Next Character From EEPROM
GOSUB Send_Text ' Send Character To LCD Display
NEXT
PAUSE 3000
Inst = %00000001 ' Clears LCD
GOSUB Send_Inst
GOSUB Date_time
GOTO Main
END
'
[noparse][[/noparse] Subroutines LCD Init]
Init_Lcd:
Inst = %00000001 ' Clears LCD
GOSUB Send_Inst
PAUSE 200
OUTS = %00110000 ' Reset The LCD
PULSOUT E,1 ' Send Command Three Times
PAUSE 10
PULSOUT E,1
PAUSE 10
PULSOUT E,1
PAUSE 10
OUTS = %00100000 ' Set To 4-bit Operation
PULSOUT E,1
Inst = %00101000 ' Function Set (2-Line Mode)
GOSUB Send_Inst
Inst = %00001110 ' Turn On Cursor
GOSUB Send_Inst
Inst = %00000110 ' Set Auto-Increment
GOSUB Send_Inst
Inst = %00000001 ' Clears LCD
GOSUB Send_Inst
Inst = 14 ' Set Cursor To Underline
GOSUB Send_Inst
RETURN
'
[noparse][[/noparse] Subroutines LCD Send Instruction]
Send_Inst:
LOW RS ' Set Instruction Mode
OUTB = Inst.HIGHNIB ' Send High Nibble
PULSOUT E,1
OUTB = Inst.LOWNIB ' Send Low Nibble
PULSOUT E,1
HIGH RS ' Set LCD Back To Text Mode
RETURN
'
[noparse][[/noparse] Subroutines LCD Send text]
Send_Text:
OUTB = Char.HIGHNIB ' Send High Nibble
PULSOUT E,1
OUTB = char.LOWNIB ' Send Low Nibble
PULSOUT E,1
PAUSE 100
RETURN
'
[noparse][[/noparse] Subroutines LCD Next Line]
Next_Line:
Inst = 128+64 ' Move Cursor To Line 2
GOSUB Send_Inst
RETURN
'
[noparse][[/noparse] Subroutines Date and Time RS1302]
Date_Time:
GOSUB ReadRTCBurst
DEBUG HOME, "Tijd:· ", DEC Hours.HIGHNIB,DEC Hours.LOWNIB,":",DEC Minutes.HIGHNIB
DEBUG DEC Minutes.LOWNIB,":",DEC Seconds.HIGHNIB,DEC Seconds.LOWNIB, CR
DEBUG "Datum: ",DEC Date.HIGHNIB, DEC Date.LOWNIB,"/"
DEBUG DEC Month.HIGHNIB,DEC Month.LOWNIB,"/",DEC Year.HIGHNIB, DEC Year.LOWNIB,CR
RETURN
'
[noparse][[/noparse] Subroutines Date and Time RS1302 ReadRTCBurst]
ReadRTCBurst:
HIGH RTCReset
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Year,Year]
LOW RTCReset
RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
http://forums.parallax.com/showthread.php?p=531080
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·