1+ '' =================================================================================================
2+ ''
3+ '' File....... DS1302_full_Demo.spin2
4+ '' Purpose.... Demonstrates interface of DS1302 Run Time Clock module driver (DS1302_full.spin2)
5+ '' Author..... Dennis Gately
6+ '' Copyright (C) 2020-2021
7+ '' -- see below for terms of use
8+ '' Dependencies... jm_fullduplexserial.spin2
9+ '' DS132_full.spin2
10+ '' Started.... 30 DEC 2020
11+ '' Updated.... 03 JAN 2021
12+ ''
13+ '' =================================================================================================
14+
15+
16+ con { timing }
17+
18+ CLK_FREQ = 200_000_000 ' system freq as a constant
19+ MS_001 = CLK_FREQ / 1_000 ' ticks in 1ms
20+ US_001 = CLK_FREQ / 1_000_000 ' ticks in 1us
21+
22+ _clkfreq = CLK_FREQ ' set system clock
23+
24+ con { terminal }
25+
26+ BR_TERM = 230_400 ' terminal baud rate
27+
28+ #0, T_PST, T_ANSI ' terminal types
29+
30+ T_TYPE = T_PST
31+
32+
33+ con { fixed io pins }
34+
35+ RX1 = 63 { I } ' programming / debug
36+ TX1 = 62 { O }
37+
38+ SF_CS = 61 { O } ' serial flash
39+ SF_SCK = 60 { O }
40+ SF_SDO = 59 { O }
41+ SF_SDI = 58 { I }
42+
43+ SD_SCK = 61 { O } ' sd card
44+ SD_CS = 60 { O }
45+ SD_SDI = 59 { O }
46+ SD_SDO = 58 { I }
47+
48+ SDA1 = 55 { IO } ' i2c connections
49+ SCL1 = 54 { IO }
50+
51+ DS_clk = 28
52+ DS_data = 29
53+ DS_CE = 30
54+
55+ con { app io pins }
56+
57+ con
58+
59+ #true, ON, OFF
60+ #false, NO, YES
61+
62+ obj
63+
64+ term : "jm_fullduplexserial" ' * serial IO for terminal
65+ rtc : "DS1302_full" ' ds1302 Run Time Clock
66+ ansi : "jm_ansi" ' ANSI terminal control sequences
67+
68+ var
69+
70+ byte hour, minute, second, day, month, year, dow
71+
72+ pub main()| i
73+
74+ setup()
75+
76+ wait_for_terminal(true)
77+
78+ '' setDatetime test, un-comment to initialize to a specific date
79+ '' parameters are: _mth, _day, _year, _dow, _hr, _min, _sec
80+ ''rtc.setDatetime( 1, 3, 21, 1, 16, 42, 10 )
81+
82+ term.str(string("DS1302_full_Demo"))
83+ term.tx(13)
84+
85+ rtc.readTime( @hour, @minute, @second ) ' read time from DS1302 RTC
86+ rtc.readDate( @day, @month, @year, @dow ) ' read date from DS1302 RTC
87+
88+ term.fstr3(string("Time: %d:%d:%d\n\r"), hour, minute, second)
89+
90+ term.fstr3(string("Date: %d/%d/%d\n\r"), month, day, year)
91+
92+ repeat
93+
94+ pub setup()| i
95+
96+ term.tstart(BR_TERM) ' start terminal io *
97+
98+ rtc.init( DS_clk, DS_data, DS_CE ) ' clock, data, chip-enable
99+
100+ pub wait_for_terminal(clear)
101+
102+ '' Wait for terminal to be open and key pressed
103+ ' -- download to RAM with F10
104+ ' -- F12 to open PST
105+ ' -- Click [Enable] (if needed)
106+ ' -- Press Enter
107+
108+ term.rxflush()
109+ term.rx()
110+ if (clear)
111+ if (T_TYPE == T_PST)
112+ term.tx(term.CLS)
113+ else
114+ term.str(ansi.hide_cursor())
115+ term.str(ansi.home())
116+ term.str(ansi.cls())
117+
118+ dat
119+
120+ con { license }
121+
122+ {{
123+
124+ Terms of Use: MIT License
125+
126+ Permission is hereby granted, free of charge, to any person obtaining a copy
127+ of this software and associated documentation files (the "Software"), to deal
128+ in the Software without restriction, including without limitation the rights
129+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
130+ copies of the Software, and to permit persons to whom the Software is
131+ furnished to do so, subject to the following conditions:
132+
133+ The above copyright notice and this permission notice shall be included in all
134+ copies or substantial portions of the Software.
135+
136+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
137+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
138+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
139+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
140+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
141+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
142+ SOFTWARE.
143+ }}
0 commit comments