Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 02:53 12 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : (micromite) adjusting for daylight saving

Author Message
vk7krj
Newbie

Joined: 15/01/2015
Location: Australia
Posts: 12
Posted: 02:08pm 11 Feb 2015
Copy link to clipboard 
Print this post

I have been trying for several days to crack this one, but it has so far defeated me. I have built a specialised timer for a community club SWMBO is a member of, all that is left to do now is make the real-time clock part of it adjust for (the stupidty of) "daylight saving".

I'm using a PCF8563 real time clock and I would like to add or subtract 1 hour to/from that whenever the front-panel switch attached to pin 42 is changed by the user. I tried:-

if pin(42) = 1 and if dst_flag = 0 then plus_one_hour
if pin(42) = 0 and if dst_flag = 1 then minus_one_hour

but it turns out I can't use that construct- I also can't use select...case as I am using a Mk1 micromite, so now I am stuck on how to format the decision.

My thinking is the 2 subroutines, "plus_one_hour" and "minus_one_hour" will do the setting and clearing of the flag and the changing of the time in the PFC8563. Problem there is I can't find any documentation on the structure of the $time string in MMbasic so I can select out the hour and change it.

Can anyone help a novice with hints or suggestions, perhaps a simpler way of doing this??

Thanks, Ken.


Ken, vk7krj
www.vk7krj.com
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 02:33pm 11 Feb 2015
Copy link to clipboard 
Print this post

  Quote  if pin(42) = 1 and if dst_flag = 0 then plus_one_hour
Assuming that dst_flag is a variable and plus_one_hour is a subroutine then it should work for you. How does it not work? What error message are you getting?

Also, from the manual describing TIME$:
  Quote  Returns the current time based on MMBasic's internal clock as a string in the form "HH:MM:SS" in 24 hour notation. For example, "14:30:00".


Geoff
Geoff Graham - http://geoffg.net
 
vk7krj
Newbie

Joined: 15/01/2015
Location: Australia
Posts: 12
Posted: 03:17pm 11 Feb 2015
Copy link to clipboard 
Print this post

Thanks for the quick reply Geoff, the error is


[113] If Pin(42) = 1 And if dst_flag = 0 Then plus_one_hour
Error: Incorrect expression syntax
>


You are correct in your assumptions, dst_flag is a variable and the other 2 are subs.
and my mistake on the $time question- I don't know how I missed that!
Ken, vk7krj
www.vk7krj.com
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5918
Posted: 03:23pm 11 Feb 2015
Copy link to clipboard 
Print this post

Try:
If Pin(42) = 1 And dst_flag = 0 Then plus_one_hour


I usually like to enclose the tests in brackets to be sure that the order is what I am expecting.

If (Pin(42) = 1) And (dst_flag = 0) Then plus_one_hour


Jim
VK7JH
MMedit   MMBasic Help
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9073
Posted: 03:30pm 11 Feb 2015
Copy link to clipboard 
Print this post

I agree with Jim - the syntax error is with the bit of your code that says "And If".
Everything SHOULD work as expected, once you change that line.
Smoke makes things work. When the smoke gets out, it stops!
 
vk7krj
Newbie

Joined: 15/01/2015
Location: Australia
Posts: 12
Posted: 03:34pm 11 Feb 2015
Copy link to clipboard 
Print this post

Ah- that fixed it, thanks Jim. The extra "if" I had in was what was breaking it- and a good tip on the brackets, worth remembering.

Ken, vk7krj
Ken, vk7krj
www.vk7krj.com
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 07:45pm 15 Feb 2015
Copy link to clipboard 
Print this post

Hi Ken;

The new revision, 4.6B, has the ability to directly read and write to the registers in the real time clock.

See the "RTC GETREG" and "RTC SETREG" commands.

Note! These registers use a king of BCD, Binary Coded Decimal.

Here is some demo code:

