// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BV4237 // This is an unusual device in that it has 3 I2C devices on the PCB // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // REQUIRES: // #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" sid=0 // #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb" sid=101 // #URL-Lib "http://pin1.org/forthlib/flb/I2C/i2c.flb" sid=103 // #URL-Lib "http://pin1.org/forthlib/flb/I2C/bvsys.flb" // CONSTANTS: // device variable is in bvsys.lib &90 constant temperature &d0 constant rt-clock // ============== ADC Section ========================================= : a1 ( -- 0|1 ) device s 1 sb sb p ; // disable / enable ADC : a2 { start -- v } device s 2 sb // reads adc at start adr start 2 * sb device 1+ rs rn &100 * rl + p ; : a2x ( -- 5v ) device s 2 sb 0 sb // prints all 5 adc values device 1+ rs cr 4 for rn &100 * rn + . next rn &100 * rl + . p ; : a3 ( delay -- ) device s 3 sb sb p ; // set acquisition delay default 10 : a4 ( 0|1 -- ) device s 4 sb sb p ; // result justification 1=right : a5 ( 0|1 -- ) device s 5 sb sb p ; // ref voltage source 0=Vdd : a6 ( 0-2 -- ) device s 6 sb sb p ; // conversion clock speed default 0 // ============= Digital section ====================================== : a11 ( 0-7 -- ) device s &11 sb sb p ; // cannel 0 : a12 ( 0-8 -- ) device s &12 sb sb p ; // cannel 1 : a13 ( 0-8 -- ) device s &13 sb sb p ; // cannel 2 : a14 ( 0-8 -- ) device s &14 sb sb p ; // cannel 3 : a15 ( 0-8 -- ) device s &15 sb sb p ; // cannel 4 : a16 ( 0-8 -- ) device s &16 sb sb p ; // cannel 5 : a17 ( 0-8 -- ) device s &17 sb sb p ; // cannel 6 : a18 ( 0-8 -- ) device s &18 sb sb p ; // cannel 7 : a19 ( byet -- ) device s &19 sb sb p ; // all chanels : 4237-default &62 bv-init i2cfull ; : adc-all ( -- ) // prints out all adc channels continuously 4237-default 0= if ." 4237 cant start " abort then begin key? if abort then a2x 500 ms again ; : jj 4237-default 0= if ." 4237 cant start " abort then 255 a19 7 a11 ; // ================ Temperature Section ============================= // This is a standard MCP9802 Temperature device, assumes set to 9 // bit resolution, returns temp as an integer value, if dec=0x80 then // +0.5 else +0 // I.e if temp=20 and dec=0x80 then temp=20.5 : get-temp ( -- temp, dec ) temperature s 0 sb temperature 1+ rs rn rl p ; : temp. ( -- ) get-temp swap . [char] . emit &80 = if 48 else 53 then // 0 or 5 emit ; // =============== RTC Section ======================================= // not well formatted but it gives the idea // Starts the clock after a power down : rtc-pd ( -- ) rt-clock s &0c sb 0 sb p ; // Read time : rtc. rt-clock s 1 sb rt-clock 1+ rs rn rn rl p ph. ." :" ph. ." :" ph. ; // Set time enter hex values : rt-settime { hrs mins secs -- } rt-clock s 0 sb // start address 0 sb secs sb mins sb hrs sb p ; // Set date : rt-setdate { date month year dow -- } rt-clock s 4 sb // start address dow sb date sb month sb year sb p ;