;   ***************************************************************
;   * Copyright (C) 2009, Embed Inc (http://www.embedinc.com)     *
;   *                                                             *
;   * Permission to copy this file is granted as long as this     *
;   * copyright notice is included in its entirety at the         *
;   * beginning of the file, whether the file is copied in whole  *
;   * or in part and regardless of whether other information is   *
;   * added to the copy.                                          *
;   *                                                             *
;   * The contents of this file may be used in any way,           *
;   * commercial or otherwise.  This file is provided "as is",    *
;   * and Embed Inc makes no claims of suitability for a          *
;   * particular purpose nor assumes any liability resulting from *
;   * its use.                                                    *
;   ***************************************************************
;
;   Manage the I/O ports at a low level.
;
/include "qq2.ins.dspic"

;*******************************************************************************
;
;   Configuration constants.
;

;
;   Derived constants.
;


;*******************************************************************************
;
;   Variables.
;
;*******************
;
;   Global state.
;

;
;*******************
;
;   Local state.
;


.text
;*******************************************************************************
;
;   Subroutine PORT_INIT
;
;   Initialize the hardware and software state managed by this module.
;
         glbsub  port_init, regf0
;
;   Disable the A/D inputs so that they become digital I/O lines if this
;   processor has an A/D.  If the A/D is used, it will be set up by a
;   module for that purpose later.
;
.ifdef   Adpcfg
         mov     #0xFFFF, w0 ;set all ANx pins to digital I/O
         mov     w0, Adpcfg
         .endif
;
;   Initialize port A if it exists.
;
.ifdef   Porta
         mov     #val_porta, w0
         mov     w0, Lata
         mov     #val_trisa, w0
         mov     w0, Trisa
         .endif
;
;   Initialize port B if it exists.
;
.ifdef   Portb
         mov     #val_portb, w0
         mov     w0, Latb
         mov     #val_trisb, w0
         mov     w0, Trisb
         .endif
;
;   Initialize port C if it exists.
;
.ifdef   Portc
         mov     #val_portc, w0
         mov     w0, Latc
         mov     #val_trisc, w0
         mov     w0, Trisc
         .endif
;
;   Initialize port D if it exists.
;
.ifdef   Portd
         mov     #val_portd, w0
         mov     w0, Latd
         mov     #val_trisd, w0
         mov     w0, Trisd
         .endif
;
;   Initialize port E if it exists.
;
.ifdef   Porte
         mov     #val_porte, w0
         mov     w0, Late
         mov     #val_trise, w0
         mov     w0, Trise
         .endif
;
;   Initialize port F if it exists.
;
.ifdef   Portf
         mov     #val_portf, w0
         mov     w0, Latf
         mov     #val_trisf, w0
         mov     w0, Trisf
         .endif
;
;   Initialize port G if it exists.
;
.ifdef   Portg
         mov     #val_portg, w0
         mov     w0, Latg
         mov     #val_trisg, w0
         mov     w0, Trisg
         .endif
;
;   Initialize port H if it exists.
;
.ifdef   Porth
         mov     #val_porth, w0
         mov     w0, Lath
         mov     #val_trish, w0
         mov     w0, Trish
         .endif
;
;   Initialize port I if it exists.
;
.ifdef   Porti
         mov     #val_porti, w0
         mov     w0, Lati
         mov     #val_trisi, w0
         mov     w0, Trisi
         .endif
;
;   Initialize port J if it exists.
;
.ifdef   Portj
         mov     #val_portj, w0
         mov     w0, Latj
         mov     #val_trisj, w0
         mov     w0, Trisj
         .endif
;
;   Initialize port K if it exists.
;
.ifdef   Portk
         mov     #val_portk, w0
         mov     w0, Latk
         mov     #val_trisk, w0
         mov     w0, Trisk
         .endif
;
;   Initialize port L if it exists.
;
.ifdef   Portl
         mov     #val_portl, w0
         mov     w0, Latl
         mov     #val_trisl, w0
         mov     w0, Trisl
         .endif
;
;   Initialize port M if it exists.
;
.ifdef   Portm
         mov     #val_portm, w0
         mov     w0, Latm
         mov     #val_trism, w0
         mov     w0, Trism
         .endif
;
;   Initialize port N if it exists.
;
.ifdef   Portn
         mov     #val_portn, w0
         mov     w0, Latn
         mov     #val_trisn, w0
         mov     w0, Trisn
         .endif
;
;   Initialize port O if it exists.
;
.ifdef   Porto
         mov     #val_porto, w0
         mov     w0, Lato
         mov     #val_triso, w0
         mov     w0, Triso
         .endif
;
;   Initialize port P if it exists.
;
.ifdef   Portp
         mov     #val_portp, w0
         mov     w0, Latp
         mov     #val_trisp, w0
         mov     w0, Trisp
         .endif
;
;   Initialize port Q if it exists.
;
.ifdef   Portq
         mov     #val_portq, w0
         mov     w0, Latq
         mov     #val_trisq, w0
         mov     w0, Trisq
         .endif
;
;   Initialize port R if it exists.
;
.ifdef   Portr
         mov     #val_portr, w0
         mov     w0, Latr
         mov     #val_trisr, w0
         mov     w0, Trisr
         .endif
;
;   Initialize port S if it exists.
;
.ifdef   Ports
         mov     #val_ports, w0
         mov     w0, Lats
         mov     #val_triss, w0
         mov     w0, Triss
         .endif
;
;   Initialize port T if it exists.
;
.ifdef   Portt
         mov     #val_portt, w0
         mov     w0, Latt
         mov     #val_trist, w0
         mov     w0, Trist
         .endif
;
;   Initialize port U if it exists.
;
.ifdef   Portu
         mov     #val_portu, w0
         mov     w0, Latu
         mov     #val_trisu, w0
         mov     w0, Trisu
         .endif
;
;   Initialize port V if it exists.
;
.ifdef   Portv
         mov     #val_portv, w0
         mov     w0, Latv
         mov     #val_trisv, w0
         mov     w0, Trisv
         .endif
;
;   Initialize port W if it exists.
;
.ifdef   Portw
         mov     #val_portw, w0
         mov     w0, Latw
         mov     #val_trisw, w0
         mov     w0, Trisw
         .endif
;
;   Initialize port X if it exists.
;
.ifdef   Portx
         mov     #val_portx, w0
         mov     w0, Latx
         mov     #val_trisx, w0
         mov     w0, Trisx
         .endif
;
;   Initialize port Y if it exists.
;
.ifdef   Porty
         mov     #val_porty, w0
         mov     w0, Laty
         mov     #val_trisy, w0
         mov     w0, Trisy
         .endif
;
;   Initialize port Z if it exists.
;
.ifdef   Portz
         mov     #val_portz, w0
         mov     w0, Latz
         mov     #val_trisz, w0
         mov     w0, Trisz
         .endif

         leaverest

.end