 
format=0.1

#device=PIC18F1331

vpp (range=9.000-13.250 dflt=13.000)
vdd (range=2.000-5.500 dfltrange=4.250-5.500 nominal=5.000)

pgming (memtech=ee tries=1 lvpthresh=4.500 panelsize=0)
    wait (pgm=1000 lvpgm=1000 eedata=4000 cfg=5000 userid=5000 erase=10000 lverase=1000)
    latches(pgm=8 eedata=2 userid=8 cfg=2 rowerase=64)   	

pgmmem (region=0x0-0x1FFF)
eedata (region=0x00-0x7f)

cfgmem (region=0x300000-0x30000D)
testmem (region=0x200000-0x2000FF)
userid (region=0x200000-0x200007)
#
# The end address has been changed from a 0x2B to a 0x37 for the ICD2
bkbgvectmem (region=0x200028-0x200037)
devid (region=0x3FFFFE-0x3FFFFF idmask=0xFFE0 id=0x1EA0)
    ver (id=0x1EA0 desc="rev a")
    
UnusedBankMask=0x7FFE
AccessBankSplitOffset=0x80
NumBanks=16

UnusedRegs (0xf00-0xf7f)
unusedRegs (0xf94-0xf94)
unusedRegs (0xf9c-0xf9c)
UnusedRegs (0xfba-0xfbf)
UnusedRegs (0xfc5-0xfcc)



                               # ---------------#
#------------------------------# CORE Registers #------------------------------------------------#
                               # ---------------#

sfr (key=TOS addr=0xFFD size=3 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='- - - TOS' width='1 1 1 2 1')
sfr (key=TOSU addr=0xFFF size=1 access='u u u rw rw rw rw rw')
    reset (por='---00000' mclr='---00000')
    bit (names='- - - TOSU' width='1 1 1 5')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=TOSH addr=0xFFE size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='TOSH' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=TOSL addr=0xFFD size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='TOSL' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=STKPTR addr=0xFFC size=1 access='rc rc u rw rw rw rw rw')
    reset (por='00-00000' mclr='00-00000')
    bit (names='STKFUL STKUNF - STKPTR' width='1 1 1 5')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=PCLAT addr=0xFF9 size=3 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='- - - PCLAT' width='1 1 1 2 1')
sfr (key=PCLATU addr=0xFFB size=1 access='u u u rw rw rw rw rw')
    reset (por='---00000' mclr='---00000')
    bit (names='- - - PCU' width='1 1 1 5')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PCLATH addr=0xFFA size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='PCH' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PCL addr=0xFF9 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='PCL' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=TBLPTR addr=0xFF6 size=3 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='- - ACSS TBLPTR' width='1 1 1 2 1')
sfr (key=TBLPTRU addr=0xFF8 size=1 access='u u rw rw rw rw rw rw')
    # NOTE: The ACSS bit allows access to the device configuration bits
    reset (por='--000000' mclr='--000000')
    bit (names='- - ACSS TBLPTRU' width='1 1 1 5')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=TBLPTRH addr=0xFF7 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='TBLPTRH' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=TBLPTRL addr=0xFF6 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='TBLPTRL' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=TABLAT addr=0xFF5 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='TABLAT' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=PROD addr=0xFF3 size=2 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='PROD' width='16')
sfr (key=PRODH addr=0xFF4 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='PRODH' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PRODL addr=0xFF3 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='PRODL' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=INTCON addr=0xFF2 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='0000000x' mclr='0000000u')
    bit (names='GIE/GIEH PEIE/GIEL TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF')
    # NOTE: When IPEN (bit 7) in the RCON register is 0 use the following bit names
    qbit (names='GIE PEIE TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF')
    # NOTE: When IPEN (bit 7) in the RCON register is 1 use the following bit names
    qbit (names='GIEH GIEL TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF')
    bit (tag=scl names='GIE_GIEH PEIE_GIEL TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=INTCON2 addr=0xFF1 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='11111111' mclr='11111111')
    bit (names='nRBPU INTEDG0 INTEDG1 INTEDG2 INTEDG3 TMR0IP INT3IP RBIP')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=INTCON3 addr=0xFF0 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='11000000' mclr='11000000')
    bit (names='INT2IP INT1IP INT3IE INT2IE INT1IE INT31F INT2IF INT1IF')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=INDF0 addr=0xFEF size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='INDF0' width='8')
sfr (key=POSTINC0 addr=0xFEE size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='POSTINC0' width='8')
sfr (key=POSTDEC0 addr=0xFED size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='POSTDEC0' width='8')
sfr (key=PREINC0 addr=0xFEC size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='PREINC0' width='8')
sfr (key=PLUSW0 addr=0xFEB size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='PLUSW0' width='8')

sfr (key=FSR0 addr=0xFE9 size=2 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='- - - - FSR0' width='1 1 1 1 12')
sfr (key=FSR0H addr=0xFEA size=1 access='u u u u rw rw rw rw')
    reset (por='----0000' mclr='----uuuu')
    bit (names='- - - - FSR0H' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=FSR0L addr=0xFE9 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='FSR0L' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=WREG addr=0xFE8 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='WREG' width='8')
    stimulus (scl=rwb type=int regfiles=w pcfiles=rw)
sfr (key=INDF1 addr=0xFE7 size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='INDF1' width='8')
sfr (key=POSTINC1 addr=0xFE6 size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='POSTINC1' width='8')
sfr (key=POSTDEC1 addr=0xFE5 size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='POSTDEC1' width='8')
sfr (key=PREINC1 addr=0xFE4 size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='PREINC1' width='8')
sfr (key=PLUSW1 addr=0xFE3 size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='PLUSW1' width='8')

