\ port initialization CATkit board:
\ -- 5 analog inputs
\ -- 3 switch inputs with pullup
\ -- audio port output
\ -- pot net on/off output


\ notes

\ * since port initialization is a board feature, all inits, except
\ for the serial port, are concentrated here. it is OK to use some
\ chip macros for init though.

\ * AD inputs can be set individually. this is different than on the
\ 18f2550 for example, where you can only enable a contiguous range of
\ ports as analog inputs.

\ * to set an analog input, both digital input and output need to be
\ disabled. (see datasheet page 89, figure 10-2) the former is done by
\ clearing bits in the ADCON1 register (0 = analog in, 1 = digital
\ in), the latter is done by setting the TRIS bits, which disables the
\ output driver.


macro    

: init-CATkit-ports
    \ note that PGM is still configured as LVP. the pin is open so it
    \ needs pullups.

    #x1F TRISA or!    \ disable digital output for A0-A4
    TRISA 7 low       \ RA7 is output: potnet on/off switch

    #xE1 TRISB or!    \ analog 4 is RB0 + RB5-RB7 are digital in
    INTCON2 RBPU low  \ enable weak pullups for port B (switches)

    #x60 ADCON1 !     \ set A0-A4 as analog input (5,6 digital for serial port)
    #x7E ADCON2 !     \ AD: left justified, 20 TAD, fosc/2
;


: S1?   PORTB 7 low? ; 
: S2?   PORTB 6 low? ; 
: S3?   PORTB 5 low? ;    
    
forth

\ these are useful as interactive commands, so not defined as macros.  
: potnet-on  LATA 7 high ;
: potnet-off LATA 7 low ;   

\ board init, leaves serial port config alone.    
: init-board
    init-CATkit-ports
    potnet-on ;
    
    