' Test Clock Registers
' TestClocRegisters.bas
PRINT CHR$(27);"[2J"; ' Clear Screen
Main:
PRINT CHR$(27);"[H"; ' Curser to home
RTC GETTIME
T$=TIME$
RTC GETREG 4,H
RTC GETREG 3,M
RTC GETREG 2,S
print T$
PRINT " ";RIGHT$(" "+STR$(H),3);" : ";
PRINT " ";RIGHT$(" "+STR$(M),3);" : ";
PRINT " ";RIGHT$(" "+STR$(S),3)
PRINT " ";BIN$(H,8);" : ";BIN$(M,8);" : ";BIN$(S,8)
PRINT "VL HH hhhh : MMM mmmm : SSS ssss"
PRINT " ";BIN$((H AND 128)/128,1);" ";
PRINT BIN$((H AND 48)/ 16,2);" ";
PRINT BIN$((H AND 15)/ 1,4);" : ";
PRINT BIN$((M AND 112)/ 16,3);" ";
PRINT BIN$((M AND 15)/ 1,4);" : ";
PRINT BIN$((S AND 112)/ 16,3);" ";
PRINT BIN$((S AND 15)/ 1,4);" "
PAUSE 250
GOTO Main


redrok
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 07:56am 22 Feb 2015
Copy link to clipboard 
Print this post

Hi vk7krj;

I have a more complete example program to play with the PCF8563 clock.
' Test Clock Registers
' TestClocRegisters.bas
' PCF8563
' MM Chat fails, Use TeraTerm
OPTION DISPLAY 24,80
PRINT CHR$(27);"[2J"; ' Clear Screen
Mode=4 ' Edit register 4, Hours
Main:
' Set local clock conventionally
RTC GETTIME
' Extract time registers bytes
RTC GETREG 8,Y ' reg 8
RTC GETREG 7,Mth ' reg 7
RTC GETREG 6,WD ' reg 6
RTC GETREG 5,D ' reg 5
RTC GETREG 4,Hr ' reg 4
RTC GETREG 3,Min ' reg 3
RTC GETREG 2,S ' reg 2
' Show that the "x" bits are not stable
DisplayFirstHalf
' Eliminate the "x" bits
Y =Y AND &b11111111 ' 255 reg 8
Cen=Mth AND &b10000000 ' 128 Century bit
Mth=Mth AND &b00011111 ' 31 reg 7
WD =WD AND &b00000111 ' 7 reg 6
D =D AND &b00111111 ' 63 reg 5
Hr =Hr AND &b00111111 ' 63 reg 4
Min=MiN AND &b01111111 ' 127 reg 3
Low=S AND &b10000000 ' 128 Low Voltage bit Can be only cleared
S =S AND &b01111111 ' 127 reg 2
DisplaySecondHalf
PAUSE 100
PRINT "8 7 6 5 4 3 2 C U D T Q Mode =";Mode;" ? ";" ";CHR$(27);"[1D";
Q$="":Q$=INKEY$:PRINT UCASE$(Q$);
IF UCASE$(Q$)="8" THEN Mode=8
IF UCASE$(Q$)="7" THEN Mode=7
IF UCASE$(Q$)="6" THEN Mode=6
IF UCASE$(Q$)="5" THEN Mode=5
IF UCASE$(Q$)="4" THEN Mode=4
IF UCASE$(Q$)="3" THEN Mode=3
IF UCASE$(Q$)="2" THEN Mode=2
IF UCASE$(Q$)="C" THEN Cen=Cen XOR &b10000000:RTC SETREG 7,Cen+(Mth AND &b00011111)
' IF UCASE$(Q$)="L" THEN Low=Low XOR &b10000000:RTC SETREG 2,Low+(S AND &b01111111)
IF UCASE$(Q$)="U" THEN Increment
IF UCASE$(Q$)="D" THEN Decrement
IF UCASE$(Q$)="T" THEN DateTime
IF UCASE$(Q$)="Q" THEN END
GOTO Main