sfr (key=FSR1 addr=0xFE1 size=2 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='- - - - FSR1' width='1 1 1 1 12')
sfr (key=FSR1H addr=0xFE2 size=1 access='u u u u rw rw rw rw')
    reset (por='----0000' mclr='----uuuu')
    bit (names='- - - - FSR1H' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=FSR1L addr=0xFE1 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='FSR1L' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=BSR addr=0xFE0 size=1 access='u u u u rw rw rw rw')
    reset (por='----0000' mclr='----0000')
    bit (names='- - - - BSR' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=INDF2 addr=0xFDF size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='INDF2' width='8')
sfr (key=POSTINC2 addr=0xFDE size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='POSTINC2' width='8')
sfr (key=POSTDEC2 addr=0xFDD size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='POSTDEC2' width='8')
sfr (key=PREINC2 addr=0xFDC size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='PREINC2' width='8')
sfr (key=PLUSW2 addr=0xFDB size=1 flags=i access='u u u u u u u u')
    reset (por='--------' mclr='--------')
    bit (names='PLUSW2' width='8')


sfr (key=FSR2 addr=0xFD9 size=2 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='- - - - FSR2' width='1 1 1 1 12')
sfr (key=FSR2H addr=0xFDA size=1 access='u u u u rw rw rw rw')
    reset (por='----0000' mclr='----0000')
    bit (names='- - - - FSR2H' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=FSR2L addr=0xFD9 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='FSR2L' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=STATUS addr=0xFD8 size=1 access='u u u rw rw rw rw rw')
    reset (por='---xxxxx' mclr='---uuuuu')
    bit (names='- - - N OV Z DC C')

sfr (key=OSCCON addr=0xFD3 size=1 access='rw rw rw rw r r rw rw')
    reset (por='0000q000' mclr='000000q0')
    bit (names='IDLEN IRCF OSTS IOFS SCS' width='1 3 1 1 2')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=LVDCON addr=0xFD2 size=1 access='u u r rw rw rw rw rw')
    reset (por='--000101' mclr='--000101')
    bit (names='- - IRVST LVDEN LVDL' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=WDTCON addr=0xFD1 size=1 access='u u u u u u u rw')
    reset (por='-------0' mclr='-------0')
    bit (names='- - - - - - - SWDTEN')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=RCON addr=0xFD0 size=1 access='rw u u rw rw rw rw rw')
# The reset values are inconsistent in the Data Sheet
# so these values might be incorrect.
    reset (por='01-11100' mclr='01-uqquu')
    bit (names='IPEN SBOREN - nRI nTO nPD nPOR nBOR')
    stimulus (scl=r regfiles=w pcfiles=rw)

#Added by Akram 
#Reset values information has to be verified.    
sfr (key=BAUDCTL addr=0xFB8 size=1 access='rw rw u rw rw u rw rw')
    reset (por='1111-1-1' mclr='1111-1-1')
    bit (names='ABDOVF RCMT - SCKP BRG16 - WUE ABDEN' width='1 1 1 1 1 1 1 1')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
    
sfr (key=CVRCON addr=0xFB5 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='11111111' mclr='11111111')
    bit (names='CVREN CVROE CVRR CVRSS CVR' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=CMCON addr=0xFB4 size=1 access='rw rw rw u u rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='C2OUT C1OUT C0OUT - - CMEN' width='1 1 1 1 1 3')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

sfr (key=IPR3 addr=0xFA5 size=1 access='u u u rw u u u u')
    reset (por='---1----' mclr='---1----')
    bit (names='- - - PTIP - - - -')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PIR3 addr=0xFA4 size=1 access='rw u u rw u rw rw u')
   reset (por='---0----' mclr='---0----')
   bit (names='- - - PTIE - - - -')
   stimulus (scl=rwb regfiles=w pcfiles=rw)
   
sfr (key=PIE3 addr=0xFA3 size=1 access='rw u u rw u rw rw u')
   reset (por='---0----' mclr='---0----')
   bit (names='- - - PTIF - - - -')
   stimulus (scl=rwb regfiles=w pcfiles=rw)
   
#Added by Akram     
#Reset values information has to be verified. 
sfr (key=IPR2 addr=0xFA2 size=1 access='rw u u rw u rw rw u')
    reset (por='1--1-11-' mclr='1--1-11-')
    bit (names='OSCFIP - - EEIP - LVDIP TMR3IP -')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PIR2 addr=0xFA1 size=1 access='rw u u rw u rw rw u')
    reset (por='0--0-00-' mclr='0--0-00-')
    bit (names='OSCFIF - - EEIF - LVDIF TMR3IF -')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PIE2 addr=0xFA0 size=1 access='rw u u rw u rw rw u')
    reset (por='0--0-00-' mclr='0--0-00-')
    bit (names='OSCFIE - - EEIE - LVDIE TMR3IE -')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=IPR1 addr=0xF9F size=1 access='u rw rw rw rw rw rw rw')
    reset (por='01111111' mclr='01111111')
    bit (names='- ADIP RCIP TXIP CMP2IP CMP1IP CMP0IP TMR1IP')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PIR1 addr=0xF9E size=1 access='u rw r r rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='- ADIF RCIF TXIF CMP2IF CMP1IF CMP0IF TMR1IF')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=PIE1 addr=0xF9D size=1 access='u rw rw rw rw rw rw rw')
    reset (por='-0000000' mclr='-0000000')
    bit (names='- ADIE RCIE TXIE CMP2IE CMP1IE CMP0IE TMR1IE')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

#Added by Akram 
#Reset values information has to be verified. 
sfr (key=PTCON0 addr=0xF9A size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='PTOPS PTCKPS PTMOD' width='4 2 2')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
  
   
sfr (key=PTCON1 addr=0xF99 size=1 access='rw rw u u u u u u')
    reset (por='00------' mclr='00------')
    bit (names='PTEN PTDIR - - - - - -')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
    
    

                               # --------------#
