the text wat to long to set in one message
Code:'paste here the above code SetTimeAndDate: '============= Setup: SetTime=hr.6 ' Determines 12/24 Hour mode If SetTime=1 then ' Regardless of 12/24 options, SetHour always ' contains the hours in 24 hour clock format ' otherwise there's twice the amount of work ' to keep track in the edit routines _hr=(hr>>4)&$01 ' if 12-hour mode else _hr=(hr>>4)&$03 ' if 24 hour mode endif _hr=_hr*10+(hr&$0F) If SetTime=1 then If hr.5=1 then If _hr<12 then _hr=hr+12 ' Add-in the AM/PM indicator else If _hr=12 then _hr=0 endif endif _Min=((Mins>>4)&$0F)*10+(Mins&$0F) _Sec=((Sec>>4)&$0F)*10+(sec&$0F) _yr=((yr>>4)&$0F)*10+(yr&$0F) _mon=((mon>>4)&$0F)*10+(mon&$0F) _day=((day>>4)&$0F)*10+(day&$0F) ' ' Setup Menu Loop ' --------------- CounterC=0 ' Set to Start of Setup (seven steps from 0 to 6) TimeOut=0 ' Zero the Time-Out counter SetupLoop: ' ' Now Display the Data ' -------------------- SetupDisplayLoop: ' ' 12/24 Hour Option ' ----------------- ' ' The Data-Entry Bit ' ------------------ SetupEntryLoop: 'datainput. ' ' Decrement(down) Button Pressed ' ------------------------ If DecButton=0 then ' ' 12/24 Clock Selection ' --------------------- If CounterC=0 then If SetTime=0 then SetTime=1 else SetTime=0 endif endif ' ' Decrement Hours ' --------------- If CounterC=1 then If _hr=0 then _hr=23 else _hr=_hr-1 endif endif ' ' Decrement Minutes ' ----------------- If CounterC=2 then If _Min=0 then _Min=59 else _Min=_Min-1 endif endif ' ' Decrement Seconds ' ----------------- ' Kinda overkill to include setting seconds, ' but if you got codespace to burn... If CounterC=3 then If _Sec=0 then _Sec=59 else _Sec=_Sec-1 endif endif gosub Pauseloop TimeOut=0 Goto SetUpDisplayLoop endif ' ' Increment(up) Button Pressed ' ------------------------ ' This is just like Decrement but opposite... If IncButton=0 then ' ' 12/24 Clock Selection ' --------------------- If CounterC=0 then If SetTime=1 then SetTime=0 else SetTime=1 endif endif ' ' Increment Hours ' --------------- If CounterC=1 then If _hr=>23 then _hr=0 else _hr=_hr+1 endif endif ' ' Increment Minutes ' ----------------- If CounterC=2 then If _min=>59 then _Min=0 else _Min=_Min+1 endif endif ' ' Increment Seconds ' ----------------- ' Kinda overkill to include setting seconds, ' but if you got codespace to burn... If CounterC=3 then If _Sec=>59 then _Sec=0 else _Sec=_Sec+1 endif endif gosub Pauseloop TimeOut=0 Goto SetupDisplayLoop endif ' ' Set Button Pressed ' ------------------ If setbutton =0 then CounterC=CounterC+1 ' Increment Menu Item TimeOut=0 endif If CounterC>3 then 'old menu counterC>6######################### ' Save Data if all edit items exhaused ' ' Save 12/24 Hours to BCD DS1307's Format ' --------------------------------------- CounterA=_hr If SetTime=1 then If CounterA>12 then CounterA=CounterA-12 If CounterA=0 then CounterA=12 endif Gosub ConvertBCD hr=CounterB ' Save the Hours Value If SetTime=1 then hr.6=1 ' Save the 12 Hour Mode Flag If _hr=>12 then hr.5=1 ' Save the 'PM' Flag endif ' ' Save Minutes ' ------------ CounterA=_min Gosub ConvertBCD MINs=CounterB ' ' Save Seconds ' ------------ CounterA=_sec Gosub ConvertBCD sec=CounterB ' ' Do the Business ' --------------- rtcwrite: I2CWrite DS_SDA, DS_SCL,$D0,$00,[sec,MINs,hr,RTCWDay,day,mon,yr,RTCCtrl] Gosub SetButtonRelease Goto ReDisplay endif Gosub SetButtonRelease Goto SetupLoop ' Loop for Next Menu Item ' ' Menu TimeOut Counter ' -------------------- gosub Segmentswrite2 TimeOut=TimeOut+1 'not jet working good If TimeOut>20000 then goto ReDisplay ' User paused too long ' Return User to Time & Date Display ' This will however bounce the User to the original ' Setup Menu start point if the DS1307 has not ' been initialised Goto SetupEntryLoop ' Loop for Button Press Pauseloop: 'some timedelay counter3=0 repeat pauseus 10 until counter3 > 50 return 'just a routine to make sure you didn't push the button by faulth '------------------------------------ SetButtonRelease: 'delay for button counter3=0 while setbutton=0 pauseus 10 Wend if counter3=>29 then repeat pauseus 10 until counter3 > 70 else goto loop endif Return FindDays: 'deleted Return DisplayMonth:'deleted DisplaySequence: 'deleted Return ' ' Subroutine Converts back to BCD ' ------------------------------- ' CounterA is the entry variable ' CounterB holds the converted BCD result on exit ConvertBCD: CounterB=CounterA DIG 1 CounterB=CounterB<<4 CounterB=CounterB+CounterA DIG 0 Return Redisplay: 'deleted return Am_or_Pm: 'deleted return coldstart: 'only started when rtc starts from cold '--xx-- _yr=0:_date =0:_mon =0:_day=0:_hr=0:_min=0:_sec=0 ' The constants below set the RTC to: 16:30:00 on 13-07-2003 _yr=$03 _mon=$07 _date=$13 _hr=$16 _sec=$00 _min=$30 I2CWrite DS_SDA, DS_SCL, $D0,$00,[_sec,_min,_hr,_day,_date,_mon,_yr,cntrl] Return




Bookmarks