//============================================================================================
//      18F2620.h             ver 8.0.0.0   (7/22/08)
//
//      copyright (c) 2001-2008 Vaux Electronics, Inc.
//============================================================================================


//============================================================================================
//
//      18F2620.h             ver 8.0.0.0   (7/22/08)
//          - original ccs header file (from compiler 3.249), with some vaux mods
//
//============================================================================================


// ===== (vaux-modified) standard header file for PIC18F2620 =====

#device PIC18F2620

#nolist

//////// Program memory: 32768x16  Data RAM: 4096  Stack: 31
//////// I/O: 25   Analog Pins: 10
//////// Data EEPROM: 1024
//////// C Scratch area: 00   ID Location: 2000
//////// Fuses: LP,XT,HS,RC,EC,EC_IO,H4,RC_IO,PROTECT,NOPROTECT,IESO,NOIESO
//////// Fuses: NOBROWNOUT,BROWNOUT,WDT1,WDT2,WDT4,WDT8,WDT16,WDT32,WDT64
//////// Fuses: WDT128,WDT,NOWDT,BORV21,BORV28,BORV43,BORV46,PUT,NOPUT,CPD
//////// Fuses: NOCPD,NOSTVREN,STVREN,NODEBUG,DEBUG,NOLVP,LVP,WRT,NOWRT,WRTD
//////// Fuses: NOWRTD,EBTR,NOEBTR,CPB,NOCPB,EBTRB,NOEBTRB,CCP2B3,CCP2C1
//////// Fuses: WRTC,NOWRTC,WRTB,NOWRTB,INTRC_IO,INTRC,FCMEN,NOFCMEN
//////// Fuses: BROWNOUT_SW,BROWNOUT_NOSL,WDT256,WDT512,WDT1024,WDT2048
//////// Fuses: WDT4096,WDT8192,WDT16384,WDT32768,XINST,NOXINST,PBADEN
//////// Fuses: NOPBADEN,LPT1OSC,NOLPT1OSC,MCLR,NOMCLR
////////
//////// WDT divider:  WDT1=4ms, WDT2=8ms, WDT4=16ms, WDT8=32ms, WDT16=64ms, WDT32=128ms, WDT64=256ms, 
////////               WDT128=512ms, WDT256=1024ms, WDT512=2048ms...WDT32768=131.072s)
////////
//////// NOTE:  Bootloaders do not program fuse (config) settings, so bootloader code 
////////        (which is initially programmed into chip) must have the fuses set properly!
////////
//////// Note: WDT1 is 4ms (but was 18ms on 18F252 and 16F876) -- adjust ported code as needed


// ===== vaux -- add port numbers and other stuff we want to access:
//                Note:   DO:     Initialize ports using set_tris_C(x) and then use PORT_C=y  --  this will
//                                   only output to pins defined as output (by set_tris).
//                        DON'T:  Using output_C(y) (standard_io) will set all pins to output!

#byte   PORT_A        = 0xF80
#byte   PORT_B        = 0xF81
#byte   PORT_C        = 0xF82
#byte   PORT_D        = 0xF83     // (18F4620)
#byte   PORT_E        = 0xF84     // (18F4620)


#byte   SSPCON1       = 0xFC6     // bit-6 is i2c receive overflow, and bit 7 is write-collision
//#byte   SSPCON2       = 0xFC5
//#byte   SSPBUF        = 0xFC9
//#byte   SSPSTAT       = 0xFC7
//#byte   SSPADD        = 0xFC8


// ===== vaux -- disable this, since done in vaux_std.h or don't want at all:
//#define FALSE 0
//#define TRUE 1
//#define BYTE int
//#define BOOLEAN short int


// ===== function macros:
#define getc getch
#define getchar getch
#define putc putchar
#define fgetc getch
#define fputc putchar
#define fgets gets
#define fputs puts


// ===== discrete I/O Functions:  SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
//                                PORT_B_PULLUPS(), INPUT(),
//                                OUTPUT_LOW(), OUTPUT_HIGH(),
//                                OUTPUT_FLOAT(), OUTPUT_BIT()
//
// constants used to identify pins in the above:

#define PIN_A0  31744
#define PIN_A1  31745
#define PIN_A2  31746
#define PIN_A3  31747
#define PIN_A4  31748
#define PIN_A5  31749
#define PIN_A6  31750
#define PIN_A7  31751