#------------------------------# PWM Registers #----------------------------------------------------------------------------#
                               # --------------#
    
sfr (key=PTMRL addr=0xF98 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='PTMRL' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=PTMRH addr=0xF97 size=1 access='u u u u rw rw rw rw')
    reset (por='----0000' mclr='----0000')
    bit (names='- - - - PTMRH' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w)
sfr (key=PTPERL addr=0xF96 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='11111111' mclr='11111111')
    bit (names='PTPERL' width='8')
    stimulus (scl=rwb regfiles=w)

sfr (key=PTPERH addr=0xF95 size=1 access='u u u u rw rw rw rw')
    reset (por='----1111' mclr='----1111')
    bit (names='- - - - PTPERH' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w)    
        
sfr (key=PDC0L addr=0xF91 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='PDC0L' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=PDC0H addr=0xF90 size=1 access='u u rw rw rw rw rw rw')
    reset (por='--000000' mclr='--000000')
    bit (names='- - PDC0H' width='1 1 6')
    stimulus (scl=rwb regfiles=w)
sfr (key=PDC1L addr=0xF8F size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='PDC1L' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=PDC1H addr=0xF8E size=1 access='u u rw rw rw rw rw rw')
    reset (por='--000000' mclr='--000000')
    bit (names='- - PDC1H' width='1 1 6')
    stimulus (scl=rwb regfiles=w)
sfr (key=PDC2L addr=0xF8D size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='PDC2L' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=PDC2H addr=0xF8C size=1 access='u u rw rw rw rw rw rw')
    reset (por='--000000' mclr='--000000')
    bit (names='- - PDC2H' width='1 1 6')
    stimulus (scl=rwb regfiles=w)
    
sfr (key=FLTCONFIG addr=0xF8B size=1 access='rw u u u u rw rw rw')
    reset (por='0----000' mclr='0----000')
    bit (names='BRFEN - - - - FLTAS FLTAMOD FLTAEN')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
    
sfr (key=SEVTCMPL addr=0xF88 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='SEVTCMPL' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=SEVTCMPH addr=0xF87 size=1 access='u u u u rw rw rw rw')
    reset (por='----0000' mclr='----0000')
    bit (names='- - - - SEVTCMPH' width='1 1 1 1 4')
    stimulus (scl=rwb regfiles=w)

sfr (key=PWMCON0 addr=0xF86 size=1 access='u rw rw rw rw rw rw rw')
    reset (por='-1010000' mclr='-1010000')
    bit (names='- PWMEN PMOD' width='1 3 4')
    stimulus (scl=rwb regfiles=w)
sfr (key=PWMCON1 addr=0xF85 size=1 access='rw rw rw rw rw u rw rw')
    reset (por='00000-00' mclr='00000-00')
    bit (names='SEVOPS SEVTDIR - UDIS OSYNC' width='4 1 1 1 1')
    stimulus (scl=rwb regfiles=w)

sfr (key=DTCON addr=0xF84 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='DTAPS DTA' width='2 6')
    stimulus (scl=rwb regfiles=w)
sfr (key=OVDCOND addr=0xF83 size=1 access='u u rw rw rw rw rw rw')
    reset (por='--111111' mclr='--111111')
    bit (names='- - POVD' width='1 1 6')
    stimulus (scl=rwb regfiles=w)
sfr (key=OVDCONS addr=0xF82 size=1 access='u u rw rw rw rw rw rw')
    reset (por='--000000' mclr='--000000')
    bit (names='- - POUT' width='1 1 6')
    stimulus (scl=rwb regfiles=w)


   
#Reset values information has to be verified. 
#Added by Akram 

                               # ---------------------#
#------------------------------# Oscillator Registers #----------------------------------------------------------------------------#
                               # ---------------------#

sfr (key=OSCTUNE addr=0xF9B size=1 access='u u rw rw rw rw rw rw')
    reset (por='--000000' mclr='--000000')
    bit (names='- - TUN' width='1 1 6')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

                               # ----------------#
#------------------------------# PORTA Registers #-------------------------------------------------#
                               # ----------------#

# Bits 6 and 7 of PORTA, LATA, and TRISA are enabled, depending on the Oscillator mode selected.  
# When not enabled as PORTA pins, they are disabled and read '0'.  Bit 5 of PORTA is enabled if 
# MCLR is disabled.

sfr (key=PORTA addr=0xF80 size=1 access='rw rw r rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0')
    bit (tag=scl names='RA' width='8')
    stimulus (scl=rwb regfiles=rw pcfiles=rw)
