// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // RTC (Real Time Clock) The RTC is built into the BV511, other // LPC range of processors may also have a RTC but may not have // the 32kHz crystal to drive it. In this case it is driven from // the CPU crystal, hence there are two methods of starting the clock // on the BV511, once the clock is started it will keep going provided // there is a battery in place. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // REQUIRES: // #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" // // HISTORY: // March 2008 * rtc.dow added // CONSTANTS: // RTC constants, not all of these are used for // words in this module. &e0024004 constant CTC &e0024008 constant CCR &e002400c constant CIIR &e0024010 constant AMR &e0024014 constant CTIME0 &e0024018 constant CTIME1 &e002401c constant CTIME2 &e0024020 constant SEC &e0024024 constant MINUTE &e0024028 constant HOUR &e002402c constant DOM &e0024030 constant DOW &e0024034 constant DOY &e0024038 constant MONTH &e002403c constant YEAR &e0024060 constant ALSEC &e0024064 constant ALMIN &e0024068 constant ALHOUR &e002406c constant ALDOM &e0024070 constant ALDOW &e0024074 constant ALDOY &e0024078 constant ALMON &e002407c constant ALYEAR &e0024080 constant PREINT &e0024084 constant PREFRAC // USE WITH 32KHZ XTAL // The clock oscillator is continuous driven form // a battery, so prescaling is not required. // enables clock and sets ocs source from 32khz osc // ( --- ) : set &11 ccr ! ; // USE WITHOUT 32KHZ XTAL // sets prescaler for systems with no separate xtal // and starts the clock // ( ---) : 1set pclk // in Hz 32768 u/mod // devide preint ! prefrac ! 1 CCR ! // enable clock ; // clock tick counter : TICK ctc @ ; // display date and time // dd/mm/yy hh:mm:ss : date dom @ <# # # #> stype 47 emit month @ <# # # #> stype 47 emit year @ <# # # #> stype space hour @ <# # # #> stype 58 emit minute @ <# # # #> stype 58 emit sec @ <# # # #> stype space ; // ---------------- Public interface --------------------------- : <0>rtc.start set ; // with 32kHz xtal : <0>trc.tick ( -- v ) tick ; : <0>rtc.settime ( h,m,s -- ) SEC ! MINUTE ! HOUR ! ; : <0>rtc.setdate ( y,m,d -- ) DOM ! MONTH ! YEAR ! ; : <0>rtc.date. ( -- ) date ; : <0>rtc.date ( -- year, month day ) year @ month @ dom @ ; : <0>rtc.time ( --- h,m,s ) hour @ minute @ sec @ ; : <0>rtc.clock? ( --- t/f ) tick 5 ms tick <> ; // shows if clock has started : <0>rtc.dow ( -- dow ) DOW ; // fetch DOW constant