#define PIN_B0  31752
#define PIN_B1  31753
#define PIN_B2  31754
#define PIN_B3  31755
#define PIN_B4  31756
#define PIN_B5  31757
#define PIN_B6  31758
#define PIN_B7  31759

#define PIN_C0  31760
#define PIN_C1  31761
#define PIN_C2  31762
#define PIN_C3  31763
#define PIN_C4  31764
#define PIN_C5  31765
#define PIN_C6  31766
#define PIN_C7  31767

#define PIN_E3  31779


// ===== control functions:  RESET_CPU(), SLEEP(), RESTART_CAUSE()
//
// constants returned from RESTART_CAUSE():

#define WDT_TIMEOUT       7
#define MCLR_FROM_SLEEP  11
#define MCLR_FROM_RUN    15
#define NORMAL_POWER_UP  12
#define BROWNOUT_RESTART 14
#define WDT_FROM_SLEEP   3
#define RESET_INSTRUCTION 0


// ===== timer 0 (aka RTCC) functions:  SETUP_COUNTERS() or SETUP_TIMER0(),
//                                      SET_TIMER0() or SET_RTCC(),
//                                      GET_TIMER0() or GET_RTCC()
//
// constants used for SETUP_TIMER0():

#define RTCC_INTERNAL   0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48

#define RTCC_DIV_1      8
#define RTCC_DIV_2      0
#define RTCC_DIV_4      1
#define RTCC_DIV_8      2
#define RTCC_DIV_16     3
#define RTCC_DIV_32     4
#define RTCC_DIV_64     5
#define RTCC_DIV_128    6
#define RTCC_DIV_256    7

#define RTCC_OFF        0x80

#define RTCC_8_BIT      0x40


// ===== constants used for SETUP_COUNTERS() are the above constants for the 1st param
//        and the following for the 2nd param:


// ===== watchdog timer functions:    SETUP_WDT() or SETUP_COUNTERS() (see above)
//                                    RESTART_WDT()

#define WDT_ON      0x100
#define WDT_OFF     0


// ===== timer 1 functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
//
// constants used for SETUP_TIMER_1() (or, via |, together constants from each group):

#define T1_DISABLED         0
#define T1_INTERNAL         0x85
#define T1_EXTERNAL         0x87
#define T1_EXTERNAL_SYNC    0x83

#define T1_CLK_OUT          8

#define T1_DIV_BY_1         0
#define T1_DIV_BY_2         0x10
#define T1_DIV_BY_4         0x20
#define T1_DIV_BY_8         0x30


// ===== timer 2 functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
//
// constants used for SETUP_TIMER_2():

#define T2_DISABLED         0
#define T2_DIV_BY_1         4
#define T2_DIV_BY_4         5
#define T2_DIV_BY_16        6


// ===== timer 3 functions: SETUP_TIMER_3, GET_TIMER3, SET_TIMER3
//
// constants used for SETUP_TIMER_3() (or, via |, together constants from each group):

#define T3_DISABLED         0
#define T3_INTERNAL         0x85
#define T3_EXTERNAL         0x87
#define T3_EXTERNAL_SYNC    0x83

#define T3_DIV_BY_1         0
#define T3_DIV_BY_2         0x10
#define T3_DIV_BY_4         0x20
#define T3_DIV_BY_8         0x30


// ===== CCP functions: SETUP_CCPx, SET_PWMx_DUTY
//       CCP variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
//
// constants used for SETUP_CCPx():

#define CCP_OFF                         0
#define CCP_CAPTURE_FE                  4
#define CCP_CAPTURE_RE                  5
#define CCP_CAPTURE_DIV_4               6
#define CCP_CAPTURE_DIV_16              7
#define CCP_COMPARE_SET_ON_MATCH        8
#define CCP_COMPARE_CLR_ON_MATCH        9
#define CCP_COMPARE_INT                 0xA
#define CCP_COMPARE_INT_AND_TOGGLE      0x2
#define CCP_COMPARE_RESET_TIMER         0xB
#define CCP_PWM                         0xC
#define CCP_PWM_PLUS_1                  0x1c
#define CCP_PWM_PLUS_2                  0x2c
#define CCP_PWM_PLUS_3                  0x3c
#define CCP_USE_TIMER3                  0x100
long CCP_1;
#byte   CCP_1    =                      0xfbe
#byte   CCP_1_LOW=                      0xfbe
#byte   CCP_1_HIGH=                     0xfbf
long CCP_2;
#byte   CCP_2    =                      0xfbb
#byte   CCP_2_LOW=                      0xfbb
#byte   CCP_2_HIGH=                     0xfbc