sfr (key=LATA addr=0xF89 size=1 access='rw rw u rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='LATA7 LATA6 LATA5 LATA4 LATA3 LATA2 LATA1 LATA0')
    bit (tag=scl names='LATA' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=TRISA addr=0xF92 size=1 access='rw rw u rw rw rw rw rw')
    reset (por='11-11111' mclr='11-11111')
    bit (names='TRISA7 TRISA6 - TRISA4 TRISA3 TRISA2 TRISA1 TRISA0')
    bit (tag=scl names='TRISA' width='8')
    stimulus (scl=rwb regfiles=w)

                               # ----------------#
#------------------------------# PORTB Registers #-----------------------------------------------------------------------------------------#
                               # ----------------#

sfr (key=PORTB addr=0xF81 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0')
    bit (tag=scl names='RB' width='8')
    stimulus (scl=rwb regfiles=rw pcfiles=rw)
sfr (key=LATB addr=0xF8A size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='LATB7 LATB6 LATB5 LATB4 LATB3 LATB2 LATB1 LATB0')
    bit (tag=scl names='LATB' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=TRISB addr=0xF93 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='11111111' mclr='11111111')
    bit (names='TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0')
    bit (tag=scl names='TRISB' width='8')
    stimulus (scl=rwb regfiles=w)
    

                               # --------------#
#------------------------------# ADC Registers #----------------------------------------------------------------------------#
                               # --------------#

sfr (key=ADRES addr=0xFC3 size=2 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='ADRES' width='16')
sfr (key=ADRESH addr=0xFC4 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='ADRESH' width='8')
    stimulus (scl=rwb type=int regfiles=w)
sfr (key=ADRESL addr=0xFC3 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='ADRESL' width='8')
    stimulus (scl=rwb type=int regfiles=r)

sfr (key=ADCON0 addr=0xFC2 size=1 access='u u u u rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='- CHS GO/nDONE ADON' width='4 2 1 1')
    bit (tag=scl names='- CHS GO_nDONE ADON' width='4 2 1 1')
    stimulus (scl=rwb regfiles=w)
sfr (key=ADCON1 addr=0xFC1 size=1 access='u u u rw rw rw rw rw')
    reset (por='00001111' mclr='00001111')
    bit (names='- VCFG PCFG' width='3 1 4')
    stimulus (scl=rwb regfiles=w)
sfr (key=ADCON2 addr=0xFC0 size=1 access='rw u rw rw rw rw rw rw')
    reset (por='0-000000' mclr='0-000000')
    bit (names='ADFM - ACQT ADCS' width='1 1 3 3')
    stimulus (scl=rwb regfiles=w)

                               # --------------#
#------------------------------# CCP Registers #----------------------------------------------------------------------------#
                               # --------------#
#commented by Akram
#sfr (key=CCPR1 addr=0xFBE size=2 flags=j)
# NOTE: The j flag means all these registers together form one larger register
#   bit (names='CCPR1' width='16')
#sfr (key=CCP1CON addr=0xFBD size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='00000000' mclr='00000000')
#    bit (names='P1M DC1B CCP1M' width='2 2 4')
#    stimulus (scl=rwb regfiles=w)
#sfr (key=ECCPAS addr=0xFB6 size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='00000000' mclr='00000000')
#    bit (names='ECCPASE ECCPAS PSSAC PSSBD' width='1 3 2 2')
#    stimulus (scl=rwb regfiles=w)
#sfr (key=PWM1CON addr=0xFB7 size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='00000000' mclr='00000000')
#    bit (names='PRSEN PDC' width='1 7')
#    stimulus (scl=rwb regfiles=w)




                               # -----------------#
#------------------------------# TIMER0 Registers #-------------------------------------------------#
                               # -----------------#

sfr (key=TMR0 addr=0xFD6 size=2 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='TMR0' width='16')
sfr (key=TMR0H addr=0xFD7 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='TMR0H' width='8')
    stimulus (scl=rwb type=int regfiles=w pcfiles=w)
sfr (key=TMR0L addr=0xFD6 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='TMR0L' width='8')
    stimulus (scl=rwb type=int regfiles=w pcfiles=w)

sfr (key=T0CON addr=0xFD5 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='11111111' mclr='11111111')
    bit (names='TMR0ON T08BIT T0CS T0SE PSA T0PS' width='1 1 1 1 1 3')
    stimulus (scl=rwb regfiles=w)

                               # -----------------#
#------------------------------# TIMER1 Registers #-------------------------------------------------#
                               # -----------------#

sfr (key=TMR1 addr=0xFCE size=2 flags=j)
    # NOTE: The j flag means all these registers together form one larger register
    bit (names='TMR1' width='16')
sfr (key=TMR1H addr=0xFCF size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='TMR1H' width='8')
    stimulus (scl=rwb type=int regfiles=w pcfiles=w)
sfr (key=TMR1L addr=0xFCE size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='xxxxxxxx' mclr='uuuuuuuu')
    bit (names='TMR1L' width='8')
    stimulus (scl=rwb type=int regfiles=w pcfiles=w)

sfr (key=T1CON addr=0xFCD size=1 access='rw r rw rw rw rw rw rw')
    reset (por='00000000' mclr='u0uuuuuu')
    bit (names='RD16 T1RUN T1CKPS T1OSCEN nT1SYNC TMR1CS TMR1ON' width='1 1 2 1 1 1 1')
    stimulus (scl=rwb regfiles=w)

                               # -----------------#
#------------------------------# TIMER2 Registers #-------------------------------------------------#
                               # -----------------#
#commented by Leo
#sfr (key=TMR2 addr=0xFCC size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='00000000' mclr='00000000')
#    bit (names='TMR2' width='8')
#    stimulus (scl=rwb type=int regfiles=w pcfiles=w)
#sfr (key=PR2 addr=0xFCB size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='11111111' mclr='11111111')
#    bit (names='PR2' width='8')
#    stimulus (scl=rwb type=int regfiles=w)
#sfr (key=T2CON addr=0xFCA size=1 access='u rw rw rw rw rw rw rw')
#    reset (por='-0000000' mclr='-0000000')
#    bit (names='- TOUTPS TMR2ON T2CKPS' width='1 4 1 2')
#    stimulus (scl=rwb regfiles=w)

                               # -----------------#
#------------------------------# TIMER3 Registers #-------------------------------------------------#
                               # -----------------#

#commented by Leo
#sfr (key=TMR3 addr=0xFB2 size=2 flags=j)
#    # NOTE: The j flag means all these registers together form one larger register
#    bit (names='TMR3' width='16')
#sfr (key=TMR3H addr=0xFB3 size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='xxxxxxxx' mclr='uuuuuuuu')
#    bit (names='TMR3H' width='8')
#    stimulus (scl=rwb type=int regfiles=w pcfiles=w)
#sfr (key=TMR3L addr=0xFB2 size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='xxxxxxxx' mclr='uuuuuuuu')
#    bit (names='TMR3L' width='8')
#    stimulus (scl=rwb type=int regfiles=w pcfiles=w)
#
#sfr (key=T3CON addr=0xFB1 size=1 access='rw rw rw rw rw rw rw rw')
#    reset (por='00000000' mclr='uuuuuuuu')
#    bit (names='RD16 T3CCP2 T3CKPS T3CCP1 nT3SYNC TMR3CS TMR3ON' width='1 1 2 1 1 1 1')
#    stimulus (scl=rwb regfiles=w)

                               # -----------------#
#------------------------------# EEPROM Registers #----------------------------------------------------------------------------#
                               # -----------------#

sfr (key=EEADR addr=0xFA9 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='EEADR' width='8')
    stimulus (scl=rwb regfiles=w pcfiles=rw)
sfr (key=EEDATA addr=0xFA8 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='EEDATA' width='8')
    stimulus (scl=rwb regfiles=rw pcfiles=rw)
sfr (key=EECON2 addr=0xFA7 size=1 flags=w access='w w w w w w w w')
    reset (por='--------' mclr='--------')
    bit (names='EECON2' width='8')
sfr (key=EECON1 addr=0xFA6 size=1 access='rw rw u rw rw rw rs rs')
    reset (por='xx-0x000' mclr='uu-0u000')
    bit (names='EEPGD CFGS - FREE WRERR WREN WR RD')
    stimulus (scl=rwb regfiles=w pcfiles=rw)

                               # ------------------------#
#------------------------------# Enhanced UART Registers #-------------------------------------------------#
                               # ------------------------#

sfr (key=SPBRGH addr=0xFB0 size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='SPBRGH' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=SPBRG addr=0xFAF size=1 access='rw rw rw rw rw rw rw rw')
    reset (por='00000000' mclr='00000000')
    bit (names='SPBRG' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=RCREG addr=0xFAE size=1 access='r r r r r r r r')
    reset (por='00000000' mclr='00000000')
    bit (names='RCREG' width='8')
    stimulus (scl=rb regfiles=rp)
sfr (key=TXREG addr=0xFAD size=1 access='w w w w w w w w')
    reset (por='00000000' mclr='00000000')
    bit (names='TXREG' width='8')
    stimulus (scl=rwb regfiles=w)
sfr (key=TXSTA addr=0xFAC size=1 access='rw rw rw rw rw rw r rw')
    reset (por='00000010' mclr='00000010')
    bit (names='CSRC TX9 TXEN SYNC SENDB BRGH TRMT TX9D')
    stimulus (scl=rwb regfiles=w)
sfr (key=RCSTA addr=0xFAB size=1 access='rw rw rw rw rw r r r')
    reset (por='0000000x' mclr='0000000x')
    bit (names='SPEN RX9 SREN CREN ADEN FERR OERR RX9D')
    stimulus (scl=rwb regfiles=w)

                               # -------------------#
#------------------------------# Configuration Bits #------------------------------------#
                               # -------------------#

cfgbits (key=CONFIG1H addr=0x300001 unused=0x0)
    field (key=OSC mask=0xF desc="Oscillator")
        setting (req=0xC value=0xC desc="EXT RC-CLKOUT on RA6" freqmin=32000 freqmax=4000000)
        setting (req=0xE value=0xA desc="EXT RC-CLKOUT on RA6" freqmin=32000 freqmax=4000000)
        setting (req=0xF value=0x9 desc="INT RC-CLKOUT on RA6,Port on RA7")
        setting (req=0xF value=0x8 desc="INT RC-Port on RA6,Port on RA7")
        setting (req=0xF value=0x7 desc="EXT RC-Port on RA6" freqmin=32000 freqmax=4000000)
        setting (req=0xF value=0x6 desc="HS-PLL enabled freq=4xFosc1" freqmin=16000000 freqmax=40000000)
        setting (req=0xF value=0x5 desc="EC-Port on RA6" freqmin=32000 freqmax=40000000)
        setting (req=0xF value=0x4 desc="EC-CLKOUT on RA6" freqmin=32000 freqmax=40000000)
        setting (req=0xF value=0x2 desc="HS" freqmin=4000000 freqmax=20000000)
        setting (req=0xF value=0x1 desc="XT" freqmin=1000000 freqmax=4000000)
        setting (req=0xF value=0x0 desc="LP" freqmin=32000 freqmax=200000)
    field (key=FCMEN mask=0x40 desc="Fail-Safe Clock Monitor Enable")
        setting (req=0x40 value=0x0 desc="Disabled")
        setting (req=0x40 value=0x40 desc="Enabled")
    field (key=IESO mask=0x80 desc="Internal External Switch Over Mode")
        setting (req=0x80 value=0x0 desc="Disabled")
        setting (req=0x80 value=0x80 desc="Enabled")
             
cfgbits (key=CONFIG2L addr=0x300002 unused=0x0)
    field (key=PUT mask=0x1 desc="Power Up Timer")
        setting (req=0x1 value=0x1 desc="Disabled")
        setting (req=0x1 value=0x0 desc="Enabled")
    field (key=BODEN mask=0x6 desc="Brown Out Detect")
        setting (req=0x6 value=0x6 desc="BOR Enabled - SBOREN Disabled")
        setting (req=0x6 value=0x4 desc="BOR when device active - SBOREN Disabled")
        setting (req=0x6 value=0x2 desc="BOR controlled with SBOREN")
        setting (req=0x6 value=0x0 desc="BOR Disabled - SBOREN Disabled")
    field (key=BODENV mask=0x18 desc="Brown Out Voltage")
        setting (req=0x18 value=0x18 desc="2.0V")
        setting (req=0x18 value=0x10 desc="2.7V")
        setting (req=0x18 value=0x08 desc="4.2V")
        setting (req=0x18 value=0x00 desc="4.5V")

cfgbits (key=CONFIG2H addr=0x300003 unused=0x0)
    field (key=WDT mask=0x1 desc="Watchdog Timer")
        setting (req=0x1 value=0x1 desc="Enabled")
        setting (req=0x1 value=0x0 desc="Disabled-Controlled by SWDTEN bit")
    field (key=WDTPS mask=0x1E desc="Watchdog Postscaler")
        setting (req=0x1E value=0x1E desc="1:32768")
        setting (req=0x1E value=0x1C desc="1:16384")
        setting (req=0x1E value=0x1A desc="1:8192")
        setting (req=0x1E value=0x18 desc="1:4096")
        setting (req=0x1E value=0x16 desc="1:2048")
        setting (req=0x1E value=0x14 desc="1:1024")
        setting (req=0x1E value=0x12 desc="1:512")
        setting (req=0x1E value=0x10 desc="1:256")
        setting (req=0x1E value=0x0E desc="1:128")
        setting (req=0x1E value=0x0C desc="1:64")
        setting (req=0x1E value=0x0A desc="1:32")
        setting (req=0x1E value=0x08 desc="1:16")
        setting (req=0x1E value=0x06 desc="1:8")
        setting (req=0x1E value=0x04 desc="1:4")
        setting (req=0x1E value=0x02 desc="1:2")
        setting (req=0x1E value=0x00 desc="1:1")

#Added by Akram
cfgbits (key=CONFIG3L addr=0x300004 unused=0x0)
    field (key=PWMPIN mask=0x2 desc="PWM Output Pin Reset")
        setting (req=0x2 value=0x2 desc="PWM outputs disabled upon RESET")
        setting (req=0x2 value=0x0 desc="PWM outputs drive active states upon RESET")
    field (key=LPOL mask=0x4 desc="Low-Side Transistors Polarity")
        setting (req=0x4 value=0x4 desc="PWM 0, 2, 4 and 6 are active high")
        setting (req=0x4 value=0x0 desc="PWM 0, 2, 4 and 6 are active low")
    field (key=HPOL mask=0x8 desc="High-Side Transistors Polarity")
        setting (req=0x8 value=0x8 desc="PWM 1, 3, 5, and 7 are active high")
        setting (req=0x8 value=0x0 desc="PWM 1, 3, 5, and 7 are active low")
#Added by Akram  

cfgbits (key=CONFIG3H addr=0x300005 unused=0x0)
    field (key=MCLRE mask=0x80 desc="Master Clear Enable")
        setting (req=0x80 value=0x80 desc="MCLR enabled, RA5 input disabled")
        setting (req=0x80 value=0x00 desc="MCLR disabled, RA5 input enabled")
    field (key=T1OSCMX mask=0x08 desc="T1OSC Mux bit")    
        setting (req=0x08 value=0x08 desc="T1OSC reside on RA6 and RA7")
        setting (req=0x08 value=0x00 desc="T1OSC reside on RB2 and RB3")
    field (key=FLTAMX mask=0x01 desc="FLTA Mux bit")            
        setting (req=0x01 value=0x01 desc="FLTA is muxed onto RA5")
        setting (req=0x01 value=0x00 desc="FLTA is muxed onto RA7")
        
cfgbits (key=CONFIG4L addr=0x300006 unused=0x0)
    field (key=STVREN mask=0x1 desc="Stack Overflow Reset")
        setting (req=0x1 value=0x1 desc="Enabled")
        setting (req=0x1 value=0x0 desc="Disabled")
    field (key=ENICPORT mask=0x08 desc="ICD/ICSP Port Enable bit")
        setting (req=0x08 value=0x08 desc="Enabled")
        setting (req=0x08 value=0x00 desc="Disabled")
    field (key=BBSIZ mask=0x30 desc="Boot Block Select bits")
	setting (req=0x30 value=0x30 desc="Boot Block size is 1 KW if EN8K = 1/ 512 W if EN8K = 0")
	setting (req=0x30 value=0x20 desc="Boot Block size is 1 KW if EN8K = 1/ 512 W if EN8K = 0")
	setting (req=0x30 value=0x10 desc="Boot Block size is 512 W")
	setting (req=0x30 value=0x00 desc="Boot Block size is 256 W")
   field (key=ENHCPU mask=0x40 desc="Enhanced CPU Enable bit")
        setting (req=0x40 value=0x40 desc="Enabled")
        setting (req=0x40 value=0x0 desc="Disabled")
    field (key=BACKBUG mask=0x80 desc="Background Debug" flags=h)
        setting (req=0x80 value=0x80 desc="Disabled")
        setting (req=0x80 value=0x0 desc="Enabled")
        
cfgbits (key=CONFIG5L addr=0x300008 unused=0x0)
    field (key=CP_0 mask=0x1 desc="Code Protect 000200-000FFF")
        setting (req=0x1 value=0x1 desc="Disabled")
            checksum (type=0x0 protregion=0x00-0x00)
        setting (req=0x1 value=0x00 desc="Enabled")
            checksum (type=0x27 protregion=0x200-0xFFF)
    field (key=CP_1 mask=0x2 desc="Code Protect 001000-001FFF")
        setting (req=0x2 value=0x2 desc="Disabled")
            checksum (type=0x0 protregion=0x00-0x00)
        setting (req=0x2 value=0x00 desc="Enabled")
            checksum (type=0x27 protregion=0x1000-0x1FFF)

cfgbits (key=CONFIG5H addr=0x300009 unused=0x0)
    field (key=CPD mask=0x80 desc="Data EEPROM Code Protect")
        setting (req=0x80 value=0x80 desc="Disabled")
        setting (req=0x80 value=0x0 desc="Enabled")
    field (key=CPB mask=0x40 desc="Code Protect Boot")
        setting (req=0x40 value=0x40 desc="Disabled")
            checksum (type=0x0 protregion=0x00-0x00)
        setting (req=0x40 value=0x0 desc="Enabled")
            checksum (type=0x27 protregion=0x0-0x1FF)

cfgbits (key=CONFIG6L addr=0x30000A unused=0x0)
    field (key=WRT_0 mask=0x1 desc="Table Write Protect 00200-00FFF")
        setting (req=0x1 value=0x1 desc="Disabled")
        setting (req=0x1 value=0x00 desc="Enabled")
    field (key=WRT_1 mask=0x2 desc="Table Write Protect 01000-01FFF")
        setting (req=0x2 value=0x2 desc="Disabled")
        setting (req=0x2 value=0x00 desc="Enabled")

cfgbits (key=CONFIG6H addr=0x30000B unused=0x0)
    field (key=WRTD mask=0x80 desc="Data EEPROM Write Protect")
        setting (req=0x80 value=0x80 desc="Disabled")
        setting (req=0x80 value=0x0 desc="Enabled")
    field (key=WRTB mask=0x40 desc="Table Write Protect Boot")
        setting (req=0x40 value=0x40 desc="Disabled")
        setting (req=0x40 value=0x0 desc="Enabled")
    field (key=WRTC mask=0x20 desc="Config. Write Protect")
        setting (req=0x20 value=0x20 desc="Disabled")
        setting (req=0x20 value=0x0 desc="Enabled")

cfgbits (key=CONFIG7L addr=0x30000C unused=0x0)
    field (key=EBTR_0 mask=0x1 desc="Table Read Protect 00200-00FFF")
        setting (req=0x1 value=0x1 desc="Disabled")
        setting (req=0x1 value=0x00 desc="Enabled")
    field (key=EBTR_1 mask=0x2 desc="Table Read Protect 01000-01FFF")
        setting (req=0x2 value=0x2 desc="Disabled")
        setting (req=0x2 value=0x00 desc="Enabled")

cfgbits (key=CONFIG7H addr=0x30000D unused=0x0)
    field (key=EBTRB mask=0x40 desc="Table Read Protect Boot")
        setting (req=0x40 value=0x40 desc="Disabled")
        setting (req=0x40 value=0x0 desc="Enabled")

                               # ------------#
#------------------------------# Peripherals #------------------------------------#
                               # ------------#


#--------------------------------------------------------------------------------
# 				PWM
#--------------------------------------------------------------------------------

peripheral18 (key=PWM sfrs='PTCON0 PTCON1 PTMRL PTMRH PTPERL PTPERH PDC0L PDC0H PDC1L PDC1H PDC2L PDC2H FLTCONFIG SEVTCMPL SEVTCMPL SEVTCMPH PWMCON0 PWMCON1 DTCON OVDCOND OVDCONS')
    pinfunc (key=PWM0 port=RB0 dir=out)
    pinfunc (key=PWM1 port=RB1 dir=out)
    pinfunc (key=PWM2 port=RB4 dir=out)
    pinfunc (key=PWM3 port=RB5 dir=out)
    pinfunc (key=PWM4 port=RB6 dir=out)
    pinfunc (key=PWM5 port=RB7 dir=out)
    pinfunc (key=PWMFLTA port=multi dir=in)
        portpins (muxaddr=0x300005 muxmask=0x01)
            setting (muxval=0x00 port=RA7 dir=in)
            setting (muxval=0x01 port=RA5 dir=in)
    specialevent (key=ADC)
    interrupt (name=PWMINT enreg=PIE3 enmask=0x10 flgreg=PIR3 flgmask=0x10 prireg=IPR3 primask=0x10)

#--------------------------------------------------------------------------------
# 				CMTRI
#--------------------------------------------------------------------------------

# CMTRI consists of 3 individual comparators, each has no output pin and since the INN is tied to CVref we do not need them.
peripheral18 (key=CMTRI sfrs='CMCON CVRCON')
    pinfunc (key=C0INP port=RA0 dir=in)
    pinfunc (key=C1INP port=RB3 dir=in)
    pinfunc (key=C2INP port=RB2 dir=in)
    interrupt (name=CM0INT enreg=PIE1 enmask=0x02 flgreg=PIR1 flgmask=0x02 prireg=IPR1 primask=0x02)
    interrupt (name=CM1INT enreg=PIE1 enmask=0x04 flgreg=PIR1 flgmask=0x04 prireg=IPR1 primask=0x04)
    interrupt (name=CM2INT enreg=PIE1 enmask=0x08 flgreg=PIR1 flgmask=0x08 prireg=IPR1 primask=0x08)

#--------------------------------------------------------------------------------
# 				TIMERs
#--------------------------------------------------------------------------------

peripheral18 (key=TMR0 sfrs='TMR0H TMR0L T0CON')
    pinfunc (key=T0CKI port=RA4 dir=in)
    interrupt (name=TMR0INT enreg=INTCON enmask=0x20 flgreg=INTCON flgmask=0x04 prireg=INTCON2 primask=0x04)

peripheral18 (key=TMR1 sfrs='TMR1H TMR1L T1CON')
    pinfunc (key=T1CKI port=multi dir=in)
		portpins (muxaddr=0x300005 muxmask=0x08)
			setting (muxval=0x08 port=RA6 dir=in)
			setting (muxval=0x00 port=RB2 dir=in)
    interrupt (name=TMR1INT enreg=PIE1 enmask=0x01 flgreg=PIR1 flgmask=0x01 prireg=IPR1 primask=0x01)

#commented by Leo
#peripheral18 (key=TMR2 sfrs='TMR2 PR2 T2CON')
#    interrupt (name=TMR2INT enreg=PIE1 enmask=0x02 flgreg=PIR1 flgmask=0x02 prireg=IPR1 primask=0x02)

#commented by Leo
#peripheral18 (key=TMR3 sfrs='TMR3H TMR3L T3CON')
#    pinfunc (key=T3CKI port=RB6 dir=in)
#    interrupt (name=TMR3INT enreg=PIE2 enmask=0x02 flgreg=PIR2 flgmask=0x02 prireg=IPR2 primask=0x02)

#--------------------------------------------------------------------------------
# 				ADC
#--------------------------------------------------------------------------------

peripheral18 (key=ADC sfrs='ADCON0 ADCON1 ADCON2 ADRESL ADRESH')
    pinfunc (key=AN0 port=RA0 dir=in)
    pinfunc (key=AN1 port=RA1 dir=in)
    pinfunc (key=AN2 port=RA4 dir=in)
    pinfunc (key=AN3 port=RA6 dir=in)
    access (key=ADCON1 mode=AD_PCFG_BIT_PIN)
    access (key=ADCON2 mode=AD_ACQUISITION)
    interrupt (name=ADC enreg=PIE1 enmask=0x40 flgreg=PIR1 flgmask=0x40 prireg=IPR1 primask=0x40)

#--------------------------------------------------------------------------------
# 				UARTs
#--------------------------------------------------------------------------------

peripheral18 (key=UART1 sfrs='SPBRGH SPBRG RCREG TXREG TXSTA RCSTA BAUDCTL')
    pinfunc (key=U1RX port=RA3 dir=in)
    pinfunc (key=U1TX port=RA2 dir=out)
    interrupt (name=RXINT1 enreg=PIE1 enmask=0x20 flgreg=PIR1 flgmask=0x20 prireg=IPR1 primask=0x20)
    interrupt (name=TXINT1 enreg=PIE1 enmask=0x10 flgreg=PIR1 flgmask=0x10 prireg=IPR1 primask=0x10)

#--------------------------------------------------------------------------------
# 				PORTA
#--------------------------------------------------------------------------------

peripheral18 (key=PORTA sfrs='TRISA LATA PORTA' type=port)
    iopin (key=RA0 dir=inout)
        extint (key=INT0 enreg=INTCON enmask=0x10 flgreg=INTCON flgmask=0x02 prireg=NONE primask=0x00)
        cnint (key=KBIRQ enreg=INTCON enmask=0x08 flgreg=INTCON flgmask=0x01 prireg=INTCON2 primask=0x01 cnkey=KBI0)
        cnpin (key=C0INP notify=CMTRI)
    iopin (key=RA1 dir=inout)
        extint (key=INT1 enreg=INTCON3 enmask=0x08 flgreg=INTCON3 flgmask=0x01 prireg=INTCON3 primask=0x40)
        cnint (key=KBIRQ enreg=INTCON enmask=0x08 flgreg=INTCON flgmask=0x01 prireg=INTCON2 primask=0x01 cnkey=KBI1)
    iopin (key=RA2 dir=inout)
    iopin (key=RA3 dir=inout)
    iopin (key=RA4 dir=inout)
    iopin (key=RA5 dir=in)
        cnpin (key=PWMFLTA notify=PWM)
    iopin (key=RA6 dir=inout)
    iopin (key=RA7 dir=inout)
        cnpin (key=PWMFLTA notify=PWM)

#--------------------------------------------------------------------------------
# 				PORTB
#--------------------------------------------------------------------------------

peripheral18 (key=PORTB sfrs='TRISB LATB PORTB' type=port)
    iopin (key=RB0 dir=inout)
    iopin (key=RB1 dir=inout)
    iopin (key=RB2 dir=inout)
        cnint (key=KBIRQ enreg=INTCON enmask=0x08 flgreg=INTCON flgmask=0x01 prireg=INTCON2 primask=0x01 cnkey=KBI2)
        extint (key=INT2 enreg=INTCON3 enmask=0x10 flgreg=INTCON3 flgmask=0x02 prireg=INTCON3 primask=0x80)
        cnpin (key=C2INP notify=CMTRI)
    iopin (key=RB3 dir=inout)
        cnint (key=KBIRQ enreg=INTCON enmask=0x08 flgreg=INTCON flgmask=0x01 prireg=INTCON2 primask=0x01 cnkey=KBI3)
        extint (key=INT3 enreg=INTCON3 enmask=0x20 flgreg=INTCON3 flgmask=0x04 prireg=INTCON2 primask=0x02)
        cnpin (key=C1INP notify=CMTRI)
    iopin (key=RB4 dir=inout)
    iopin (key=RB5 dir=inout)
    iopin (key=RB6 dir=inout)
    iopin (key=RB7 dir=inout)



#--------------------------------------------------------------------------------
# 				OSC
#--------------------------------------------------------------------------------

peripheral18 (key=PMOSC sfrs='OSCCON')
    pinfunc (key=OSC1 port=RA7 dir=out)
    pinfunc (key=OSC2 port=RA6 dir=out)
    pinfunc (key=T1OSCI port=multi dir=in)
		portpins (muxaddr=0x300005 muxmask=0x08)
			setting (muxval=0x08 port=RA7 dir=in)
			setting (muxval=0x00 port=RB3 dir=in)
	pinfunc (key=T1OSCO port=multi dir=out)	
		portpins (muxaddr=0x300005 muxmask=0x08)
			setting (muxval=0x08 port=RA6 dir=out)
			setting (muxval=0x00 port=RB2 dir=out)
#       nextp (nextperiph=TMR1 nextpin=T1CKI)



#--------------------------------------------------------------------------------
# 				MCLR
#--------------------------------------------------------------------------------

peripheral18 (key=MCLR)
    pinfunc (key=MCLR port=RA5 dir=in)
