<?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="B15:14=FSCKM1:0 B9:8=FOS1:0 B3:0=FPR3:0"></line>
      <line register="FOSC" action="WCFG" mask="0xFFFF" comment=""></line>
      <line comment="B15=FWDTEN B5:4=FWPSA1:0 B3:0=FWPSB3:0"></line>
      <line register="FWDT" action="WCFG" mask="0xFFFF" comment=""></line>
      <line comment="B15=MCLREN B10=PWMPIN B9=HPOL B8=LPOL"></line>
      <line comment="B7=BOREN B5:4=BORV1:0 B3:0=FPWRT3:0"></line>
      <line register="FBORPOR" action="WCFG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="Interrupts" caption="Disable Interrupts during configuration">
      <line comment="clear int flags:"></line>
      <line comment="B15=CN B14=BCL B13=I2C B12=NVM B11=AD B10=U1TX B9=U1RX B8=SPI1"></line>
      <line comment="B7=T3 B6=T2 B5=OC2 B4=IC2 B3=T1 B2=OC1 B1=IC1 B0=INT0"></line>
      <line register="IFS0" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
      <line comment="B15:12=IC6:3 B11=C1 B10=SPI2 B9=U2TX B8=U2RX"></line>
      <line comment="B7=INT2 B6=T5 B5=T4 B4=OC4 B3=OC3 B2=IC8 B1=IC7 B0=INT1"></line>
      <line register="IFS1" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
      <line comment="B12=FLTB B11=FLTA B10=LVD B9=DCI B8=QEI"></line>
      <line comment="B7=PWM B6=C2 B5=INT4 B4=INT3 B3:0=OC8:5"></line>
      <line register="IFS2" action="W" value="0x0000" mask="0x1FFF" comment=""></line>

      <line register="IEC0" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
      <line register="IEC1" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
      <line register="IEC2" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="Reset" caption="Reset configuration">
      <line comment="B15=TRAPR B14=IOPWR B13=BGST B12=LVDEN B11:8=LVDL3:0"></line>
      <line comment="B7=EXTR B6=SWR B5=SWDTEN B4=WDTO B3=SLEEP B2=IDLE B1=BOR B0=POR"></line>
      <line register="RCON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="DSP" caption="DSP core configuration">
      <line comment="B11=EDT B10:8=DL2:0 B7=SATA B6=SATB B5=SATDW"></line>
      <line comment="B4=ACCSAT B3=IPL3 B2=PSV B1=RND B0=IF"></line>
      <line register="CORCON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="NVM" caption="NVM configuration - not implemented">
    </code>

    <code name="Oscillator" caption="Oscillator configuration">
      <line comment="method to override OSCCON write protect"></line>
      <line comment="B13:12=COSC1:0 B9:8=NOSC1:0"></line>
      <line register="OSCCON" action="LREG.b_H" value="WREG" mask="0x00FF" comment=""></line>
      <line register="W1" action="W.b_H" value="0x78" mask="0x00FF" comment=""></line>
      <line register="W2" action="W.b_H" value="0x9A" mask="0x00FF" comment=""></line>
      <line code="MOV.W #OSCCON, W3" comment=""></line>

      <line code="MOV.B W1, [W3+1]" comment=""></line>
      <line code="MOV.B W2, [W3+1]" comment=""></line>
      <line code="MOV.B W0, [W3+1]" comment=""></line>

      <line comment="B7:6=POST1:0 B5=LOCK B3=CF B1=LPOSCEN B0=OSWEN"></line>
      <line register="OSCCON" action="LREG.b_L" value="WREG" mask="0x00FF" comment=""></line>
      <line register="W1" action="W.b_L" value="0x46" mask="0x00FF" comment=""></line>
      <line register="W2" action="W.b_L" value="0x57" mask="0x00FF" comment=""></line>

      <line code="MOV.B W1, [W3+0]" comment=""></line>
      <line code="MOV.B W2, [W3+0]" comment=""></line>
      <line code="MOV.B W0, [W3+0]" comment=""></line>
    </code>

    <code name="A2D" caption="A2D configuration">
      <line register="ADPCFG" action="W" value="0xFFFF" mask="0xFFFF" comment="force all A2D ports to digital IO at first"></line>
    </code>

    <code name="IOPortA" caption="IO Ports configuration">
      <line comment="B15:0=A15:0"></line>
      <line register="PORTA" action="WREG" mask="0xFFFF" comment="enable"></line>
      <line register="TRISA" action="WREG" mask="0xFFFF" comment="direction in=1"></line>
    </code>

    <code name="IOPortB" caption="IO Ports configuration">
      <line comment="B15:0=B15:0"></line>
      <line register="PORTB" action="WREG" mask="0xFFFF" comment="enable"></line>
      <line register="TRISB" action="WREG" mask="0xFFFF" comment="direction in=1"></line>
    </code>

    <code name="IOPortC" caption="IO Ports configuration">
      <line comment="B15:0=C15:0"></line>
      <line register="PORTC" action="WREG" mask="0xFFFF" comment="enable"></line>
      <line register="TRISC" action="WREG" mask="0xFFFF" comment="direction in=1"></line>
    </code>

    <code name="IOPortD" caption="IO Ports configuration">
      <line comment="B15:0=D15:0"></line>
      <line register="PORTD" action="WREG" mask="0xFFFF" comment="enable"></line>
      <line register="TRISD" action="WREG" mask="0xFFFF" comment="direction in=1"></line>
    </code>

    <code name="IOPortE" caption="IO Ports configuration">
      <line comment="B15:0=D15:0"></line>
      <line register="PORTE" action="WREG" mask="0xFFFF" comment="enable"></line>
      <line register="TRISE" action="WREG" mask="0xFFFF" comment="direction in=1"></line>
    </code>

    <code name="IOPortF" caption="IO Ports configuration">
      <line comment="B15:0=F15:0"></line>
      <line register="PORTF" action="WREG" mask="0xFFFF" comment="enable"></line>
      <line register="TRISF" action="WREG" mask="0xFFFF" comment="direction in=1"></line>
    </code>

    <code name="IOPortG" caption="IO Ports configuration">
      <line comment="B15:0=G15:0"></line>
      <line register="PORTG" action="WREG" mask="0xFFFF" comment="enable"></line>
      <line register="TRISG" action="WREG" mask="0xFFFF" comment="direction in=1"></line>
    </code>

    <code name="CN1" caption="Input Change Notification configuration">
      <line comment="B15:0=CN15:0"></line>
      <line register="CNEN1" action="WREG" mask="0xFFFF" comment="enable change notification"></line>
      <line register="CNPU1" action="WREG" mask="0xFFFF" comment="enable pullup change notification"></line>
      <line comment="B15:0=CN21:16 B7:0=CN7:0"></line>
      <line register="CNEN2" action="WREG" mask="0x003F" comment="enable change notification"></line>
      <line register="CNPU2" action="WREG" mask="0x003F" comment="enable pullup change notification"></line>
    </code>

    <code name="Timer1" caption="Timers configuration">
      <line register="T1CON" action="W" value="0x0000" mask="0xFFFF" comment="stop timer"></line>
    </code>

    <code name="Timer2" caption="Timers configuration">
      <line register="T2CON" action="W" value="0x0000" mask="0xFFFF" comment="stop timer"></line>
    </code>

    <code name="Timer3" caption="Timers configuration">
      <line register="T3CON" action="W" value="0x0000" mask="0xFFFF" comment="stop timer"></line>
    </code>

    <code name="Timer4" caption="Timers configuration">
      <line register="T4CON" action="W" value="0x0000" mask="0xFFFF" comment="stop timer"></line>
    </code>

    <code name="Timer5" caption="Timers configuration">
      <line register="T5CON" action="W" value="0x0000" mask="0xFFFF" comment="stop timer"></line>
    </code>

    <code name="Timer1" caption="Timers configuration">
      <line register="TMR1" action="WREG" mask="0xFFFF" comment="timer register"></line>
      <line register="PR1" action="WREG" mask="0xFFFF" comment="period register"></line>
    </code>

    <code name="Timer3" caption="Timers configuration">
      <line register="TMR3" action="WREG" mask="0xFFFF" comment="timer register"></line>
      <line register="TMR3HLD" action="WREG" mask="0xFFFF" comment="timer holding register for 32bit"></line>
      <line register="PR3" action="WREG" mask="0xFFFF" comment="period register"></line>
    </code>

    <code name="Timer2" caption="Timers configuration">
      <line register="TMR2" action="WREG" mask="0xFFFF" comment="timer register"></line>
      <line register="PR2" action="WREG" mask="0xFFFF" comment="period register"></line>
    </code>


    <code name="Timer5" caption="Timers configuration">
      <line register="TMR4" action="WREG" mask="0xFFFF" comment="timer register"></line>
      <line register="PR4" action="WREG" mask="0xFFFF" comment="period register"></line>
    </code>

    <code name="Timer4" caption="Timers configuration">
      <line register="TMR5" action="WREG" mask="0xFFFF" comment="timer register"></line>
      <line register="TMR5HLD" action="WREG" mask="0xFFFF" comment="timer holding register for 32bit"></line>
      <line register="PR5" action="WREG" mask="0xFFFF" comment="period register"></line>
    </code>

    <code name="IC1" caption="Input Capture configuration">
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line register="IC1CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="IC2" caption="Input Capture configuration">
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line register="IC2CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="IC3" caption="Input Capture configuration">
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line register="IC3CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="IC4" caption="Input Capture configuration">
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line register="IC4CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="IC5" caption="Input Capture configuration">
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line register="IC5CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="IC6" caption="Input Capture configuration">
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line register="IC6CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="IC7" caption="Input Capture configuration">
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line comment="B13=ICSDL B7=ICTMR B6:5=ICI1:0 B4=ICOV B3=ICBNE B2:0=ICM2:0"></line>
      <line register="IC7CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="IC8" caption="Input Capture configuration">
      <line register="IC8CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC1" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC1CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC2" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC2CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC3" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC3CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC4" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC4CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC5" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC5CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC6" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC6CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC7" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC7CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC8" caption="Turn off OC1 thru OC8">
      <line comment="associated timers need to be turned off first"></line>
      <line register="OC8CON" action="W" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC1" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC1RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC1R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC1CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC2" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC2RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC2R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC2CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC3" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC3RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC3R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC3CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC4" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC4RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC4R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC4CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC5" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC5RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC5R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC5CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC6" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC6RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC6R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC6CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC7" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC7RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC7R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC7CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="OC8" caption="Output Compare configuration">
      <line comment="OCnRS:  output compare n secondary register"></line>
      <line comment="OCnR:   output compare 1 main register"></line>
      <line comment="OCnCON: B13=OCSIDL B4=OCFLT B3=OCTSEL B2:0=OCM2:0"></line>

      <line register="OC8RS" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC8R" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="OC8CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="SPI1" caption="SPI configuration">
      <line comment="SPInBUF:    SPI n buffer"></line>
      <line comment="SPInSTAT:   B15=SPIEN B13=SPISIDL B6=SPITBF B5=SPIROV B0=SPIRBF"></line>
      <line comment="SPInCON(H): B14=FRMEN B13=SPIFSD B11=DISSDO B10=MODE16 B9=SMP B8=CKE"></line>
      <line comment="SPInCON(L): B7=SSEN B6=CKP B5=MSTEN B4:2=SPRE2:0 B1:0=PPRE1:0"></line>

      <line register="SPI1BUF" action="R" mask="0xFFFF" comment=""></line>
      <line register="SPI1STAT" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="SPI1CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="SPI2" caption="SPI configuration">
      <line comment="SPInBUF:    SPI n buffer"></line>
      <line comment="SPInSTAT:   B15=SPIEN B13=SPISIDL B6=SPITBF B5=SPIROV B0=SPIRBF"></line>
      <line comment="SPInCON(H): B14=FRMEN B13=SPIFSD B11=DISSDO B10=MODE16 B9=SMP B8=CKE"></line>
      <line comment="SPInCON(L): B7=SSEN B6=CKP B5=MSTEN B4:2=SPRE2:0 B1:0=PPRE1:0"></line>

      <line register="SPI2BUF" action="R" mask="0xFFFF" comment="SPI 2 buffer"></line>
      <line register="SPI2STAT" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="SPI2CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="I2C" caption="I2C configuration">
      <line comment="B7:0: receive register bits7:0"></line>
      <line register="I2CRCV" action="R" mask="0x01FF" comment=""></line>
      <line comment="B9:0: address register bits9:0"></line>
      <line register="I2CADD" action="WREG" mask="0x01FF" comment=""></line>
      <line comment="B8:0: baud rate generator bits 8:0"></line>
      <line register="I2CBRG" action="WREG" mask="0x01FF" comment=""></line>
      <line comment="B15=ACKSTAT B14=TRSTAT B10=BCL B9=GCSTAT B8=ADD10"></line>
      <line comment="B7=IWCOL B6=I2COV B5=D_A B4=P B3=S B2=R_W B1=RBF B0=TBF"></line>
      <line register="I2CSTAT" action="WREG" mask="0x01FF" comment=""></line>
      <line comment="B15=I2CEN B13=I2CSIDL B12=SCLREL B11=IPMIEN B10=A10M B9=DISSLW B8=SMEN"></line>
      <line comment="B7=GCEN B6=STREN B5=ACKDT B4=ACKEN B3=RCEN B2=PEN B1=RSEN B0=SEN"></line>
      <line register="I2CCON" action="WREG" mask="0x01FF" comment=""></line>
    </code>

    <code name="UART1" caption="UART 1 configuration">
      <line register="U1BRG" action="WREG" mask="0xFFFF" comment="UART1 baud rate generator"></line>
      <line comment="B15=UTXISEL B11=UTXBRK B10=UTXEN B9=UTXBF B8=TRMT"></line>
      <line comment="B7:6=URXISEL1:0 B5=ADDEN B4=RIDLE B3=PERR B2=FERR B1=OERR B0=URXDA"></line>
      <line register="U1MODE" action="W" value="0x8000" mask="0xFFFF" comment="enabling UART flushes buffers"></line>
      <line register="U1STA" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15=UARTEN B13=USIDL B10=ALTIO"></line>
      <line comment="B7=WAKE B6=LPBACK B5=ABAUD B2:1=PDSEL1:0 B0=STSEL"></line>
      <line register="U1MODE" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="UART2" caption="UART 2 configuration">
      <line register="U2BRG" action="WREG" mask="0xFFFF" comment="UART2 baud rate generator"></line>
      <line comment="B15=UTXISEL B11=UTXBRK B10=UTXEN B9=UTXBF B8=TRMT"></line>
      <line comment="B7:6=URXISEL1:0 B5=ADDEN B4=RIDLE B3=PERR B2=FERR B1=OERR B0=URXDA"></line>
      <line register="U2MODE" action="W" value="0x8000" mask="0xFFFF" comment=""></line>
      <line register="U2STA" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15=UARTEN B13=USIDL B10=ALTIO"></line>
      <line comment="B7=WAKE B6=LPBACK B5=ABAUD B2:1=PDSEL1:0 B0=STSEL"></line>
      <line register="U2MODE" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="CAN1" caption="CAN bus configuration">
      <line comment="Always abort pending TX before init."></line>

      <line code="MOV C1CTRL, W0" comment="get current settings"></line>
      <line code="BSET W0, #12" comment="set 'abort pending TX' bit"></line>
      <line code="MOV W0, C1CTRL" comment="write to register"></line>
      <line code="MOV #0x1000, W1" comment="mask for status bit"></line>

      <line label="CAN1_TX_WAIT" comment=" wait for PIC to signal pending"></line>
      <line code="MOV C1CTRL, W0" comment="has been aborted"></line>
      <line code="AND W1, W0, W0" comment=""></line>
      <line code="BRA NZ, CAN1_TX_WAIT" comment="status bit cleared when done"></line>

      <line comment="Request CAN module go into config mode so"></line>
      <line comment="we can update configuration registers."></line>

      <line code="MOV C1CTRL, W0" comment="get current control settings"></line>
      <line code="BCLR W0, #8" comment="clear request config bits"></line>
      <line code="BCLR W0, #9" comment="clear request config bits"></line>
      <line code="BCLR W0, #10" comment="clear request config bits"></line>
      <line code="BSET W0, #10" comment="set config mode bits"></line>
      <line code="MOV W0, C1CTRL" comment="send request"></line>

      <line comment="Loop until current mode is 'config'."></line>

      <line code="MOV #0x0080, W1" comment="config mode setting"></line>
      <line code="MOV #0x00E0, W2" comment="mask for current mode bits"></line>

      <line label="CAN1_CONFIG_WAIT" comment=""></line>
      <line code="MOV C1CTRL, W0" comment="get status"></line>
      <line code="AND W2, W0, W0" comment="mask off current mode bits"></line>
      <line code="SUB W1, W0, W0" comment="compare to config mode value"></line>
      <line code="BRA NZ, CAN1_CONFIG_WAIT" comment="loop back if no match"></line>

      <line comment="RXFnSID: B12:2=RXFnSID10:0 B0=EXIDEN"></line>
      <line comment="RXFnEIDH: B11:0=EID17:6"></line>
      <line comment="RXFnEIDL: B15:10=EID5:0"></line>

      <line register="C1RXF0SID" action="WREG" mask="0xFFFF" comment="" ></line>
      <line register="C1RXF0EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF0EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF0EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF0EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF2SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF2EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF2EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF3SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF3EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF3EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF4SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF4EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF4EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF5SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF5EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXF5EIDL" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="RXMnSID: B12:2=RXFnSID10:0 B0=EXIDEN"></line>
      <line comment="RXMnEIDH: B11:0=EID17:6"></line>
      <line comment="RXMnEIDL: B15:10=EID5:0"></line>

      <line register="C1RXM0SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXM0EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXM0EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXM1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXM1EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RXM1EIDL" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="TXnSID: B15:11=TXnSID10:6 B7:2=SID5:0 B1=SRR B0=EXIDEN"></line>
      <line comment="TXnEID: B15:12=EID17:14 B9:0=EID13:6"></line>
      <line comment="TXnDLC: B15:10=EID5:0 B9=RTR B8:7=RB1:0 B6:3=DLC3:0"></line>
      <line comment="TXnCON: B6=TXABT B5=TXLARB B4=TXERR B3=TXREQ B1:0=TXPRI1:0"></line>

      <line register="C1TX2SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX2EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX2DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX2CON" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX1EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX1DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX1CON" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX0SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX0EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX0DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1TX0CON" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="RXnSID: B12:2=SID10:0 B1=SRR B0=EXIDEN"></line>
      <line comment="RXnEID: B11:0=EID17:6"></line>
      <line comment="RXnDLC: B15:10=EID5:0 B9=RTR B8=RB1 B4=RB0 B3:0=DLC3:0"></line>
      <line comment="RXnCON: B7=RXFUL B3=RXRTRO B2=DBEN B1=JTOFF B0=FILHIT0"></line>

      <line register="C1RX1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RX1EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RX1DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RX1CON" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RX0SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RX0EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RX0DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C1RX0CON" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="B7:6=SJWS1:0 B5:0=BRP"></line>
      <line register="C1CFG1" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B14=WAKFIL B10:8=SEG2PH"></line>
      <line comment="B7=BTLMODE B6=SAM B5:3=SEG1PH B2:0=PRSEG"></line>
      <line register="C1CFG2" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15=CANCAP B13=CSIDLE B12=ABAT B11=CANCKS B10:8=REQOP2:0 B7:5=OPMODE2:0 B3:1=ICODE2:0"></line>
      <line register="C1CTRL" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="Flags: B15=RX0OVR B14=RX1OVR B13=TXBO B12=TXEP"></line>
      <line comment="Flags: B11=RXEP B10=TXWAR B9=RXWAR B8=EWARN"></line>
      <line comment="Flags IF, Enables IE: B7=IVRI B6=WAK B5=ERR B4=TX2 B3=TX1 B2=TX0 B1=RX1 B0=RX0"></line>
      <line register="C1INTF" action="W" value="0x0000" mask="0xFFFF" comment="clear all flags"></line>
      <line register="C1INTE" action="WREG" mask="0xFFFF" comment=""></line>

      <line register="C1EC" action="W" value="0x0000" mask="0xFFFF" comment="clear tx and rx error registers"></line>

      <line comment="request post-config operating mode for CAN module "></line>

      <line register="C1CTRL" action="WREG" mask="0x2700" comment="send post config settings"></line>

      <line code="MOV C1CTRL, W1" comment="get requested mode"></line>
      <line code="MOV #0x0700, W2" comment="remove all but desired bits"></line>
      <line code="AND W1, W2, W1" comment="remove all but desired bits"></line>
      <line code="LSR W1, #0x03, W1" comment="shift bits to current mode location"></line>
      <line code="MOV #0x00E0, W2" comment="mask for current mode bits"></line>

      <line label="CAN1_OPMODE_WAIT" comment=""></line>
      <line code="MOV C1CTRL, W0" comment="get status"></line>
      <line code="AND W2, W0, W0" comment="mask off current mode bits"></line>
      <line code="SUB W1, W0, W0" comment="compare to config mode value"></line>
      <line code="BRA NZ, CAN1_OPMODE_WAIT" comment="loop back if no match"></line>
    </code>

    <code name="CAN2" caption="CAN bus configuration">
      <line comment="Always abort pending TX before init."></line>

      <line code="MOV C2CTRL, W0" comment="get current settings"></line>
      <line code="BSET W0, #12" comment="set 'abort pending TX' bit"></line>
      <line code="MOV W0, C2CTRL" comment="write to register"></line>
      <line code="MOV #0x1000, W1" comment="mask for status bit"></line>

      <line label="CAN2_TX_WAIT" comment=" wait for PIC to signal pending"></line>
      <line code="MOV C2CTRL, W0" comment="has been aborted"></line>
      <line code="AND W1, W0, W0" comment=""></line>
      <line code="BRA NZ, CAN2_TX_WAIT" comment="status bit cleared when done"></line>

      <line comment="Request CAN module go into config mode so"></line>
      <line comment="we can update configuration registers."></line>

      <line code="MOV C2CTRL, W0" comment="get current control settings"></line>
      <line code="BCLR W0, #8" comment="clear request config bits"></line>
      <line code="BCLR W0, #9" comment="clear request config bits"></line>
      <line code="BCLR W0, #10" comment="clear request config bits"></line>
      <line code="BSET W0, #10" comment="set config mode bits"></line>
      <line code="MOV W0, C2CTRL" comment="send request"></line>

      <line comment="Loop until current mode is 'config'."></line>

      <line code="MOV #0x0080, W1" comment="config mode setting"></line>
      <line code="MOV #0x00E0, W2" comment="mask for current mode bits"></line>

      <line label="CAN2_CONFIG_WAIT" comment=""></line>
      <line code="MOV C2CTRL, W0" comment="get status"></line>
      <line code="AND W2, W0, W0" comment="mask off current mode bits"></line>
      <line code="SUB W1, W0, W0" comment="compare to config mode value"></line>
      <line code="BRA NZ, CAN2_CONFIG_WAIT" comment="loop back if no match"></line>

      <line comment="RXFnSID: B12:2=RXFnSID10:0 B0=EXIDEN"></line>
      <line comment="RXFnEIDH: B11:0=EID17:6"></line>
      <line comment="RXFnEIDL: B15:10=EID5:0"></line>

      <line register="C2RXF0SID" action="WREG" mask="0xFFFF" comment="" ></line>
      <line register="C2RXF0EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF0EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF0EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF0EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF2SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF2EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF2EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF3SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF3EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF3EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF4SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF4EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF4EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF5SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF5EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXF5EIDL" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="RXMnSID: B12:2=RXFnSID10:0 B0=EXIDEN"></line>
      <line comment="RXMnEIDH: B11:0=EID17:6"></line>
      <line comment="RXMnEIDL: B15:10=EID5:0"></line>

      <line register="C2RXM0SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXM0EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXM0EIDL" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXM1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXM1EIDH" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RXM1EIDL" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="TXnSID: B15:11=TXnSID10:6 B7:2=SID5:0 B1=SRR B0=EXIDEN"></line>
      <line comment="TXnEID: B15:12=EID17:14 B9:0=EID13:6"></line>
      <line comment="TXnDLC: B15:10=EID5:0 B9=RTR B8:7=RB1:0 B6:3=DLC3:0"></line>
      <line comment="TXnCON: B6=TXABT B5=TXLARB B4=TXERR B3=TXREQ B1:0=TXPRI1:0"></line>

      <line register="C2TX2SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX2EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX2DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX2CON" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX1EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX1DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX1CON" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX0SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX0EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX0DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2TX0CON" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="RXnSID: B12:2=SID10:0 B1=SRR B0=EXIDEN"></line>
      <line comment="RXnEID: B11:0=EID17:6"></line>
      <line comment="RXnDLC: B15:10=EID5:0 B9=RTR B8=RB1 B4=RB0 B3:0=DLC3:0"></line>
      <line comment="RXnCON: B7=RXFUL B3=RXRTRO B2=DBEN B1=JTOFF B0=FILHIT0"></line>

      <line register="C2RX1SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RX1EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RX1DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RX1CON" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RX0SID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RX0EID" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RX0DLC" action="WREG" mask="0xFFFF" comment=""></line>
      <line register="C2RX0CON" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="B7:6=SJWS1:0 B5:0=BRP"></line>
      <line register="C2CFG1" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B14=WAKFIL B10:8=SEG2PH"></line>
      <line comment="B7=BTLMODE B6=SAM B5:3=SEG1PH B2:0=PRSEG"></line>
      <line register="C2CFG2" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15=CANCAP B13=CSIDLE B12=ABAT B11=CANCKS B10:8=REQOP2:0 B7:5=OPMODE2:0 B3:1=ICODE2:0"></line>
      <line register="C2CTRL" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="Flags: B15=RX0OVR B14=RX1OVR B13=TXBO B12=TXEP"></line>
      <line comment="Flags: B11=RXEP B10=TXWAR B9=RXWAR B8=EWARN"></line>
      <line comment="Flags IF, Enables IE: B7=IVRI B6=WAK B5=ERR B4=TX2 B3=TX1 B2=TX0 B1=RX1 B0=RX0"></line>
      <line register="C2INTF" action="W" value="0x0000" mask="0xFFFF" comment="clear all flags"></line>
      <line register="C2INTE" action="WREG" mask="0xFFFF" comment=""></line>

      <line register="C2EC" action="W" value="0x0000" mask="0xFFFF" comment="clear tx and rx error registers"></line>

      <line comment="request post-config operating mode for CAN module "></line>

      <line register="C2CTRL" action="WREG" mask="0x2700" comment="send post config settings"></line>

      <line code="MOV C2CTRL, W1" comment="get requested mode"></line>
      <line code="MOV #0x0700, W2" comment="remove all but desired bits"></line>
      <line code="AND W1, W2, W1" comment="remove all but desired bits"></line>
      <line code="LSR W1, #0x03, W1" comment="shift bits to current mode location"></line>
      <line code="MOV #0x00E0, W2" comment="mask for current mode bits"></line>

      <line label="CAN2_OPMODE_WAIT" comment=""></line>
      <line code="MOV C2CTRL, W0" comment="get status"></line>
      <line code="AND W2, W0, W0" comment="mask off current mode bits"></line>
      <line code="SUB W1, W0, W0" comment="compare to config mode value"></line>
      <line code="BRA NZ, CAN2_OPMODE_WAIT" comment="loop back if no match"></line>
    </code>

    <code name="PWM" caption="Motor PWM configuration">
      <line comment="clears and preparation"></line>
      <line register="PTCON" action="W" value="0x0000" mask="0xFFFF" comment="disable during init"></line>
      <line register="PTMR" action="WREG" mask="0xFFFF" comment="timer counter"></line>
      <line register="PTPER" action="WREG" mask="0x7FFF" comment="count period"></line>
      <line register="SEVTCMP" action="WREG" mask="0xFFFF" comment="special event condition"></line>

      <line comment="B11:8=PTMOD3:0 B7:4=PENnH,n=0,3 B3:0=PENnL,n=0,3"></line>
      <line register="PWMCON1" action="WREG" mask="0x0FFF" comment=""></line>
      <line comment="B11:8=SEVOPS3:0 B1=OSYNC B0=UDIS"></line>
      <line register="PWMCON2" action="WREG" mask="0x0F03" comment=""></line>

      <line comment="dead time"></line>
      <line comment="B15:14=DTBPS B13:8=DTBValue5:0 B7:6=DTAPS1:0 B5:0=DTAValue5:0"></line>
      <line register="DTCON1" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B7=DTS4A B6=DTS4I B5=DTS3A B4=DTS3I B3=DTS2A B2=DTS2I B1=DTS1A B0=DTS1I"></line>
      <line register="DTCON2" action="WREG" mask="0x00FF" comment=""></line>

      <line comment="faults"></line>
      <line comment="B15=FAOV4H B14=FAOV4L B13=FAOV3H B12=FAOV3L"></line>
      <line comment="B7=B11=FAOV2H B10=FAOV2L B9=FAOV1H B8=FAOV1L FLTAM B3:0=FAEN4:1"></line>
      <line register="FLTACON" action="WREG" mask="0xFF8F" comment=""></line>
      <line comment="B15=FBOV4H B14=FBOV4L B13=FBOV3H B12=FBOV3L"></line>
      <line comment="B11=FBOV2H B10=FBOV2L B9=FBOV1H B8=FBOV1L B7=FLTBM B3:0=FBEN4:1"></line>
      <line register="FLTBCON" action="WREG" mask="0xFF8F" comment=""></line>
      <line comment="B15=POVD4H B14=POVD4L B13=POVD3H B12=POVD3L"></line>
      <line comment="B11=POVD2H B10=POVD2L B9=POVD1H B8=POVD1L"></line>
      <line comment="B15=POUT4H B14=POUT4L B13=POUT3H B12=POUT3L"></line>
      <line comment="B11=POUT2H B10=POUT2L B9=POUT1H B8=POUT1L"></line>
      <line register="OVDCON" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="duty cycle"></line>
      <line register="PDC1" action="WREG" mask="0xFFFF" comment="duty cycle register 1"></line>
      <line register="PDC2" action="WREG" mask="0xFFFF" comment="duty cycle register 2"></line>
      <line register="PDC3" action="WREG" mask="0xFFFF" comment="duty cycle register 3"></line>
      <line register="PDC4" action="WREG" mask="0xFFFF" comment="duty cycle register 4"></line>

      <line comment="final enable"></line>
      <line comment="B15=PTEN B13=PTSIDL B7:4=PTOPS3:0 B3:2=PRCKPS"></line>
      <line register="PTCON" action="WREG" mask="0xA0FF" comment=""></line>
    </code>

    <code name="QEI" caption="QEI configuration">
      <line register="QEICON" action="W" value="0x0000" mask="0xFFFF" comment="hard clear"></line>
      <line comment="B7=QEOUT B6:4=QECK2:0 B3=INDOUT B2:0=INDCK2:0"></line>
      <line register="DFLTCON" action="WREG" mask="0x00FF" comment=""></line>
      <line register="POSCNT" action="WREG" mask="0xFFFF" comment="clear position counter"></line>
      <line register="MAXCNT" action="WREG" mask="0xFFFF" comment="clear maximum count"></line>
      <line comment="B15=CNTERR B13=QEISIDL B12=INDX B11=UPDN B10:8=QEIM2:0"></line>
      <line comment="B7=SWPAB B6=PCDOUT B5=TQGATE"></line>
      <line comment="B4:3=TQCLPS1:0 B2=POSRES B1=TQCS B0=UPDN_CNT"></line>
      <line register="QEICON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="DCI" caption="DCI configuration">
      <line register="DCICON1" action="WMAN" value="0x0000" mask="0xFFFF" comment="hard clear to disable during init"></line>

      <line register="RXBUF0" action="R" mask="0xFFFF" comment="flush buffer 0"></line>
      <line register="RXBUF1" action="R" mask="0xFFFF" comment="flush buffer 1"></line>
      <line register="RXBUF2" action="R" mask="0xFFFF" comment="flush buffer 2"></line>
      <line register="RXBUF3" action="R" mask="0xFFFF" comment="flush buffer 3"></line>

      <line comment="B15:0=TSE15:0"></line>
      <line register="TSCON" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15:0=RSE15:0"></line>
      <line register="RSCON" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B11:8=SLOT3:0 B3=ROV B2=RFUL B1=TUNF B0=TMPTY"></line>
      <line register="DCISTAT" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B11:0=BCG "></line>
      <line register="DCICON3" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B11:10=BLEN1:0 B8:5=COFSG3:0 B3:0=WS"></line>
      <line register="DCICON2" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15=DCIEN B13=DCISIDL B11=DLOOP B10=CSCKD B9=CSCKE B8=COFSD"></line>
      <line comment="B7=UNFM B6=CSDOM B5=DJST B1:0=COFSM1:0"></line>
      <line register="DCICON1" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="A2D" caption="A2D configuration">
      <line register="ADCON1" action="W" value="0x0000" mask="0xFFFF" comment="Turn off A2D before setting registers"></line>
      <line comment="B15:0=CSSL15:0"></line>
      <line register="ADCSSL" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15:14=CH123NB1:0 B13=CH123SB B12=CH0NB B11:8=CH0SB3:0"></line>
      <line comment="B7:6=CH123NA1:0 B5=CH123SA B4=CH0NA B3:0=CH0SA3:0"></line>
      <line register="ADCHS" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15:0=PCFG15:0"></line>
      <line register="ADPCFG" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B12:8=SAMC4:0 B7=ADRC B5:0=ADCS5:0"></line>
      <line register="ADCON3" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15:13=VCFG2:0 B12=OFFCAL B10=CSCNA B9:8=CHPS1:0"></line>
      <line comment="B7=BUFS B5:2=SMPI B1=BUFM B0=ALTS"></line>
      <line register="ADCON2" action="WREG" mask="0xFFFF" comment=""></line>
      <line comment="B15=ADON B13=ADSIDL B12=ADSTBY B9:8=FORM"></line>
      <line comment="B7:5=SSRC B3=SIMSAM B2=ASAM B1=SAMP B0=CONV"></line>
      <line register="ADCON1" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="required" caption="Interrupt flags cleared and interrupt configuration">
      <line comment="interrupt priorities IP"></line>
      <line comment="B14:12=T1 B10:8=OC1 B6:4=IC1 B2:0=INTO"></line>
      <line register="IPC0" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=T3 B10:8=T2 B6:4=OC2 B2:0=IC2"></line>
      <line register="IPC1" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=AD B10:8=U1TX B6:4=U1RX B2:0=SPI1"></line>
      <line register="IPC2" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=CN B10:8= BCLB6:4=I2C B2:0=NVM"></line>
      <line register="IPC3" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=OC3 B10:8=IC8 B6:4=IC7 B2:0=INT1"></line>
      <line register="IPC4" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=INT2 B10:8=T5 B6:4=T4 B2:0=OC4"></line>
      <line register="IPC5" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=C1 B10:8=SPI2 B6:4=U2TX B2:0=U2RX"></line>
      <line register="IPC6" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=IC6 B10:8=IC5 B6:4=IC4 B2:0=IC3"></line>
      <line register="IPC7" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=OC8 B10:8=OC7 B6:4=OC6 B2:0=OC5"></line>
      <line register="IPC8" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=PWM B10:8=C2 B6:4=INT4 B2:0=INT3"></line>
      <line register="IPC9" action="WREG" mask="0x7777" comment=""></line>
      <line comment="B14:12=FLTA B10:8=LVD B6:4=DCI B2:0=QEI"></line>
      <line register="IPC10" action="WREG" mask="0x7777" comment=""></line>

      <line comment="external interrupt enables"></line>
      <line comment="B15=NSTDIS B10=OVATE B9=OVBTE B8=COVTE"></line>
      <line comment="B4=MATHERR B3=ADDRERR B2=STKERR B1=OSCFAIL"></line>
      <line register="INTCON1" action="WREG" mask="0x801E" comment=""></line>
      <line comment="B15=ALTIVT B4:0=INTnEP4:0"></line>
      <line register="INTCON2" action="WREG" mask="0x801F" comment=""></line>
    </code>

    <code name="Timer1" caption="Start timers">
      <line comment="Timers1: B15=TON B13=TSIDL B5=TGATE B5:4=TCKPS1:0 B2=TSYNC B1=TCS"></line>
      <line register="T1CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="Timer3" caption="Start timers">
      <line comment="Timers3,5:   B15=TON B13=TSIDL B5=TGATE B5:4=TCKPS1:0 B1=TCS"></line>
      <line register="T3CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="Timer2" caption="Start timers">
      <line comment="Timers2,4:   B15=TON B13=TSIDL B5=TGATE B5:4=TCKPS1:0 B3=T32 B1=TCS"></line>
      <line register="T2CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="Timer5" caption="Start timers">
      <line comment="Timers3,5:   B15=TON B13=TSIDL B5=TGATE B5:4=TCKPS1:0 B1=TCS"></line>
      <line register="T5CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="Timer4" caption="Start timers">
      <line comment="Timers2,4:   B15=TON B13=TSIDL B5=TGATE B5:4=TCKPS1:0 B3=T32 B1=TCS"></line>
      <line register="T4CON" action="WREG" mask="0xFFFF" comment=""></line>
    </code>

    <code name="CPU" caption="CPU register configuration">
      <line register="SR" action="WMAN" value="0x0000" mask="0xFFFF" comment=""></line>
      <line register="SR" action="WREGMAN" mask="0xFFFF" comment=""></line>

      <line register="W0" action="WMAN" value="0x0000" mask="0xFFFF" comment=""></line>
      <line register="W1" action="WMAN" value="0x0000" mask="0xFFFF" comment=""></line>
      <line register="W2" action="WMAN" value="0x0000" mask="0xFFFF" comment=""></line>
    </code>

    <code name="Interrupts" caption="enable interrupts">
      <line comment="feature interrupt enables IE"></line>

      <line comment="B15=CN B14=BCL B13=I2C B12=NVM B11=AD B10=U1TX B9=U1RX B8=SPI1"></line>
      <line comment="B7=T3 B6=T2 B5=OC2 B4=IC2 B3=T1 B2=OC1 B1=IC1 B0=INT0"></line>
      <line register="IEC0" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="B15:12=IC6:3 B11=C1 B10=SPI2 B9=U2TX B8=U2RX"></line>
      <line comment="B7=INT2 B6=T5 B5=T4 B4=OC4 B3=OC3 B2=IC8 B1=IC7 B0=INT1"></line>
      <line register="IEC1" action="WREG" mask="0xFFFF" comment=""></line>

      <line comment="B12=FLTB B11=FLTA B10=LVD B9=DCI B8=QEI"></line>
      <line comment="B7=PWM B6=C2 B5=INT4 B4=INT3 B3:0=OC8:5"></line>
      <line register="IEC2" action="WREG" mask="0x1FFF" comment=""></line>

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

  </codeBlock>
</codeDefinitions>