// ===== SPI functions: SETUP_SPI, SPI_WRITE, SPI_READ, SPI_DATA_IN
//
// constants used in SETUP_SSP():

#define SPI_MASTER       0x20
#define SPI_SLAVE        0x24
#define SPI_L_TO_H       0
#define SPI_H_TO_L       0x10
#define SPI_CLK_DIV_4    0
#define SPI_CLK_DIV_16   1
#define SPI_CLK_DIV_64   2
#define SPI_CLK_T2       3
#define SPI_SS_DISABLED  1

#define SPI_SAMPLE_AT_END 0x8000
#define SPI_XMIT_L_TO_H   0x4000


// ===== UART functions: setup_uart()
//
// constants used in setup_uart():
//
// FALSE - Turn UART off
// TRUE  - Turn UART on

#define UART_ADDRESS           2
#define UART_DATA              4
#define UART_AUTODETECT        8
#define UART_AUTODETECT_NOWAIT 9
#define UART_WAKEUP_ON_RDA     10


// ===== Comparator Variables: C1OUT, C2OUT
//
// constants used in setup_comparator() are:

#define A0_A3_A1_A3  0xfff04
#define A0_A3_A1_A2_OUT_ON_A4_A5  0xfcf03
#define A0_A3_A1_A3_OUT_ON_A4_A5  0xbcf05
#define NC_NC_NC_NC  0x0ff07
#define A0_A3_A1_A2  0xfff02
#define A0_A3_NC_NC_OUT_ON_A4  0x9ef01
#define A0_VR_A1_VR 0x3ff06
#define A3_VR_A2_VR 0xcff0e

#bit C1OUT = 0xfb4.6
#bit C2OUT = 0xfb4.7


// ===== VREF functions: setup_vref(), setup_low_volt_detect()
//
// constants used in setup_vref() are:

#define VREF_LOW  0xa0
#define VREF_HIGH 0x80
// or (with |) the above with a number 0-15
#define VREF_F5   0x40
#define VREF_COMP 0x10

// constants used in setup_low_volt_detect() are:

#define LVD_LVDIN   0x1F
#define LVD_45 0x1E
#define LVD_42 0x1D
#define LVD_40 0x1C
#define LVD_38 0x1B
#define LVD_36 0x1A
#define LVD_35 0x19
#define LVD_33 0x18
#define LVD_30 0x17
#define LVD_28 0x16
#define LVD_27 0x15
#define LVD_25 0x14
#define LVD_23 0x13
#define LVD_21 0x12
#define LVD_19 0x11

#define LVD_TRIGGER_BELOW 0
#define LVD_TRIGGER_ABOVE 0x80


// ===== Internal RC Oscillator: setup_oscillator()
//
// constants used in setup_oscillator():

// first param:
#define OSC_31KHZ   0
#define OSC_125KHZ  0x10
#define OSC_250KHZ  0x20
#define OSC_500KHZ  0x30
#define OSC_1MHZ    0x40
#define OSC_2MHZ    0x50
#define OSC_4MHZ    0x60
#define OSC_8MHZ    0x70
#define OSC_16MHZ   0x4060
#define OSC_32MHZ   0x4070
// the following may be OR'ed in with the above using |
#define OSC_TIMER1  1
#define OSC_INTRC   2
#define OSC_NORMAL  0
// the following may be OR'ed in with the above using |
#define OSC_IDLE_MODE  0x80
#define OSC_31250   0x8000
#define OSC_PLL_ON  0x4000
#define OSC_PLL_OFF 0
// a second optional parameter may be used with this part to fine
// tune the speed (signed int,0-31)
// result may be (ignore all other bits)
#define OSC_STATE_STABLE 4
#define OSC_STATE_EXT_RUNNING 8


