
hex
\ ADC on and sample & hold time at 8 ADC10 clocks
: SETUP-ADC ( -- )
    39 22 *bic              \ P1.0, P1.3,4,5 are inputs
    30 27 *bis  30 21 *bis  \ P1.4,5 are inputs with pullup
\ P2.0 to P2.5 are positive on led outputs
    12 1B0 **bic            \ ADC10CTL0  Deactivate ADC & clear ENC
    10 1B0 **bis            \ ADC10CTL0  Activate ADC
    09 04A c!               \ ADC10AE0   P1.0 & P1.3 are ADC in
\   0010 1B0 ! ;            \ ADC10CTL0  T-sample 4 ADC10 clocks,
    0910 1B0 ! ;            \ ADC10CTL0  T-sample 8 ADC10 clocks,
                            \            ADC on & Vref = VCC & VSS
                            \            Ref. buf on during sample & hold

: ADC       ( +n -- u )     \ Use ADC10OSC as clock
    F000 and                \ Mask ADC input channel selector
    02 1B0 **bic            \ ADC10CTL0  Clear ENC
    60 or 1B2 !             \ ADC10CTL1  Select input, MCLK/4
    03 1B0 **bis            \ ADC10CTL0  Set ENC & ADC10SC
\   noop noop
    begin 4 1B0 bit** until \ ADC10CTL0  ADC10 ready?
    1B4 @ ;                 \ ADC10MEM   Read result

hex
: LIPO          0000 adc ;  \ Read level at P1.0
: LDR           3000 adc ;  \ Read level at P1.3

: .LIPO         ( -- )          \ Show LiPo voltage in decimal
    lipo dm 10364 dm 10000 */   \ Convert ADC to voltage
    0 <# # # ch . hold # #>     \ Make string
    &type  &"  V " ;            \ And print it

: .STAT
    0 4 xy" Light: "  ldr drop ldr &u.
    0 6 xy" LiPo: "  lipo drop .lipo ;
decimal  setup-adc

hex
\ ADC on and sample & hold time at 64 ADC10 clocks
: SETUP-ADC ( -- )
    39 22 *bic              \ P1.0, P1.3,4,5 are inputs
    30 27 *bis  30 21 *bis  \ P1.4,5 are inputs with pullup
\ P2.0 to P2.5 are positive on led outputs
    12 1B0 **bic            \ ADC10CTL0  Deactivate ADC & clear ENC
    10 1B0 **bis            \ ADC10CTL0  Activate ADC
    09 04A c!               \ ADC10AE0   P1.0 & P1.3 are ADC in
\   0D10 1B0 ! ;            \ ADC10CTL0  T-sample 8 ADC10 clocks,
    1C10 1B0 ! ;            \ ADC10CTL0  T-sample 64 ADC10 clocks,
                            \            ADC on & Vref = VCC & VSS

: ADC       ( +n -- u )
    F000 and                \ Mask ADC input channel selector
    02 1B0 **bic            \ ADC10CTL0  Clear ENC
    60 or 1B2 !             \ ADC10CTL1  Select input, MCLK/3
    03 1B0 **bis            \ ADC10CTL0  Set ENC & ADC10SC
\    noop noop
    begin 4 1B0 bit** until \ ADC10CTL0  ADC10 ready?
    1B4 @ ;                 \ ADC10MEM   Read result


: SAVE-POWER    ( -- )      8 adr ok **bis ;
: EMPTY-BAT?    ( -- )      lipo dm 290 < if sleep then ;

