DS 1302 programing problems < can't get this freaking thing working, need some help
Igor_Rast
Posts: 357
hi there < Ive been working on how to set the time and date of the 1302 tru a lcd display and 4 buttons . , I am using a 20*4 lcd to display it . Im , working on creating a menu wich this time setting has to be part off.
when I do the set date command all clocks go to 000000. so somthing not good , my best guess is that it has somthing to do with the format of the variables i want to program , there decimal values . how do I convert it or , what's happening here
program runs like . normal shows clock , when buton 3 is pressed it goed into instellseq to get the variables and then setts them
pleas HELPPPP
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
led1 = 0
led2 = 1
buton1 =12 {input buttons up }
buton2 =11 {input buttons down}
buton3 =10 {input buttons enter }
buton4 =9 {input buttons return }
RS = 25 {lcd control}
RW = 26 {lcd control}
E = 27 {lcd control}
DBLow = 28 {lcd control}
DBHigh = 31 {lcd control}
OBJ
LCD : "LCD_20x4"
rtc : "DS1302_full"
VAR
long stack[30],idx,tc
byte hour, minute, second, day, month, year, dow,out ,cmd {time ic variables}
byte nstr[64]
byte _month, _day, _year, _dow, _hour, _min, _sec
PUB main
rtc.init(20,19,18)
LCD.Init( E, RS, RW, DBHigh, DBLow ) {LCD init}
LCD.usDelay( 5_000 ) {LCD init}
LCD.Clear
repeat
rtc.readTime( @hour, @minute, @second ) 'read time from DS1302
rtc.readDate( @day, @month, @year, @dow ) 'read date from DS1302
LCD.Clear
LCD.RawSetPos( $01 ) {display time on first row lcd}
LCD.PrintStr( decx(hour,2) )
LCD.Printchr( ":" )
LCD.PrintStr( decx(minute,2) )
LCD.Printchr( ":")
LCD.PrintStr( decx(second,2) )
LCD.RawSetPos( $0B ) {display date on first row lcd}
LCD.PrintStr( decx(day,2) )
LCD.Printchr( "/" )
LCD.PrintStr( decx(month,2) )
LCD.Printchr( "/")
LCD.PrintStr( decx(year,2))
if ina[buton3]==1
waitcnt (clkfreq / 14+ cnt)
instelseq
waitcnt( clkfreq + cnt )
PUB instelseq
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Maand" ))
instel(_Month,12) {Maand instellen }
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Dag " ))
instel(_day,31) {Dag instellen }
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Jaar " )) {Jaar instellen }
instel(_year,99)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("DoW " )) {Dag vd week instellen }
instel(_dow,7)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Uur " )) {Uur instellen }
instel(_hour,24)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Min " )) {min instellen }
instel(_min,60)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Sec " )) {sec instellen }
instel(_sec,60)
rtc.config
rtc.setDatetime( _month, _day, _year, _dow, _hour, _min, _sec )
return
PUB instel (Variabele,schaal)
variabele:=variabele + 1 {start at 1}
repeat
if ina[buton1]==1 { down scroll button}
Variabele:= Variabele + 1
if Variabele == (schaal+1) {menu size }
Variabele := 0
waitcnt (clkfreq / 14+ cnt)
if ina[buton2]==1 {up scroll button }
Variabele:=Variabele - 1
if Variabele == 0
Variabele:= schaal {menu size }
waitcnt (clkfreq / 14+ cnt)
LCD.RawSetPos( $5D ) {display variable on lcd}
LCD.PrintStr( decx(Variabele,2) )
LCD.usDelay( 200_000)
if ina[buton3]==1
waitcnt (clkfreq / 14+ cnt)
return
PUB decx(value, digits) | div
'' Returns pointer to zero-padded, signed-decimal string
'' -- if value is negative, field width is digits+1
clrstr(@nstr, 64)
digits := 1 #> digits <# 10
if (value < 0) ' negative value?
-value ' yes, make positive
nstr[idx++] := "-" ' and print sign indicator
div := 1_000_000_000 ' initialize divisor
if digits < 10 ' less than 10 digits?
repeat (10 - digits) ' yes, adjust divisor
div /= 10
value //= (div * 10) ' truncate unused digits
repeat digits
nstr[idx++] := (value / div + "0") ' convert digit to ASCII
value //= div ' update value
div /= 10 ' update divisor
return @nstr
PRI clrstr(strAddr, size)
' Clears string at strAddr
' -- also resets global character pointer (idx)
bytefill(strAddr, 0, size) ' clear string to zeros
idx~ ' reset index
when I do the set date command all clocks go to 000000. so somthing not good , my best guess is that it has somthing to do with the format of the variables i want to program , there decimal values . how do I convert it or , what's happening here
program runs like . normal shows clock , when buton 3 is pressed it goed into instellseq to get the variables and then setts them
pleas HELPPPP
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
led1 = 0
led2 = 1
buton1 =12 {input buttons up }
buton2 =11 {input buttons down}
buton3 =10 {input buttons enter }
buton4 =9 {input buttons return }
RS = 25 {lcd control}
RW = 26 {lcd control}
E = 27 {lcd control}
DBLow = 28 {lcd control}
DBHigh = 31 {lcd control}
OBJ
LCD : "LCD_20x4"
rtc : "DS1302_full"
VAR
long stack[30],idx,tc
byte hour, minute, second, day, month, year, dow,out ,cmd {time ic variables}
byte nstr[64]
byte _month, _day, _year, _dow, _hour, _min, _sec
PUB main
rtc.init(20,19,18)
LCD.Init( E, RS, RW, DBHigh, DBLow ) {LCD init}
LCD.usDelay( 5_000 ) {LCD init}
LCD.Clear
repeat
rtc.readTime( @hour, @minute, @second ) 'read time from DS1302
rtc.readDate( @day, @month, @year, @dow ) 'read date from DS1302
LCD.Clear
LCD.RawSetPos( $01 ) {display time on first row lcd}
LCD.PrintStr( decx(hour,2) )
LCD.Printchr( ":" )
LCD.PrintStr( decx(minute,2) )
LCD.Printchr( ":")
LCD.PrintStr( decx(second,2) )
LCD.RawSetPos( $0B ) {display date on first row lcd}
LCD.PrintStr( decx(day,2) )
LCD.Printchr( "/" )
LCD.PrintStr( decx(month,2) )
LCD.Printchr( "/")
LCD.PrintStr( decx(year,2))
if ina[buton3]==1
waitcnt (clkfreq / 14+ cnt)
instelseq
waitcnt( clkfreq + cnt )
PUB instelseq
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Maand" ))
instel(_Month,12) {Maand instellen }
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Dag " ))
instel(_day,31) {Dag instellen }
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Jaar " )) {Jaar instellen }
instel(_year,99)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("DoW " )) {Dag vd week instellen }
instel(_dow,7)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Uur " )) {Uur instellen }
instel(_hour,24)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Min " )) {min instellen }
instel(_min,60)
LCD.Clear
LCD.RawSetPos( $55 )
LCD.PrintStr( string("Sec " )) {sec instellen }
instel(_sec,60)
rtc.config
rtc.setDatetime( _month, _day, _year, _dow, _hour, _min, _sec )
return
PUB instel (Variabele,schaal)
variabele:=variabele + 1 {start at 1}
repeat
if ina[buton1]==1 { down scroll button}
Variabele:= Variabele + 1
if Variabele == (schaal+1) {menu size }
Variabele := 0
waitcnt (clkfreq / 14+ cnt)
if ina[buton2]==1 {up scroll button }
Variabele:=Variabele - 1
if Variabele == 0
Variabele:= schaal {menu size }
waitcnt (clkfreq / 14+ cnt)
LCD.RawSetPos( $5D ) {display variable on lcd}
LCD.PrintStr( decx(Variabele,2) )
LCD.usDelay( 200_000)
if ina[buton3]==1
waitcnt (clkfreq / 14+ cnt)
return
PUB decx(value, digits) | div
'' Returns pointer to zero-padded, signed-decimal string
'' -- if value is negative, field width is digits+1
clrstr(@nstr, 64)
digits := 1 #> digits <# 10
if (value < 0) ' negative value?
-value ' yes, make positive
nstr[idx++] := "-" ' and print sign indicator
div := 1_000_000_000 ' initialize divisor
if digits < 10 ' less than 10 digits?
repeat (10 - digits) ' yes, adjust divisor
div /= 10
value //= (div * 10) ' truncate unused digits
repeat digits
nstr[idx++] := (value / div + "0") ' convert digit to ASCII
value //= div ' update value
div /= 10 ' update divisor
return @nstr
PRI clrstr(strAddr, size)
' Clears string at strAddr
' -- also resets global character pointer (idx)
bytefill(strAddr, 0, size) ' clear string to zeros
idx~ ' reset index
Comments
Alternatively you could return the value from the method and assign it accordingly.
this should help when posting code
thanks for the post, I knew it was somthing silly. just changes that and it work , thanks again .
ill sure be using this for to complete the furter project . hope someone can help me
next stop
building an fan controler to control te speed of an ac 230 volt single fase fan
anyone have some info ?
thanks
Gringo INc