123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- #ifndef __ADC_H__
- #define __ADC_H__
- #pragma library io
- #define ADC_CHN_0 0x00
- #define ADC_CHN_1 0x01
- #define ADC_CHN_2 0x02
- #define ADC_CHN_3 0x03
- #define ADC_CHN_4 0x04
- #define ADC_CHN_5 0x05
- #define ADC_CHN_6 0x06
- #define ADC_CHN_7 0x07
- #define ADC_CHN_8 0x08
- #define ADC_CHN_9 0x09
- #define ADC_CHN_10 0x0a
- #define ADC_CHN_11 0x0b
- #define ADC_CHN_12 0x0c
- #define ADC_CHN_13 0x0d
- #define ADC_CHN_14 0x0e
- #define ADC_CHN_DAC 0x0e /* 13k50-style */
- #define ADC_CHN_15 0x0f
- #define ADC_CHN_FVR 0x0f /* 13k50-style */
- #define ADC_CHN_16 0x10
- #define ADC_CHN_17 0x11
- #define ADC_CHN_18 0x12
- #define ADC_CHN_19 0x13
- #define ADC_CHN_20 0x14
- #define ADC_CHN_21 0x15
- #define ADC_CHN_22 0x16
- #define ADC_CHN_23 0x17
- #define ADC_CHN_24 0x18
- #define ADC_CHN_25 0x19
- #define ADC_CHN_26 0x1a
- #define ADC_CHN_27 0x1b
- #define ADC_CHN_K_CTMU 0x1d
- #define ADC_CHN_K_DAC 0x1e
- #define ADC_CHN_K_FVR 0x1f
- #define ADC_FOSC_2 0x00
- #define ADC_FOSC_4 0x04
- #define ADC_FOSC_8 0x01
- #define ADC_FOSC_16 0x05
- #define ADC_FOSC_32 0x02
- #define ADC_FOSC_64 0x06
- #define ADC_FOSC_RC 0x07
- #define ADC_ACQT_0 (0x00 << 3)
- #define ADC_ACQT_2 (0x01 << 3)
- #define ADC_ACQT_4 (0x02 << 3)
- #define ADC_ACQT_6 (0x03 << 3)
- #define ADC_ACQT_8 (0x04 << 3)
- #define ADC_ACQT_12 (0x05 << 3)
- #define ADC_ACQT_16 (0x06 << 3)
- #define ADC_ACQT_20 (0x07 << 3)
- #define ADC_CAL 0x40
- #define ADC_TRIGGER 0x80
- #define ADC_FRM_LJUST 0x00
- #define ADC_FRM_RJUST 0x80
- #define ADC_INT_OFF 0x00
- #define ADC_INT_ON 0x40
- #define ADC_VCFG_VDD_VSS 0x00
- #define ADC_VCFG_AN3_VSS 0x10
- #define ADC_VCFG_VDD_AN2 0x20
- #define ADC_VCFG_AN3_AN2 0x30
- #define ADC_NVCFG_VSS 0x00
- #define ADC_NVCFG_AN5 0x01
- #define ADC_PVCFG_VDD (0x00 << 2)
- #define ADC_PVCFG_AN4 (0x01 << 2)
- #define ADC_PVCFG_FVR (0x02 << 2)
- #define ADC_NVCFG_AN2 0x01
- #define ADC_PVCFG_AN3 (0x01 << 2)
- #define ADC_TRIGSEL_CCP5 (0x00 << 7)
- #define ADC_TRIGSEL_CTMU (0x01 << 7)
- #include "pic18fam.h"
- #if (__SDCC_ADC_STYLE == 0)
- #warning The target device is not supported by the SDCC PIC16 ADC library.
- #elif (__SDCC_ADC_STYLE == 1802420)
- #define ADC_CFG_8A_0R 0x00
- #define ADC_CFG_7A_1R 0x01
- #define ADC_CFG_5A_0R 0x02
- #define ADC_CFG_4A_1R 0x03
- #define ADC_CFG_3A_0R 0x04
- #define ADC_CFG_2A_1R 0x05
- #define ADC_CFG_0A_0R 0x06
- #define ADC_CFG_6A_2R 0x08
- #define ADC_CFG_6A_0R 0x09
- #define ADC_CFG_5A_1R 0x0a
- #define ADC_CFG_4A_2R 0x0b
- #define ADC_CFG_3A_2R 0x0c
- #define ADC_CFG_2A_2R 0x0d
- #define ADC_CFG_1A_0R 0x0e
- #define ADC_CFG_1A_2R 0x0f
- #elif (__SDCC_ADC_STYLE == 1812200)
- #define ADC_CFG_6A 0x00
- #define ADC_CFG_5A 0x20
- #define ADC_CFG_4A 0x30
- #define ADC_CFG_3A 0x38
- #define ADC_CFG_2A 0x3c
- #define ADC_CFG_1A 0x3e
- #define ADC_CFG_0A 0x3f
- #elif (__SDCC_ADC_STYLE == 1812300)
- #define ADC_CFG_4A 0x00
- #define ADC_CFG_3A 0x08
- #define ADC_CFG_2A 0x0c
- #define ADC_CFG_1A 0x0e
- #define ADC_CFG_0A 0x0f
- #define ADC_VCFG_AVDD 0x00 /* AVdd */
- #define ADC_VCFG_VREF 0x10 /* Vref+ */
- #elif (__SDCC_ADC_STYLE == 1813502)
- #define ADC_CFG_16A 0xFFFF
- #define ADC_CFG_15A 0x7FFF
- #define ADC_CFG_14A 0x3FFF
- #define ADC_CFG_13A 0x1FFF
- #define ADC_CFG_12A 0x0FFF
- #define ADC_CFG_11A 0x07FF
- #define ADC_CFG_10A 0x03FF
- #define ADC_CFG_9A 0x01FF
- #define ADC_CFG_8A 0x00FF
- #define ADC_CFG_7A 0x007F
- #define ADC_CFG_6A 0x003F
- #define ADC_CFG_5A 0x001F
- #define ADC_CFG_4A 0x000F
- #define ADC_CFG_3A 0x0007
- #define ADC_CFG_2A 0x0003
- #define ADC_CFG_1A 0x0001
- #define ADC_CFG_0A 0x0000
- #elif (__SDCC_ADC_STYLE == 1822200)
- #define ADC_CFG_16A 0x00
- #define ADC_CFG_14A 0x01
- #define ADC_CFG_13A 0x02
- #define ADC_CFG_12A 0x03
- #define ADC_CFG_11A 0x04
- #define ADC_CFG_10A 0x05
- #define ADC_CFG_9A 0x06
- #define ADC_CFG_8A 0x07
- #define ADC_CFG_7A 0x08
- #define ADC_CFG_6A 0x09
- #define ADC_CFG_5A 0x0a
- #define ADC_CFG_4A 0x0b
- #define ADC_CFG_3A 0x0c
- #define ADC_CFG_2A 0x0d
- #define ADC_CFG_1A 0x0e
- #define ADC_CFG_0A 0x0f
- #define ADC_CFG_16A_0R 0x00
- #define ADC_CFG_16A_1R 0x10
- #define ADC_CFG_16A_2R 0x30
- #define ADC_CFG_15A_0R 0x00
- #define ADC_CFG_15A_1R 0x10
- #define ADC_CFG_15A_2R 0x30
- #define ADC_CFG_14A_0R 0x01
- #define ADC_CFG_14A_1R 0x11
- #define ADC_CFG_14A_2R 0x31
- #define ADC_CFG_13A_0R 0x02
- #define ADC_CFG_13A_1R 0x12
- #define ADC_CFG_13A_2R 0x32
- #define ADC_CFG_12A_0R 0x03
- #define ADC_CFG_12A_1R 0x13
- #define ADC_CFG_12A_2R 0x33
- #define ADC_CFG_11A_0R 0x04
- #define ADC_CFG_11A_1R 0x14
- #define ADC_CFG_11A_2R 0x34
- #define ADC_CFG_10A_0R 0x05
- #define ADC_CFG_10A_1R 0x15
- #define ADC_CFG_10A_2R 0x35
- #define ADC_CFG_09A_0R 0x06
- #define ADC_CFG_09A_1R 0x16
- #define ADC_CFG_09A_2R 0x36
- #define ADC_CFG_08A_0R 0x07
- #define ADC_CFG_08A_1R 0x17
- #define ADC_CFG_08A_2R 0x37
- #define ADC_CFG_07A_0R 0x08
- #define ADC_CFG_07A_1R 0x18
- #define ADC_CFG_07A_2R 0x38
- #define ADC_CFG_06A_0R 0x09
- #define ADC_CFG_06A_1R 0x19
- #define ADC_CFG_06A_2R 0x39
- #define ADC_CFG_05A_0R 0x0a
- #define ADC_CFG_05A_1R 0x1a
- #define ADC_CFG_05A_2R 0x3a
- #define ADC_CFG_04A_0R 0x0b
- #define ADC_CFG_04A_1R 0x1b
- #define ADC_CFG_04A_2R 0x3b
- #define ADC_CFG_03A_0R 0x0c
- #define ADC_CFG_03A_1R 0x1c
- #define ADC_CFG_03A_2R 0x3c
- #define ADC_CFG_02A_0R 0x0d
- #define ADC_CFG_02A_1R 0x1d
- #define ADC_CFG_02A_2R 0x3d
- #define ADC_CFG_01A_0R 0x0e
- #define ADC_CFG_01A_1R 0x1e
- #define ADC_CFG_01A_2R 0x3e
- #define ADC_CFG_00A_0R 0x0f
- #elif (__SDCC_ADC_STYLE == 1823222)
- #elif (__SDCC_ADC_STYLE == 1824501) || (__SDCC_ADC_STYLE == 1865501)
- #define ADC_CFG_16A 0x0000
- #define ADC_CFG_15A 0x8000
- #define ADC_CFG_14A 0xC000
- #define ADC_CFG_13A 0xE000
- #define ADC_CFG_12A 0xF000
- #define ADC_CFG_11A 0xF800
- #define ADC_CFG_10A 0xFC00
- #define ADC_CFG_9A 0xFE00
- #define ADC_CFG_8A 0xFF00
- #define ADC_CFG_7A 0xFF80
- #define ADC_CFG_6A 0xFFC0
- #define ADC_CFG_5A 0xFFE0
- #define ADC_CFG_4A 0xFFF0
- #define ADC_CFG_3A 0xFFF8
- #define ADC_CFG_2A 0xFFFC
- #define ADC_CFG_1A 0xFFFE
- #define ADC_CFG_0A 0xFFFF
- #else /* unhandled ADC style */
- #error No supported ADC style selected.
- #endif /* __SDCC_ADC_STYLE */
- #if (__SDCC_ADC_STYLE == 1813502) \
- || (__SDCC_ADC_STYLE == 1824501) \
- || (__SDCC_ADC_STYLE == 1865501)
- typedef unsigned int sdcc_pcfg_t;
- #else /* other styles */
- typedef unsigned char sdcc_pcfg_t;
- #endif
- void adc_open (unsigned char channel, unsigned char fosc, sdcc_pcfg_t pcfg, unsigned char config);
- void adc_close (void);
- void adc_conv (void);
- char adc_busy (void) __naked;
- int adc_read (void) __naked;
- void adc_setchannel (unsigned char channel);
- #endif
|