<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE codeDefinitions SYSTEM "../codeDefinitions.dtd">

<codeDefinitions>

  <codeBlock>

    <code name="fuses" caption="fuses (DCR) configuration">

      <line comment="B5=OSCEN-L B2:0=FOSC2:0"/>
      <line register="CONFIG1H" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B3:2=BORV1:0 B1=BOREN B0=PWRTEN-L"/>
      <line register="CONFIG2L" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B3:1=WDTPS2:0 B0=WDTEN"/>
      <line register="CONFIG2H" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B0=CCP2MX"/>
      <line register="CONFIG3H" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B7=DEBUG-L B2=LVP B0=STVREN"/>
      <line register="CONFIG4L" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B3:0=CP3:0"/>
      <line register="CONFIG5L" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B7=CPD B6=CPB"/>
      <line register="CONFIG5H" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B3:0=WR3:0"/>
      <line register="CONFIG6L" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B7=WRTD B6=WRTB B5=WRTC"/>
      <line register="CONFIG6H" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B3:0=EBTR3:0"/>
      <line register="CONFIG7L" action="WCFG" mask="0x00FF" comment=""/>

      <line comment="B6=EBTRB"/>
      <line register="CONFIG7H" action="WCFG" mask="0x00FF" comment=""/>

    </code>

    <code name="Reset" caption="Check for reset errors">

    </code>

    <code name="Interrupts" caption="Disable Interrupts during configuration">

      <line comment="B4=EE B3=BCL B2=LVD B1=TMR3 B0=CCP2"/>
      <line register="PIE2" action="W" value="0x0000" mask="0x001F" comment=""/>
      <line comment="B7=PSP B6=AD B5=RC1 B4=TX1 B3=SSP B2=CCP1 B1=TMR2 B0=TMR1"/>
      <line register="PIE1" action="W" value="0x0000" mask="0x00FF" comment=""/>

    </code>

    <code name="Oscillator" caption="Oscillator configuration">

      <line comment="B0=SCS"/>
      <line register="OSCCON" action="WREG" mask="0x0001" comment=""/>

    </code>

    <code name="Reset" caption="Reset configuration">

      <line comment="B5=IRVST B4=LVDEN B3:0=LVDL3:0"/>
      <line register="LVDCON" action="WREG" mask="0x003F" comment=""/>
      <line comment="B5=IRVST B4=LVDEN B3:0=LVDL3:0"/>
      <line register="WDTCON" action="WREG" mask="0x0001" comment=""/>
      <line comment="B7=IPEN B6=LWRT B4=RI-L B3=TO-L B2=PD-L B1=POR-L B0=BOR-L"/>
      <line register="RCON" action="WREG" mask="0x00DF" comment=""/>

    </code>

    <code name="IOPortA" caption="IO Ports configuration">

      <line comment="port A is 6 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISA" action="W" value="0x3F" mask="0x003F" comment=""/>
      <line register="PORTA" action="WREG" mask="0x003F" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISA" action="WREG" mask="0x003F" comment=""/>

    </code>

    <code name="IOPortB" caption="IO Ports configuration">

      <line comment="port B is 8 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISB" action="W" value="0xFF" mask="0x00FF" comment=""/>
      <line register="PORTB" action="WREG" mask="0x00FF" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISB" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="IOPortC" caption="IO Ports configuration">

      <line comment="port C is 8 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISC" action="W" value="0xFF" mask="0x00FF" comment=""/>
      <line register="PORTC" action="WREG" mask="0x00FF" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISC" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="IOPortD" caption="IO Ports configuration">

      <line comment="port D is 8 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISD" action="W" value="0xFF" mask="0x00FF" comment=""/>
      <line register="PORTD" action="WREG" mask="0x00FF" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISD" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="IOPortE" caption="IO Ports configuration">

      <line comment="port E is 8 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISE" action="W" value="0xFF" mask="0x00FF" comment=""/>
      <line register="PORTE" action="WREG" mask="0x00FF" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISE" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="IOPortF" caption="IO Ports configuration">

      <line comment="port F is 8 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISF" action="W" value="0xFF" mask="0x00FF" comment=""/>
      <line register="PORTF" action="WREG" mask="0x00FF" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISF" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="IOPortG" caption="IO Ports configuration">

      <line comment="port G is 5 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISG" action="W" value="0x1F" mask="0x001F" comment=""/>
      <line register="PORTG" action="WREG" mask="0x001F" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISG" action="WREG" mask="0x001F" comment=""/>

    </code>

    <code name="IOPortH" caption="IO Ports configuration">

      <line comment="port H is 8 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISH" action="W" value="0xFF" mask="0x00FF" comment=""/>
      <line register="PORTH" action="WREG" mask="0x00FF" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISH" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="IOPortJ" caption="IO Ports configuration">

      <line comment="port J is 8 bits wide"/>
      <line comment="set TRIS to all inputs before setting initial value"/>
      <line register="TRISJ" action="W" value="0xFF" mask="0x00FF" comment=""/>
      <line register="PORTJ" action="WREG" mask="0x00FF" comment=""/>
      <line comment="set port bit as input (1) or output (0)"/>
      <line register="TRISJ" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="PSP" caption="PSP configuration">

      <line comment="part of TRISE: B7=IBF B6=OBF B5=IBOV B4=PSPMODE"/>
      <line comment="TRISE already configured above"/>

    </code>

    <code name="EMI" caption="EMI configuration">

      <line comment="B7=EBDIS B5:4=WAIT1:0 B1:0=WM1:0"/>
      <line register="MEMCON" action="WREG" mask="0x00B3" comment=""/>

    </code>

    <code name="CCP1" caption="CCP configuration">

      <line comment="(H)Register High Byte"/>
      <line comment="(L)Register Low Byte"/>
      <line comment="(CON)B5:4=DCB1:0 B4:0=CCPM3:0"/>
      <line register="CCPR1H" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCPR1L" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCP1CON" action="WREG" mask="0x003F" comment=""/>

    </code>

    <code name="CCP2" caption="CCP configuration">

      <line comment="(H)Register High Byte"/>
      <line comment="(L)Register Low Byte"/>
      <line comment="(CON)B5:4=DCB1:0 B4:0=CCPM3:0"/>
      <line register="CCPR2H" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCPR2L" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCP2CON" action="WREG" mask="0x003F" comment=""/>

    </code>

    <code name="CCP3" caption="CCP configuration">

      <line comment="(H)Register High Byte"/>
      <line comment="(L)Register Low Byte"/>
      <line comment="(CON)B5:4=DCB1:0 B4:0=CCPM3:0"/>
      <line register="CCPR3H" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCPR3L" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCP3CON" action="WREG" mask="0x003F" comment=""/>

    </code>

    <code name="CCP4" caption="CCP configuration">

      <line comment="(H)Register High Byte"/>
      <line comment="(L)Register Low Byte"/>
      <line comment="(CON)B5:4=DCB1:0 B4:0=CCPM3:0"/>
      <line register="CCPR4H" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCPR4L" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCP4CON" action="WREG" mask="0x003F" comment=""/>

    </code>

    <code name="CCP5" caption="CCP configuration">

      <line comment="(H)Register High Byte"/>
      <line comment="(L)Register Low Byte"/>
      <line comment="(CON)B5:4=DCB1:0 B4:0=CCPM3:0"/>
      <line register="CCPR5H" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCPR5L" action="WREG" mask="0x00FF" comment=""/>
      <line register="CCP5CON" action="WREG" mask="0x003F" comment=""/>

    </code>

    <code name="MSSP" caption="MSSP configuration">

      <line comment="RX/TX buffer"/>
      <line register="SSPBUF" action="R" mask="0x00FF" comment=""/>
      <line comment="Address register (I2C Slave) or BRG (I2C Master)"/>
      <line register="SSPADD" action="WREG" mask="0x00FF" comment=""/>
      <line comment="B7=SMP B6=CKE B5=D/A-L B4=P B3=S B2=R/W-L B1=UA B0=BF"/>
      <line register="SSPSTAT" action="WREG" mask="0x00FF" comment=""/>
      <line comment="B7=WCOL B6=SSPOV B5=SSPEN B4=CKP B3:0=SSPM3:0"/>
      <line register="SSPCON1" action="WREG" mask="0x00FF" comment=""/>
      <line comment="B7=GCEN B6=ACKSTAT B5=ACKDT B4=ACKEN B3=RCEN B2=PEN B1=RSEN B0=SEN"/>
      <line register="SSPCON2" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="UART1" caption="USART configuration">

      <line comment="(RCSTA)B7=SPEN B6=RX9 B5=SREN B4=CREN B3=ADDEN B2=FERR B1=OERR B0=RX9D"/>
      <line comment="(TXSTA)B7=CSRC B6=TX9 B5=TXEN B4=SYNC B2=BRGH B1=TRMT B0=TX9D"/>
      <line comment="(SPBRG)Baud rate generator"/>
      <line comment="(RCREG)Receive register"/>
      <line register="RCSTA" action="WREG" mask="0x00FF" comment="set up receive options"/>
      <line register="TXSTA" action="WREG" mask="0x00F7" comment="set up transmit options"/>
      <line register="SPBRG" action="WREG" mask="0x00FF" comment="set up baud"/>
      <line register="RCREG" action="R" value="0x0000" mask="0x00FF" comment="flush receive buffer"/>
      <line register="RCREG" action="R" value="0x0000" mask="0x00FF" comment=""/>

    </code>

    <code name="UART2" caption="USART configuration">

      <line comment="(RCSTA)B7=SPEN B6=RX9 B5=SREN B4=CREN B3=ADDEN B2=FERR B1=OERR B0=RX9D"/>
      <line comment="(TXSTA)B7=CSRC B6=TX9 B5=TXEN B4=SYNC B2=BRGH B1=TRMT B0=TX9D"/>
      <line comment="(SPBRG)Baud rate generator"/>
      <line comment="(RCREG)Receive register"/>
      <line register="RCSTA2" action="WREG" mask="0x00FF" comment="set up receive options"/>
      <line register="TXSTA2" action="WREG" mask="0x00F7" comment="set up transmit options"/>
      <line register="SPBRG2" action="WREG" mask="0x00FF" comment="set up baud"/>
      <line register="RCREG2" action="R" value="0x0000" mask="0x00FF" comment="flush receive buffer"/>
      <line register="RCREG2" action="R" value="0x0000" mask="0x00FF" comment=""/>

    </code>

    <code name="A2D" caption="A2D configuration">

      <line comment="set pins for analog or digital"/>
      <line comment="B7:6=ADCS1:0 B5:3=CHS2:0 B2=GO B0=ADON"/>
      <line register="ADCON0" action="WREG" mask="0x003B" comment="GO bit2 to 0"/>
      <line comment="B7=ADFM B6=ADCS2 B3:0=PCFG3:0"/>
      <line register="ADCON1" action="WREG" mask="0x003F" comment=""/>

    </code>

    <code name="Comparator" caption="Comparator configuration">

      <line comment="set pins for analog or digital"/>
      <line comment="B7=C2OUT B6:C1OUT B5=C2INV B4=C1INV B3=CIS B2:0=CM2:0"/>
      <line register="CMCON" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="VoltageRef" caption="Voltage Reference configuration">

      <line comment="set pins for analog or digital"/>
      <line comment="B7=CVREN B6=CVROE B5=CVRR B4=CVSS B3:0=CVF3:0"/>
      <line register="CVRCON" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="required" caption="Interrupt flags cleared and interrupt configuration">

      <line comment="interrupt priorities"/>
      <line comment="B4=EE B3=BCL B2=LVD B1=TMR3 B0=CCP2"/>
      <line register="IPR2" action="WREG" mask="0x001F" comment=""/>
      <line comment="B7=PSP B6=AD B5=RC1 B4=TX1 B3=SSP B2=CCP1 B1=TMR2 B0=TMR1"/>
      <line register="IPR1" action="WREG" mask="0x00FF" comment=""/>

      <line comment="clear int flags"/>
      <line comment="B4=EE B3=BCL B2=LVD B1=TMR3 B0=CCP2"/>
      <line register="PIR2" action="W" value="0x0000" mask="0x001F" comment=""/>
      <line comment="B7=PSP B6=AD B5=RC1 B4=TX1 B3=SSP B2=CCP1 B1=TMR2 B0=TMR1"/>
      <line register="PIR1" action="W" value="0x0000" mask="0x00FF" comment=""/>

      <line comment="global and external interrupt enables"/>
      <line comment="B7=GIE B6=PEIE B5=TMR0IE B4=INTOIE B3=RBIE B2=TMR0IF B1=INTOIF B0=RBIF"/>
      <line register="INTCON" action="WREG" mask="0x00FF" comment=""/>
      <line comment="B7=RBPU-L B6:3=INTEDG0:3 B2=TMR0IP B1=INT3IP B0=RBIP"/>
      <line register="INTCON2" action="WREG" mask="0x00FF" comment=""/>
      <line comment="B7:6=INT2:1IP B5:3=INT3:1IE B2:0=INT3:1IF"/>
      <line register="INTCON3" action="WREG" mask="0x00FF" comment=""/>

    </code>

    <code name="Timer0" caption="Timers configuration">

      <line comment="(CON)B7=TMRON B6=T8BIT B5=TCS B4=TSE B3=PSA B2:0=TPS2:0"/>
      <line comment="(TMRH)B7:0=Timer register High byte"/>
      <line comment="(TMRL)B7:0=Timer register Low byte"/>
      <line code="bcf T0CON,TMR0ON" comment="stop the timer"/>
      <line register="T0CON" action="WREG" mask="0x00FF" comment="set options with timer on/off (bit7)"/>
      <line comment="***note: must reload 0x100-TMR in application code***"/>
      <line register="TMR0" action="LREG.b_H" mask="0xFFFF" comment="preset timer values"/>
      <line register="TMR0" action="LREG.b_L" mask="0xFFFF" comment=""/>

    </code>

    <code name="Timer2" caption="Timers configuration">

      <line comment="(CON)B6:3=TOUTPS3:0 B2=TMRON B1:0=TCKPS1:0"/>
      <line comment="(TMR)Timer register (cleared)"/>
      <line comment="(PR)Timer preload register (set)"/>
      <line code="bcf T2CON,TMR2ON" comment="stop the timer"/>
      <line register="T2CON" action="WREG" mask="0x007F" comment="set options with timer on/off (bit2)"/>
      <line register="TMR2" action="W" value="0x0000" mask="0x00FF" comment="preset timer values"/>
      <line register="PR2" action="WREG" mask="0x00FF" comment="preload timer values"/>

    </code>

    <code name="Timer4" caption="Timers configuration">

      <line comment="(CON)B6:3=TOUTPS3:0 B2=TMRON B1:0=TCKPS1:0"/>
      <line comment="(TMR)Timer register (cleared)"/>
      <line comment="(PR)Timer preload register (set)"/>
      <line code="bcf T4CON,TMR4ON" comment="stop the timer"/>
      <line register="T4CON" action="WREG" mask="0x007F" comment="set options with timer on/off (bit2)"/>
      <line register="TMR4" action="W" value="0x000" mask="0x00FF" comment="preset timer values"/>
      <line register="PR4" action="WREG" mask="0x00FF" comment="preload timer values"/>

    </code>

    <code name="Timer1" caption="Timers configuration">

      <line comment="(CON)B7=RD16 B5:4=TCKPS1:0 B3=TOSCEN B2=TSYNC-L B1=TMRCS B0=TMRON"/>
      <line comment="(TMRH)Timer register High byte"/>
      <line comment="(TMRL)Timer register Low byte"/>
      <line code="bcf T1CON,TMR1ON" comment="stop the timer"/>
      <line register="T1CON" action="WREG" mask="0x00BF" comment="set options with timer on/off (bit0)"/>
      <line comment="***note: must reload 0x100-TMR in application code***"/>
      <line register="TMR1" action="LREG.b_H" mask="0xFFFF" comment="preset timer values"/>
      <line register="TMR1" action="LREG.b_L" mask="0xFFFF" comment=""/>

    </code>

    <code name="Timer3" caption="Timers configuration">

      <line comment="(CON)B7=RD16 B5:4=TCKPS1:0 B3=TOSCEN B2=TSYNC-L B1=TMRCS B0=TMRON"/>
      <line comment="(TMRH)Timer register High byte"/>
      <line comment="(TMRL)Timer register Low byte"/>
      <line code="bcf T3CON,TMR3ON" comment="stop the timer"/>
      <line register="T3CON" action="WREG" mask="0x00BF" comment="set options with timer on/off (bit0)"/>
      <line comment="***note: must reload 0x100-TMR in application code***"/>
      <line register="TMR3" action="LREG.b_H" mask="0xFFFF" comment="preset timer values"/>
      <line register="TMR3" action="LREG.b_L" mask="0xFFFF" comment=""/>

    </code>

    <code name="CPU" caption="CPU register configuration">

    </code>

    <code name="Interrupts" caption="enable interrupts">

      <line comment="feature interrupt enables"/>
      <line comment="B4=EE B3=BCL B2=LVD B1=TMR3 B0=CCP2"/>
      <line register="PIE2" action="WREG" mask="0x001F" comment=""/>
      <line comment="B7=PSP B6=AD B5=RC1 B4=TX1 B3=SSP B2=CCP1 B1=TMR2 B0=TMR1"/>
      <line register="PIE1" action="WREG" mask="0x00FF" comment=""/>

      <line code="return" comment="end of init"/>

    </code>

    <code name="Reset" caption="Reset Error Handlers">

    </code>

</codeBlock>

</codeDefinitions>