SUB Increment
IF Mode=8 THEN
IF Y<9*16+8 THEN Y=Y+1
IF (Y AND 15)>9 THEN Y=Y+6
RTC SETREG 8,Y
ELSEIF Mode=7 THEN
IF Mth<1*16+2 THEN Mth=Mth+1
IF (Mth AND 15)>9 THEN Mth=Mth+6
RTC SETREG 7,Cen+(Mth AND &b00011111)
ELSEIF Mode=6 THEN
IF WD<7 THEN WD=WD+1
RTC SETREG 6,WD
ELSEIF Mode=5 THEN
IF D<3*16+1 THEN D=D+1
IF (D AND 15)>9 THEN D=D+6
RTC SETREG 5,D
ELSEIF Mode=4 THEN
IF Hr<2*16+3 THEN Hr=Hr+1
IF (Hr AND 15)>9 THEN Hr=Hr+6
RTC SETREG 4,Hr
ELSEIF Mode=3 THEN
IF Min<5*16+9 THEN Min=Min+1
IF (Min AND 15)>9 THEN Min=Min+6
RTC SETREG 3,Min
ELSEIF Mode=2 THEN
IF S<5*16+9 THEN S=S+1
IF (S AND 15)>9 THEN S=S+6
RTC SETREG 2,Low+S
ENDIF
END SUB

SUB Decrement
IF Mode=8 THEN
IF Y>0 THEN Y=Y-1
IF (Y AND 15)>9 THEN Y=Y-6
RTC SETREG 8,Y
ELSEIF Mode=7 THEN
IF Mth>1 THEN Mth=Mth-1
IF (Mth AND 15)>9 THEN Mth=Mth-6
RTC SETREG 7,Cen+(Mth AND &b00011111)
ELSEIF Mode=6 THEN
IF WD>1 THEN WD=WD-1
RTC SETREG 6,WD
ELSEIF Mode=5 THEN
IF D>1 THEN D=D-1
IF (D AND 15)>9 THEN D=D-6
RTC SETREG 5,D
ELSEIF Mode=4 THEN
IF Hr>0 THEN Hr=Hr-1
IF (Hr AND 15)>9 THEN Hr=Hr-6
RTC SETREG 4,Hr
ELSEIF Mode=3 THEN
IF Min>0 THEN Min=Min-1
IF (Min AND 15)>9 THEN Min=Min-6
RTC SETREG 3,Min
ELSEIF Mode=2 THEN
IF S>0 THEN S=S-1
IF (S AND 15)>9 THEN S=S-6
RTC SETREG 2,Low+S
ENDIF
END SUB

SUB DateTime
PRINT
INPUT "YY,MM,DD,HH,MM,SS ";DT8,DT7,DT5,DT4,DT3,DT2
RTC SETTIME DT8,DT7,DT5,DT4,DT3,DT2
END SUB

SUB DisplayFirstHalf
PRINT CHR$(27);"[H";' Curser to home
PRINT RIGHT$(DATE$,4)+MID$(DATE$,3,4)+LEFT$(DATE$,2)+" "+TIME$
PRINT " Year 8- Month 7-WeekDay 6- Day 5";
PRINT " Hours 4:Minites 3:Seconds 2"
PRINT "Decimal ";RIGHT$(" "+STR$(Y ),3);
PRINT "- " ;RIGHT$(" "+STR$(Mth),3);
PRINT "- " ;RIGHT$(" "+STR$(WD ),3);
PRINT "- " ;RIGHT$(" "+STR$(D ),3);
PRINT " " ;RIGHT$(" "+STR$(Hr ),3);
PRINT ": " ;RIGHT$(" "+STR$(Min),3);
PRINT ": " ;RIGHT$(" "+STR$(S ),3)
PRINT " ";BIN$(Y ,8);
PRINT "- " ;BIN$(Mth,8);
PRINT "- " ;BIN$(WD ,8);
PRINT "- " ;BIN$(D ,8);
PRINT " " ;BIN$(Hr ,8);
PRINT ": " ;BIN$(Min,8);
PRINT ": " ;BIN$(S ,8)
END SUB

