Revision: 1178 Author: sebastien.lelong Date: Sun Aug 9 01:29:38 2009 Log: issue-80: deal with 16F72X family exceptions about ANSx not being in continue. Added unittests http://code.google.com/p/jallib/source/detail?r=1178
Added: /trunk/test/unittest/16f722_adc.jalt /trunk/test/unittest/16f727_adc.jalt Modified: /trunk/include/jal/unittest.jal /trunk/include/peripheral/adc/adc_channels.jal /trunk/tools/adc/adc_channels.jal.tmpl ======================================= --- /dev/null +++ /trunk/test/unittest/16f722_adc.jalt Sun Aug 9 01:29:38 2009 @@ -0,0 +1,129 @@ +-- Title: unittest to check ADC libs for 16F777 +-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved. +-- Adapted-by: +-- Compiler: >=2.4k +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php) +-- +-- Description: this describes multiple unittests (a testcase), to test the +-- many different combination while setting up ADC. +-- 16f7x7 family (datasheet 30498C) is quite a weird one, many exceptions can be found about it... +-- Just some thoughts... +-- +-- Notes: see jallib wiki page about unit testing to learn how to use this file +-- + +;@jallib section pic +include 16f722 ;@no_debug +pragma target OSC HS +pragma target clock 20_000_000 +pragma target WDT disabled +enable_digital_io() +-- force analog pin/port to be output, so we can check they are +-- automagically set as input when configured (else it can be optimized away) +porta_direction = all_output +portb_direction = all_output +porte_direction = all_output + + +;@jallib section self_test +include unittest +var byte a = 120 +test_byte(a) ;@assertEquals 120 test_test + + +;@jallib testcase test_all_analog_pins +;@jallib use pic +;@jallib use self_test +const byte ADC_NVREF = 0 +const bit ADC_HIGH_RESOLUTION = false +const word ADC_RSOURCE = 2_500 +porta_direction = all_output +portb_direction = all_output + +include adc +adc_init() +set_analog_pin(0) +-- check pin on PORTA configured as inputs (0b0000_0001 => RA0) +asm nop +test_byte(TRISA) ;@assertEquals 1 test_porta_pin_an0_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0_input + +set_analog_pin(1) +-- check pin on PORTA configured as inputs (0b0000_0011 => RA{0,1}) +asm nop +test_byte(TRISA) ;@assertEquals 3 test_porta_pin_an01_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an01_input + +set_analog_pin(2) +-- check pin on PORTA configured as inputs (0b0000_0111 => RA{0,1,2}) +asm nop +test_byte(TRISA) ;@assertEquals 7 test_porta_pin_an012_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an012_input + +set_analog_pin(3) +-- check pin on PORTA configured as inputs (0b0000_1111 => RA{0,1,2,3}) +asm nop +test_byte(TRISA) ;@assertEquals 15 test_porta_pin_an0123_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0123_input + +set_analog_pin(4) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an01234_input + +set_analog_pin(12) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_0001 => RB{0}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12_input +asm nop +test_byte(TRISB) ;@assertEquals 1 test_portb_pin_an01234-12_input + +set_analog_pin(10) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_0011 => RB{0,1}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10_input +asm nop +test_byte(TRISB) ;@assertEquals 3 test_portb_pin_an01234-12-10_input + +set_analog_pin(8) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_0111 => RB{0,1,2}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8_input +asm nop +test_byte(TRISB) ;@assertEquals 7 test_portb_pin_an01234-12-10-8_input + +set_analog_pin(9) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9_input +asm nop +test_byte(TRISB) ;@assertEquals 15 test_portb_pin_an01234-12-10-8-9_input + +set_analog_pin(11) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3,4}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9-11_input +asm nop +test_byte(TRISB) ;@assertEquals 31 test_portb_pin_an01234-12-10-8-9-11_input + +set_analog_pin(13) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3,4,5}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9-11-13_input +asm nop +test_byte(TRISB) ;@assertEquals 63 test_portb_pin_an01234-12-10-8-9-11-13_input + ======================================= --- /dev/null +++ /trunk/test/unittest/16f727_adc.jalt Sun Aug 9 01:29:38 2009 @@ -0,0 +1,185 @@ +-- Title: unittest to check ADC libs for 16F777 +-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved. +-- Adapted-by: +-- Compiler: >=2.4k +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php) +-- +-- Description: this describes multiple unittests (a testcase), to test the +-- many different combination while setting up ADC. +-- 16f7x7 family (datasheet 30498C) is quite a weird one, many exceptions can be found about it... +-- Just some thoughts... +-- +-- Notes: see jallib wiki page about unit testing to learn how to use this file +-- + +;@jallib section pic +include 16f727 ;@no_debug +pragma target OSC HS +pragma target clock 20_000_000 +pragma target WDT disabled +enable_digital_io() +-- force analog pin/port to be output, so we can check they are +-- automagically set as input when configured (else it can be optimized away) +porta_direction = all_output +portb_direction = all_output +porte_direction = all_output + + +;@jallib section self_test +include unittest +var byte a = 120 +test_byte(a) ;@assertEquals 120 test_test + + +;@jallib testcase test_all_analog_pins +;@jallib use pic +;@jallib use self_test +const byte ADC_NVREF = 0 +const bit ADC_HIGH_RESOLUTION = false +const word ADC_RSOURCE = 2_500 +porta_direction = all_output +portb_direction = all_output + +include adc +adc_init() +set_analog_pin(0) +-- check pin on PORTA configured as inputs (0b0000_0001 => RA0) +asm nop +test_byte(TRISA) ;@assertEquals 1 test_porta_pin_an0_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an0_input + +set_analog_pin(1) +-- check pin on PORTA configured as inputs (0b0000_0011 => RA{0,1}) +asm nop +test_byte(TRISA) ;@assertEquals 3 test_porta_pin_an01_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an01_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01_input + +set_analog_pin(2) +-- check pin on PORTA configured as inputs (0b0000_0111 => RA{0,1,2}) +asm nop +test_byte(TRISA) ;@assertEquals 7 test_porta_pin_an012_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an012_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an012_input + +set_analog_pin(3) +-- check pin on PORTA configured as inputs (0b0000_1111 => RA{0,1,2,3}) +asm nop +test_byte(TRISA) ;@assertEquals 15 test_porta_pin_an0123_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0123_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an0123_input + +set_analog_pin(4) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234_input +asm nop +test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an01234_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01234_input + +set_analog_pin(12) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_0001 => RB{0}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12_input +asm nop +test_byte(TRISB) ;@assertEquals 1 test_portb_pin_an01234-12_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01234-12_input + +set_analog_pin(10) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_0011 => RB{0,1}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10_input +asm nop +test_byte(TRISB) ;@assertEquals 3 test_portb_pin_an01234-12-10_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01234-12-10_input + +set_analog_pin(8) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_0111 => RB{0,1,2}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8_input +asm nop +test_byte(TRISB) ;@assertEquals 7 test_portb_pin_an01234-12-10-8_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01234-12-10-8_input + +set_analog_pin(9) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9_input +asm nop +test_byte(TRISB) ;@assertEquals 15 test_portb_pin_an01234-12-10-8-9_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01234-12-10-8-9_input + +set_analog_pin(11) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3,4}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9-11_input +asm nop +test_byte(TRISB) ;@assertEquals 31 test_portb_pin_an01234-12-10-8-9-11_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01234-12-10-8-9-11_input + +set_analog_pin(13) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3,4,5}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9-11-13_input +asm nop +test_byte(TRISB) ;@assertEquals 63 test_portb_pin_an01234-12-10-8-9-11-13_input +asm nop +test_byte(TRISE) ;@assertEquals 0 test_porte_pin_an01234-12-10-8-9-11-13_input + + +set_analog_pin(5) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3,4,5}) +-- check pin on PORTE configured as inputs (0b0000_0001 => RE{0}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9-11-13-5_input +asm nop +test_byte(TRISB) ;@assertEquals 63 test_portb_pin_an01234-12-10-8-9-11-13-5_input +asm nop +test_byte(TRISE) ;@assertEquals 1 test_porte_pin_an01234-12-10-8-9-11-13-5_input + +set_analog_pin(6) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3,4,5}) +-- check pin on PORTE configured as inputs (0b0000_0011 => RE{0,1}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9-11-13-56_input +asm nop +test_byte(TRISB) ;@assertEquals 63 test_portb_pin_an01234-12-10-8-9-11-13-56_input +asm nop +test_byte(TRISE) ;@assertEquals 3 test_porte_pin_an01234-12-10-8-9-11-13-56_input + +set_analog_pin(7) +-- check pin on PORTA configured as inputs (0b0010_1111 => RA{0,1,2,3,5}) +-- check pin on PORTB configured as inputs (0b0000_1111 => RB{0,1,2,3,4,5}) +-- check pin on PORTE configured as inputs (0b0000_0111 => RE{0,1,2}) +asm nop +test_byte(TRISA) ;@assertEquals 47 test_porta_pin_an01234-12-10-8-9-11-13-567_input +asm nop +test_byte(TRISB) ;@assertEquals 63 test_portb_pin_an01234-12-10-8-9-11-13-567_input +asm nop +test_byte(TRISE) ;@assertEquals 7 test_porte_pin_an01234-12-10-8-9-11-13-567_input + ======================================= --- /trunk/include/jal/unittest.jal Sun Jun 7 02:08:40 2009 +++ /trunk/include/jal/unittest.jal Sun Aug 9 01:29:38 2009 @@ -18,5 +18,11 @@ procedure test_word(word in t) is end procedure +procedure test_sword(sword in t) is +end procedure + procedure test_dword(dword in t) is end procedure + +procedure test_sdword(sdword in t) is +end procedure ======================================= --- /trunk/include/peripheral/adc/adc_channels.jal Tue Aug 4 02:07:49 2009 +++ /trunk/include/peripheral/adc/adc_channels.jal Sun Aug 9 01:29:38 2009 @@ -1664,6 +1664,112 @@ -- Provide helper func to configure pins either in digital or analog mode -- (/!\, true/false logic is inverted compared to PCFGx bits) + -- Some exceptions have been reported related to 16f72X family. These devises + -- have gaps within their analog pins, but ANSx bits are continued. For instance, + -- for 16f722, JANSEL_ANS5 should refer to analog pin AN5, but it does not exist ! + -- We need to put some more exceptions here, hoping there won't be much more. If so, + -- these would have to be dealt an in external file people could easily enrich. + -- Anyway... here we go ! + -- Guilty PICs: 16F722, 16F723, 16F724, 16F726, 16F727 + LF versions + -- Here's how ANSx bits are mapped to analog pins: + + if target_chip == PIC_16F722 | target_chip == PIC_16F723 | target_chip == PIC_16F724 | target_chip == PIC_16F726 | target_chip == PIC_16F727 | + target_chip == PIC_16LF722 | target_chip == PIC_16LF723 | target_chip == PIC_16LF724 | target_chip == PIC_16LF726 | target_chip == PIC_16LF727 then + + alias ADC_JANSEL_ANS0 is JANSEL_ANS0 + alias ADC_JANSEL_ANS1 is JANSEL_ANS1 + alias ADC_JANSEL_ANS2 is JANSEL_ANS2 + alias ADC_JANSEL_ANS3 is JANSEL_ANS3 + alias ADC_JANSEL_ANS4 is JANSEL_ANS5 + alias ADC_JANSEL_ANS12 is JANSEL_ANS6 + alias ADC_JANSEL_ANS10 is JANSEL_ANS7 + alias ADC_JANSEL_ANS8 is JANSEL_ANS8 + alias ADC_JANSEL_ANS9 is JANSEL_ANS9 + alias ADC_JANSEL_ANS11 is JANSEL_ANS10 + alias ADC_JANSEL_ANS13 is JANSEL_ANS11 + + + + + if target_chip == PIC_16F724 | target_chip == PIC_16F727 | target_chip == PIC_16LF724 | target_chip == PIC_16LF727 then + alias ADC_JANSEL_ANS5 is JANSEL_ANS20 + alias ADC_JANSEL_ANS6 is JANSEL_ANS21 + alias ADC_JANSEL_ANS7 is JANSEL_ANS22 + end if + + else + -- no exception here: ANSx corresponds to analog pin n°x + if defined(JANSEL_ANS0) == true then + alias ADC_JANSEL_ANS0 is JANSEL_ANS0 + end if + if defined(JANSEL_ANS1) == true then + alias ADC_JANSEL_ANS1 is JANSEL_ANS1 + end if + if defined(JANSEL_ANS2) == true then + alias ADC_JANSEL_ANS2 is JANSEL_ANS2 + end if + if defined(JANSEL_ANS3) == true then + alias ADC_JANSEL_ANS3 is JANSEL_ANS3 + end if + if defined(JANSEL_ANS4) == true then + alias ADC_JANSEL_ANS4 is JANSEL_ANS4 + end if + if defined(JANSEL_ANS5) == true then + alias ADC_JANSEL_ANS5 is JANSEL_ANS5 + end if + if defined(JANSEL_ANS6) == true then + alias ADC_JANSEL_ANS6 is JANSEL_ANS6 + end if + if defined(JANSEL_ANS7) == true then + alias ADC_JANSEL_ANS7 is JANSEL_ANS7 + end if + if defined(JANSEL_ANS8) == true then + alias ADC_JANSEL_ANS8 is JANSEL_ANS8 + end if + if defined(JANSEL_ANS9) == true then + alias ADC_JANSEL_ANS9 is JANSEL_ANS9 + end if + if defined(JANSEL_ANS10) == true then + alias ADC_JANSEL_ANS10 is JANSEL_ANS10 + end if + if defined(JANSEL_ANS11) == true then + alias ADC_JANSEL_ANS11 is JANSEL_ANS11 + end if + if defined(JANSEL_ANS12) == true then + alias ADC_JANSEL_ANS12 is JANSEL_ANS12 + end if + if defined(JANSEL_ANS13) == true then + alias ADC_JANSEL_ANS13 is JANSEL_ANS13 + end if + if defined(JANSEL_ANS14) == true then + alias ADC_JANSEL_ANS14 is JANSEL_ANS14 + end if + if defined(JANSEL_ANS15) == true then + alias ADC_JANSEL_ANS15 is JANSEL_ANS15 + end if + if defined(JANSEL_ANS16) == true then + alias ADC_JANSEL_ANS16 is JANSEL_ANS16 + end if + if defined(JANSEL_ANS17) == true then + alias ADC_JANSEL_ANS17 is JANSEL_ANS17 + end if + if defined(JANSEL_ANS18) == true then + alias ADC_JANSEL_ANS18 is JANSEL_ANS18 + end if + if defined(JANSEL_ANS19) == true then + alias ADC_JANSEL_ANS19 is JANSEL_ANS19 + end if + if defined(JANSEL_ANS20) == true then + alias ADC_JANSEL_ANS20 is JANSEL_ANS20 + end if + if defined(JANSEL_ANS21) == true then + alias ADC_JANSEL_ANS21 is JANSEL_ANS21 + end if + if defined(JANSEL_ANS22) == true then + alias ADC_JANSEL_ANS22 is JANSEL_ANS22 + end if + end if + -- Configure a pin to act as an analog pin. -- an_pin_num references the 'x' in ANx notation. -- Say you want to activate pin AN7, which is pin #12, also named RA4 in digital mode: @@ -1672,141 +1778,141 @@ -- one named AN12, if any -- - set_analog_pin(4) will do the same for AN4 procedure set_analog_pin(byte in an_pin_num) is - if defined(JANSEL_ANS0) == true then + if defined(ADC_JANSEL_ANS0) == true then if an_pin_num == 0 then - JANSEL_ANS0 = true + ADC_JANSEL_ANS0 = true pin_AN0_direction = input end if end if - if defined(JANSEL_ANS1) == true then + if defined(ADC_JANSEL_ANS1) == true then if an_pin_num == 1 then - JANSEL_ANS1 = true + ADC_JANSEL_ANS1 = true pin_AN1_direction = input end if end if - if defined(JANSEL_ANS2) == true then + if defined(ADC_JANSEL_ANS2) == true then if an_pin_num == 2 then - JANSEL_ANS2 = true + ADC_JANSEL_ANS2 = true pin_AN2_direction = input end if end if - if defined(JANSEL_ANS3) == true then + if defined(ADC_JANSEL_ANS3) == true then if an_pin_num == 3 then - JANSEL_ANS3 = true + ADC_JANSEL_ANS3 = true pin_AN3_direction = input end if end if - if defined(JANSEL_ANS4) == true then + if defined(ADC_JANSEL_ANS4) == true then if an_pin_num == 4 then - JANSEL_ANS4 = true + ADC_JANSEL_ANS4 = true pin_AN4_direction = input end if end if - if defined(JANSEL_ANS5) == true then + if defined(ADC_JANSEL_ANS5) == true then if an_pin_num == 5 then - JANSEL_ANS5 = true + ADC_JANSEL_ANS5 = true pin_AN5_direction = input end if end if - if defined(JANSEL_ANS6) == true then + if defined(ADC_JANSEL_ANS6) == true then if an_pin_num == 6 then - JANSEL_ANS6 = true + ADC_JANSEL_ANS6 = true pin_AN6_direction = input end if end if - if defined(JANSEL_ANS7) == true then + if defined(ADC_JANSEL_ANS7) == true then if an_pin_num == 7 then - JANSEL_ANS7 = true + ADC_JANSEL_ANS7 = true pin_AN7_direction = input end if end if - if defined(JANSEL_ANS8) == true then + if defined(ADC_JANSEL_ANS8) == true then if an_pin_num == 8 then - JANSEL_ANS8 = true + ADC_JANSEL_ANS8 = true pin_AN8_direction = input end if end if - if defined(JANSEL_ANS9) == true then + if defined(ADC_JANSEL_ANS9) == true then if an_pin_num == 9 then - JANSEL_ANS9 = true + ADC_JANSEL_ANS9 = true pin_AN9_direction = input end if end if - if defined(JANSEL_ANS10) == true then + if defined(ADC_JANSEL_ANS10) == true then if an_pin_num == 10 then - JANSEL_ANS10 = true + ADC_JANSEL_ANS10 = true pin_AN10_direction = input end if end if - if defined(JANSEL_ANS11) == true then + if defined(ADC_JANSEL_ANS11) == true then if an_pin_num == 11 then - JANSEL_ANS11 = true + ADC_JANSEL_ANS11 = true pin_AN11_direction = input end if end if - if defined(JANSEL_ANS12) == true then + if defined(ADC_JANSEL_ANS12) == true then if an_pin_num == 12 then - JANSEL_ANS12 = true + ADC_JANSEL_ANS12 = true pin_AN12_direction = input end if end if - if defined(JANSEL_ANS13) == true then + if defined(ADC_JANSEL_ANS13) == true then if an_pin_num == 13 then - JANSEL_ANS13 = true + ADC_JANSEL_ANS13 = true pin_AN13_direction = input end if end if - if defined(JANSEL_ANS14) == true then + if defined(ADC_JANSEL_ANS14) == true then if an_pin_num == 14 then - JANSEL_ANS14 = true + ADC_JANSEL_ANS14 = true pin_AN14_direction = input end if end if - if defined(JANSEL_ANS15) == true then + if defined(ADC_JANSEL_ANS15) == true then if an_pin_num == 15 then - JANSEL_ANS15 = true + ADC_JANSEL_ANS15 = true pin_AN15_direction = input end if end if - if defined(JANSEL_ANS16) == true then + if defined(ADC_JANSEL_ANS16) == true then if an_pin_num == 16 then - JANSEL_ANS16 = true + ADC_JANSEL_ANS16 = true pin_AN16_direction = input end if end if - if defined(JANSEL_ANS17) == true then + if defined(ADC_JANSEL_ANS17) == true then if an_pin_num == 17 then - JANSEL_ANS17 = true + ADC_JANSEL_ANS17 = true pin_AN17_direction = input end if end if - if defined(JANSEL_ANS18) == true then + if defined(ADC_JANSEL_ANS18) == true then if an_pin_num == 18 then - JANSEL_ANS18 = true + ADC_JANSEL_ANS18 = true pin_AN18_direction = input end if end if - if defined(JANSEL_ANS19) == true then + if defined(ADC_JANSEL_ANS19) == true then if an_pin_num == 19 then - JANSEL_ANS19 = true + ADC_JANSEL_ANS19 = true pin_AN19_direction = input end if end if - if defined(JANSEL_ANS20) == true then + if defined(ADC_JANSEL_ANS20) == true then if an_pin_num == 20 then - JANSEL_ANS20 = true + ADC_JANSEL_ANS20 = true pin_AN20_direction = input end if end if - if defined(JANSEL_ANS21) == true then + if defined(ADC_JANSEL_ANS21) == true then if an_pin_num == 21 then - JANSEL_ANS21 = true + ADC_JANSEL_ANS21 = true pin_AN21_direction = input end if end if - if defined(JANSEL_ANS22) == true then + if defined(ADC_JANSEL_ANS22) == true then if an_pin_num == 22 then - JANSEL_ANS22 = true + ADC_JANSEL_ANS22 = true pin_AN22_direction = input end if end if @@ -1824,119 +1930,119 @@ -- -- Note: the pin direction is not modified procedure set_digital_pin(byte in an_pin_num) is - if defined(JANSEL_ANS0) == true then + if defined(ADC_JANSEL_ANS0) == true then if an_pin_num == 0 then - JANSEL_ANS0 = false + ADC_JANSEL_ANS0 = false end if end if - if defined(JANSEL_ANS1) == true then + if defined(ADC_JANSEL_ANS1) == true then if an_pin_num == 1 then - JANSEL_ANS1 = false + ADC_JANSEL_ANS1 = false end if end if - if defined(JANSEL_ANS2) == true then + if defined(ADC_JANSEL_ANS2) == true then if an_pin_num == 2 then - JANSEL_ANS2 = false + ADC_JANSEL_ANS2 = false end if end if - if defined(JANSEL_ANS3) == true then + if defined(ADC_JANSEL_ANS3) == true then if an_pin_num == 3 then - JANSEL_ANS3 = false + ADC_JANSEL_ANS3 = false end if end if - if defined(JANSEL_ANS4) == true then + if defined(ADC_JANSEL_ANS4) == true then if an_pin_num == 4 then - JANSEL_ANS4 = false + ADC_JANSEL_ANS4 = false end if end if - if defined(JANSEL_ANS5) == true then + if defined(ADC_JANSEL_ANS5) == true then if an_pin_num == 5 then - JANSEL_ANS5 = false + ADC_JANSEL_ANS5 = false end if end if - if defined(JANSEL_ANS6) == true then + if defined(ADC_JANSEL_ANS6) == true then if an_pin_num == 6 then - JANSEL_ANS6 = false + ADC_JANSEL_ANS6 = false end if end if - if defined(JANSEL_ANS7) == true then + if defined(ADC_JANSEL_ANS7) == true then if an_pin_num == 7 then - JANSEL_ANS7 = false + ADC_JANSEL_ANS7 = false end if end if - if defined(JANSEL_ANS8) == true then + if defined(ADC_JANSEL_ANS8) == true then if an_pin_num == 8 then - JANSEL_ANS8 = false + ADC_JANSEL_ANS8 = false end if end if - if defined(JANSEL_ANS9) == true then + if defined(ADC_JANSEL_ANS9) == true then if an_pin_num == 9 then - JANSEL_ANS9 = false + ADC_JANSEL_ANS9 = false end if end if - if defined(JANSEL_ANS10) == true then + if defined(ADC_JANSEL_ANS10) == true then if an_pin_num == 10 then - JANSEL_ANS10 = false + ADC_JANSEL_ANS10 = false end if end if - if defined(JANSEL_ANS11) == true then + if defined(ADC_JANSEL_ANS11) == true then if an_pin_num == 11 then - JANSEL_ANS11 = false + ADC_JANSEL_ANS11 = false end if end if - if defined(JANSEL_ANS12) == true then + if defined(ADC_JANSEL_ANS12) == true then if an_pin_num == 12 then - JANSEL_ANS12 = false + ADC_JANSEL_ANS12 = false end if end if - if defined(JANSEL_ANS13) == true then + if defined(ADC_JANSEL_ANS13) == true then if an_pin_num == 13 then - JANSEL_ANS13 = false + ADC_JANSEL_ANS13 = false end if end if - if defined(JANSEL_ANS14) == true then + if defined(ADC_JANSEL_ANS14) == true then if an_pin_num == 14 then - JANSEL_ANS14 = false + ADC_JANSEL_ANS14 = false end if end if - if defined(JANSEL_ANS15) == true then + if defined(ADC_JANSEL_ANS15) == true then if an_pin_num == 15 then - JANSEL_ANS15 = false + ADC_JANSEL_ANS15 = false end if end if - if defined(JANSEL_ANS16) == true then + if defined(ADC_JANSEL_ANS16) == true then if an_pin_num == 16 then - JANSEL_ANS16 = false + ADC_JANSEL_ANS16 = false end if end if - if defined(JANSEL_ANS17) == true then + if defined(ADC_JANSEL_ANS17) == true then if an_pin_num == 17 then - JANSEL_ANS17 = false + ADC_JANSEL_ANS17 = false end if end if - if defined(JANSEL_ANS18) == true then + if defined(ADC_JANSEL_ANS18) == true then if an_pin_num == 18 then - JANSEL_ANS18 = false + ADC_JANSEL_ANS18 = false end if end if - if defined(JANSEL_ANS19) == true then + if defined(ADC_JANSEL_ANS19) == true then if an_pin_num == 19 then - JANSEL_ANS19 = false + ADC_JANSEL_ANS19 = false end if end if - if defined(JANSEL_ANS20) == true then + if defined(ADC_JANSEL_ANS20) == true then if an_pin_num == 20 then - JANSEL_ANS20 = false + ADC_JANSEL_ANS20 = false end if end if - if defined(JANSEL_ANS21) == true then + if defined(ADC_JANSEL_ANS21) == true then if an_pin_num == 21 then - JANSEL_ANS21 = false + ADC_JANSEL_ANS21 = false end if end if - if defined(JANSEL_ANS22) == true then + if defined(ADC_JANSEL_ANS22) == true then if an_pin_num == 22 then - JANSEL_ANS22 = false + ADC_JANSEL_ANS22 = false end if end if end procedure ======================================= --- /trunk/tools/adc/adc_channels.jal.tmpl Mon Aug 3 10:31:22 2009 +++ /trunk/tools/adc/adc_channels.jal.tmpl Sun Aug 9 01:29:38 2009 @@ -459,6 +459,53 @@ -- Provide helper func to configure pins either in digital or analog mode -- (/!\, true/false logic is inverted compared to PCFGx bits) + -- Some exceptions have been reported related to 16f72X family. These devises + -- have gaps within their analog pins, but ANSx bits are continued. For instance, + -- for 16f722, JANSEL_ANS5 should refer to analog pin AN5, but it does not exist ! + -- We need to put some more exceptions here, hoping there won't be much more. If so, + -- these would have to be dealt an in external file people could easily enrich. + -- Anyway... here we go ! + -- Guilty PICs: 16F722, 16F723, 16F724, 16F726, 16F727 + LF versions + -- Here's how ANSx bits are mapped to analog pins: + ## stores JANSEL_ANSx <=> AN pin number + ## 16F72X_map = {0:0, 1:1, 2:2, 3:3, 4:5, 6:12, 7:10, 8:8, 9:9, 10:11, 11:13, 20:5, 21:6, 22:7} + ## Maybe this should be in an external python lib file... + + if target_chip == PIC_16F722 | target_chip == PIC_16F723 | target_chip == PIC_16F724 | target_chip == PIC_16F726 | target_chip == PIC_16F727 | + target_chip == PIC_16LF722 | target_chip == PIC_16LF723 | target_chip == PIC_16LF724 | target_chip == PIC_16LF726 | target_chip == PIC_16LF727 then + + ## always exists in all 16F72X family + alias ADC_JANSEL_ANS0 is JANSEL_ANS0 + alias ADC_JANSEL_ANS1 is JANSEL_ANS1 + alias ADC_JANSEL_ANS2 is JANSEL_ANS2 + alias ADC_JANSEL_ANS3 is JANSEL_ANS3 + alias ADC_JANSEL_ANS4 is JANSEL_ANS5 + alias ADC_JANSEL_ANS12 is JANSEL_ANS6 + alias ADC_JANSEL_ANS10 is JANSEL_ANS7 + alias ADC_JANSEL_ANS8 is JANSEL_ANS8 + alias ADC_JANSEL_ANS9 is JANSEL_ANS9 + alias ADC_JANSEL_ANS11 is JANSEL_ANS10 + alias ADC_JANSEL_ANS13 is JANSEL_ANS11 + + + + + ## only for these + if target_chip == PIC_16F724 | target_chip == PIC_16F727 | target_chip == PIC_16LF724 | target_chip == PIC_16LF727 then + alias ADC_JANSEL_ANS5 is JANSEL_ANS20 + alias ADC_JANSEL_ANS6 is JANSEL_ANS21 + alias ADC_JANSEL_ANS7 is JANSEL_ANS22 + end if + + else + -- no exception here: ANSx corresponds to analog pin n°x + #for i in range(23) + if defined(JANSEL_ANS$i) == true then + alias ADC_JANSEL_ANS$i is JANSEL_ANS$i + end if + #end for + end if + -- Configure a pin to act as an analog pin. -- an_pin_num references the 'x' in ANx notation. -- Say you want to activate pin AN7, which is pin #12, also named RA4 in digital mode: @@ -468,9 +515,9 @@ -- - set_analog_pin(4) will do the same for AN4 procedure set_analog_pin(byte in an_pin_num) is #for i in range(23) - if defined(JANSEL_ANS$i) == true then + if defined(ADC_JANSEL_ANS$i) == true then if an_pin_num == $i then - JANSEL_ANS$i = true + ADC_JANSEL_ANS$i = true pin_AN${i}_direction = input end if end if @@ -490,9 +537,9 @@ -- Note: the pin direction is not modified procedure set_digital_pin(byte in an_pin_num) is #for i in range(23) - if defined(JANSEL_ANS$i) == true then + if defined(ADC_JANSEL_ANS$i) == true then if an_pin_num == $i then - JANSEL_ANS$i = false + ADC_JANSEL_ANS$i = false end if end if #end for --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jallib?hl=en -~----------~----~----~----~------~----~------~--~---
