OSDN Git Service

bug bug bug...
[fast-forth/master.git] / MSP430-FORTH / RTC.f
1 ; --------------------
2 ; RTC_B.f
3 ; --------------------
4
5 \ Copyright (C) <2016>  <J.M. THOORENS>
6 \
7 \ This program is free software: you can redistribute it and/or modify
8 \ it under the terms of the GNU General Public License as published by
9 \ the Free Software Foundation, either version 3 of the License, or
10 \ (at your option) any later version.
11 \
12 \ This program is distributed in the hope that it will be useful,
13 \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14 \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 \ GNU General Public License for more details.
16 \
17 \ You should have received a copy of the GNU General Public License
18 \ along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 \ REGISTERS USAGE
22 \ R4 to R7 must be saved before use and restored after
23 \ scratch registers Y to S are free for use
24 \ under interrupt, IP is free for use
25
26 \ PUSHM order : PSP,TOS, IP,  S,  T,  W,  X,  Y, R7, R6, R5, R4
27 \ example : PUSHM IP,Y
28 \
29 \ POPM  order :  R4, R5, R6, R7,  Y,  X,  W,  T,  S, IP,TOS,PSP
30 \ example : POPM Y,IP
31
32 \ ASSEMBLER conditionnal usage after IF UNTIL WHILE : S< S>= U< U>= 0= 0<> 0>=
33 \ ASSEMBLER conditionnal usage before GOTO ?GOTO     : S< S>= U< U>= 0= 0<> <0 
34
35 \ FORTH conditionnal usage after IF UNTIL WHILE : 0= 0< = < > U<
36
37
38
39 \ routines RTC for MSP430fr5xxx and MSP430FR6xxx families
40 \ target must have a LF_XTAL 32768Hz.
41
42 \ compile DTCforthMSP430FR5xxx.asm with the switch LF_XTAL set to ON (uncommment the line).
43
44 \ use :
45 \ to set date, type : dd mm yyyy DATE!
46 \ to view date, type DATE?
47 \ to set time, type : hh mm ss TIME!, or hh mm TIME!
48 \ to view time, type TIME?
49  
50 \ allow to write on a SD_Card file with a valid date and a valid time
51
52 \ ECHO      ; if an error occurs during download, uncomment this line then download again
53
54     \
55
56 CODE MAX    \    n1 n2 -- n3       signed maximum
57             CMP     @PSP,TOS    \ n2-n1
58             S<      ?GOTO FW1   \ n2<n1
59 BW1         ADD     #2,PSP
60             MOV     @IP+,PC
61 ENDCODE
62     \
63
64 CODE MIN    \    n1 n2 -- n3       signed minimum
65             CMP     @PSP,TOS     \ n2-n1
66             S<      ?GOTO BW1    \ n2<n1
67 FW1         MOV     @PSP+,TOS
68             MOV     @IP+,PC
69 ENDCODE
70     \
71
72 : U.R                       \ u n --           display u unsigned in n width
73   >R  <# 0 # #S #>  
74   R> OVER - 0 MAX SPACES TYPE
75 ;
76     \
77 CODE DATE?
78     SUB     #6,PSP
79     MOV     TOS,4(PSP)
80     BEGIN
81         BIT.B #RTCRDY,&RTCCTL1  \ test RTCRDY flag
82     0<> UNTIL                   \ wait until RTCRDY high
83     MOV     &RTCYEARL,2(PSP)    \ year
84     MOV.B   &RTCMON,TOS
85     MOV     TOS,0(PSP)          \ month
86     MOV.B   &RTCDAY,TOS         \ day
87 COLON
88     2 U.R $2F EMIT
89     2 U.R $2F EMIT . 
90 ;
91     \
92 : DATE!
93 DEPTH 2 > IF
94     HI2LO
95     MOV     TOS,&RTCYEARL   \ year
96     MOV.B   @PSP,&RTCMON    \ month     \ @PSP+ don't work because byte format !
97     MOV.B   2(PSP),&RTCDAY  \ day       \ @PSP+ don't work because byte format !
98     ADD     #4,PSP
99     MOV     @PSP+,TOS       \
100     LO2HI
101 THEN
102     ." we are on " DATE? 
103 ;
104     \
105 CODE TIME?
106     SUB     #6,PSP
107     MOV     TOS,4(PSP)      \ save TOS
108     BEGIN
109         BIT.B #RTCRDY,&RTCCTL1 \
110     0<> UNTIL               \ wait until RTCRDY high
111     MOV.B   &RTCSEC,TOS
112     MOV     TOS,2(PSP)      \ seconds
113     MOV.B   &RTCMIN,TOS
114     MOV     TOS,0(PSP)      \ minutes
115     MOV.B   &RTCHOUR,TOS    \ hours
116 COLON
117     2 U.R $3A EMIT 
118     2 U.R $3A EMIT 2 U.R 
119 ;
120     \
121 : TIME!
122 DEPTH 1 > IF
123     DEPTH 2 = IF 0 THEN     \ to allow "hour min TIME!" scheme
124     HI2LO
125     MOV     TOS,&RTCSEC     \ seconds
126     MOV.B   @PSP,&RTCMIN    \ minutes   \ @PSP+ don't work because byte format !
127     MOV.B   2(PSP),&RTCHOUR \ hours     \ @PSP+ don't work because byte format !
128     ADD     #4,PSP
129     MOV     @PSP+,TOS       \
130     LO2HI
131 THEN
132     ." it is " TIME? 
133 ;
134     \
135 CREATE ABUF 20 ALLOT
136     \
137 : GET_TIME
138     ECHO
139     CR CR ."    DATE (DMY): "
140     ABUF ABUF 20 (ACCEPT) EVALUATE CR 3 SPACES DATE!
141     CR CR ."    TIME (HMS or HM): "
142     ABUF ABUF 20 (ACCEPT) EVALUATE CR 3 SPACES TIME!
143     CR
144     HI2LO
145     MOV #PSTACK,PSP \ to avoid stack empty error if lack of typed values.
146     MOV @RSP+,IP
147     MOV @IP+,PC
148 ENDCODE
149     \
150 PWR_HERE
151     \
152 GET_TIME