SUB DisplaySecondHalf
PRINT "Decimal ";RIGHT$(" "+STR$( Y ),3);
PRINT "- " ;RIGHT$(" "+STR$((Cen AND &b10000000)+Mth),3);
PRINT "- " ;RIGHT$(" "+STR$( WD ),3);
PRINT "- " ;RIGHT$(" "+STR$( D ),3);
PRINT " " ;RIGHT$(" "+STR$( Hr ),3);
PRINT ": " ;RIGHT$(" "+STR$( Min ),3);
PRINT ": " ;RIGHT$(" "+STR$((Low AND &b10000000)+S ),3)
PRINT "BCD ";BIN$( Y ,8);
PRINT "- " ;BIN$((Cen AND &b10000000)+Mth,8);
PRINT "- " ;BIN$( WD ,8);
PRINT "- " ;BIN$( D ,8);
PRINT " " ;BIN$( Hr ,8);
PRINT ": " ;BIN$( Min ,8);
PRINT ": " ;BIN$((Low AND &b10000000)+S ,8)
PRINT " YYYY yyyy-CxxM mmmm-xxxx xWWW-xxDD dddd";
PRINT " xxHH hhhh:xMMM mmmm:LSSS ssss"
PRINT "BCD " ;BIN$((Y AND &b11110000)/ 16,4);
PRINT " " ;BIN$( Y AND &b00001111 ,4);
PRINT "-" ;BIN$((Cen AND &b10000000)/128,1);
PRINT " " ;BIN$((Mth AND &b00010000)/ 16,1);
PRINT " " ;BIN$( Mth AND &b00001111 ,4);
PRINT "- ";BIN$( WD AND &b00000111 ,3);
PRINT "- " ;BIN$((D AND &b01110000)/ 16,2);
PRINT " " ;BIN$( D AND &b00001111 ,4);
PRINT " " ;BIN$((Hr AND &b01110000)/ 16,2);
PRINT " " ;BIN$( Hr AND &b00001111 ,4);
PRINT ": " ;BIN$((Min AND &b01110000)/ 16,3);
PRINT " " ;BIN$( Min AND &b00001111 ,4);
PRINT ":" ;BIN$((Low AND &b10000000)/128,1); ' Under Voltage can be only cleared
PRINT "" ;BIN$((S AND &b01110000)/ 16,3);
PRINT " " ;BIN$( S AND &b00001111 ,4)
PRINT "BCD ";INT(Y /16);INT(Y MOD 16);
PRINT " - ";INT(Mth/16);INT(Mth MOD 16);
PRINT " - " ;INT(WD MOD 16);
PRINT " - " ;INT(D /16);INT(D MOD 16);
PRINT " ";INT(Hr /16);INT(Hr MOD 16);
PRINT " : ";INT(Min/16);INT(Min MOD 16);
PRINT " : ";INT(S /16);INT(S MOD 16)
END SUB

Note! This fails on MM Chat. I suspect the buffers are overrunning.
TeraTerm works well. Especially when sending VT100 escape sequences.

The program is severely "bloated" because I wanted to test all aspects of the Date & Time functions. However, I did nothing with the timer/alarm functions. But they work similarly to the Date & Time functions.

Watch the unused "x" bits which change state at will. Go figure? They do it.
The interface is through the single character INKEY$ command.
8 through 2 selects the register and is indicated by "Mode = ".
U and D increments or decrements the register.
C toggles the Century bit.
T runs the conventional "RTC SETTIME" command.
Q Quits or Stops the program.

Have fun!
redrok
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5918
Posted: 10:30am 22 Feb 2015
Copy link to clipboard 
Print this post

  redrok said  
Note! This fails on MM Chat. I suspect the buffers are overrunning.
TeraTerm works well. Especially when sending VT100 escape sequences.


You're correct. MM Chat is very slow in VT100 mode.

For testing you could put a bigger delay in the main loop to give MM Chat time to catchup.

TeraTerm is far superior for serious terminal work.

Jim
VK7JH
MMedit   MMBasic Help
 
vk7krj
Newbie

Joined: 15/01/2015
Location: Australia
Posts: 12
Posted: 11:10am 22 Feb 2015
Copy link to clipboard 
Print this post

Thanks Redrok, I will study your code and apply it to mine when I get back to the project- I have had to put it down for a while to get on with other things.

Ken.
Ken, vk7krj
www.vk7krj.com
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024