; Keith Neufeld ; 05-Aug-2006 ; ; LogoChip library to configure the number of analog inputs, which ; start on port A and work into port E (on the 4320) and port B: ; ; A0, A1, A2, A3, A5, E0, E1, E1, B2, B3, B1, B4, B0 ; ; (PIC18F2220/2320/4220/4320 Datasheet, p. 4) ; ; Lines set as analog inputs also function as digital outputs, ; depending on the settings of their port's tristate register. Lines ; not set as analog inputs function as digital I/O. ; ; The PIC sets all possible inputs to analog on powerup (Datasheet ; p. 50), which the LogoChip firmware overrides to five (A0-3 and A5; ; LogoChip Language Reference, p. 7). constants [ [ADCON $fc1] ; port A control register [PCFG-MASK #00001111] ; mask for port config bits ; Datasheet p. 214 ] to config-analog-lines :number if (:number < 0 or :number > 13) [ ; only 13 lines possible stop ] ; Preserve high nybble and set low nybble to %1111 minus the desired ; number of analog lines. ; ; *ADCON = (*ADCON & !PCFG-MASK) | (PCFG-MASK - :number) write ADCON (((read ADCON) and (not PCFG-MASK)) or (PCFG-MASK - :number)) end