// ===== ADC functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
//                      SET_ADC_CHANNEL(), READ_ADC()
//
// constants used for SETUP_ADC():

#define ADC_OFF               0           // ADC Off
#define ADC_CLOCK_DIV_2   0x100
#define ADC_CLOCK_DIV_4    0x04
#define ADC_CLOCK_DIV_8    0x01
#define ADC_CLOCK_DIV_16   0x05
#define ADC_CLOCK_DIV_32   0x02
#define ADC_CLOCK_DIV_64   0x06
#define ADC_CLOCK_INTERNAL 0x07           // Internal 2-6us
// the following may be OR'ed in with the above using |
#define ADC_TAD_MUL_0      0x00
#define ADC_TAD_MUL_2      0x08
#define ADC_TAD_MUL_4      0x10
#define ADC_TAD_MUL_6      0x18
#define ADC_TAD_MUL_8      0x20
#define ADC_TAD_MUL_12     0x28
#define ADC_TAD_MUL_16     0x30
#define ADC_TAD_MUL_20     0x38

// constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS   0x0F   // None
#define ALL_ANALOG   0x00   // A0 A1 A2 A3 A5 B2 B3 B1 B4 B0
#define AN0_TO_AN11  0x03   // A0 A1 A2 A3 A5 B2 B3 B1 B4
#define AN0_TO_AN10  0x04   // A0 A1 A2 A3 A5 B2 B3 B1
#define AN0_TO_AN9   0x05   // A0 A1 A2 A3 A5 B2 B3
#define AN0_TO_AN8   0x06   // A0 A1 A2 A3 A5 B2
#define AN0_TO_AN4   0x0A   // A0 A1 A2 A3 A5
#define AN0_TO_AN3   0x0B   // A0 A1 A2 A3
#define AN0_TO_AN2   0x0C   // A0 A1 A2
#define AN0_TO_AN1   0x0D   // A0 A1
#define AN0          0x0E   // A0
#define AN0_TO_AN11_ANALOG     0x03   //!old only provided for compatibility
#define AN0_TO_AN10_ANALOG     0x04   //!old only provided for compatibility
#define AN0_TO_AN9_ANALOG      0x05   //!old only provided for compatibility
#define AN0_TO_AN8_ANALOG      0x06   //!old only provided for compatibility
#define AN0_TO_AN4_ANALOG      0x0A   //!old only provided for compatibility
#define AN0_TO_AN3_ANALOG      0x0B   //!old only provided for compatibility
#define AN0_TO_AN2_ANALOG      0x0C   //!old only provided for compatibility
#define AN0_TO_AN1_ANALOG      0x0D   //!old only provided for compatibility
#define AN0_ANALOG             0x0E   //!old only provided for compatibility
// the following may be OR'ed in with the above using |
#define VSS_VDD               0x00              // Range 0-Vdd
#define VREF_VREF             0x30              // Range VrefL-VrefH
#define VREF_VDD              0x20              // Range VrefL-Vdd
#define VSS_VREF              0x10              // Range 0-VrefH


// constants used in READ_ADC() are:
#define ADC_START_AND_READ     7   // This is the default if nothing is specified
#define ADC_START_ONLY         1
#define ADC_READ_ONLY          6


// ===== interrupt functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(), EXT_INT_EDGE()
//
// constants used for EXT_INT_EDGE():

#define L_TO_H              0x40
#define H_TO_L                 0

// constants used in ENABLE/DISABLE_INTERRUPTS() are:
#define GLOBAL                    0xF2C0
#define INT_RTCC                  0xF220
#define INT_TIMER0                0xF220
#define INT_TIMER1                0x9D01
#define INT_TIMER2                0x9D02
#define INT_TIMER3                0xA002
#define INT_EXT                   0xF210
#define INT_EXT1                  0xF008
#define INT_EXT2                  0xF010
#define INT_RB                    0xF208
#define INT_AD                    0x9D40
#define INT_RDA                   0x9D20
#define INT_TBE                   0x9D10
#define INT_SSP                   0x9D08
#define INT_CCP1                  0x9D04
#define INT_CCP2                  0xA001
#define INT_BUSCOL                0xA008
#define INT_LOWVOLT               0xA004
#define INT_COMP                  0xA040
#define INT_EEPROM                0xA010
#define INT_OSCF                  0xA080

#list
