;******************************************************************************
;                                                                             *
;   This file is a basic code template for code generation on the             *
;   PIC18F14K50. This file contains the basic code building blocks to build   *
;   upon.                                                                     *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on features    *
;   of the assembler.                                                         *
;                                                                             *
;   Refer to the respective data sheet for additional information on the      *
;   instruction set.                                                          *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:         xxx.asm                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files required: P18F14K50.INC                                            *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Notes:                                                                   *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Revision History:                                                        *
;                                                                             *
;******************************************************************************

;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------

     LIST      P=PIC18F14K50          ; list directive to define processor
     #INCLUDE <P18F14K50.INC>         ; processor specific variable definitions
     ;#INCLUDE <P18Cxxx.INC>
     
    __idlocs    _IDLOC0, 0x0
    __idlocs    _IDLOC1, 0x0
    __idlocs    _IDLOC2, 0x0
    __idlocs    _IDLOC3, 0x0
    __idlocs    _IDLOC4, 0x0
    __idlocs    _IDLOC5, 0x0
    __idlocs    _IDLOC6, 0x0
    __idlocs    _IDLOC7, 0x1
     ;//#pragma config LVP = OFF  ;
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the 
; .asm file. The lables following the directive are located in the respective 
; .inc file.  See the data sheet for additional information on configuration 
; word settings.
;
;------------------------------------------------------------------------------

     CONFIG CPUDIV = NOCLKDIV, USBDIV = OFF, FOSC = HS, PLLEN = ON
     CONFIG PCLKEN = ON, FCMEN = OFF, IESO = OFF, PWRTEN = OFF, BOREN = OFF
     CONFIG BORV = 30, WDTEN = OFF, WDTPS = 1, MCLRE = OFF, HFOFST = OFF
     CONFIG STVREN = ON, LVP = OFF, BBSIZ = OFF, XINST = OFF, CP0 = OFF
     CONFIG CP1 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRTB = OFF
     CONFIG WRTC = OFF, WRTD = OFF, EBTR0 = OFF, EBTR1 = OFF, EBTRB = OFF
    ; CONFIG FOSC = HS
;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Refer to datasheet for available data memory (RAM) organization
;
;------------------------------------------------------------------------------

; Example of using GPR Uninitialized Data
GPR_VAR        UDATA           
MYVAR1         RES        1      ; User variable linker places
MYVAR2         RES        1      ; User variable linker places
MYVAR3         RES        1      ; User variable linker places

; Example of using Access Uninitialized Data Section
INT_VAR        UDATA_ACS       
W_TEMP         RES        1      ; w register for context saving (ACCESS)
STATUS_TEMP    RES        1      ; status used for context saving 
BSR_TEMP       RES        1      ; bank select used for ISR context saving

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 18F14K50 has non-volatile EEPROM starting at 0xF00000
; 
;------------------------------------------------------------------------------

DATAEE    CODE    0xF00000 ; Starting address for EEPROM for 18F4553

    DE    "MCHP"           ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RES_VECT  CODE    0x0000            ; processor reset vector
          GOTO    START             ; go to beginning of program

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRHV     CODE    0x0008

          ; Run the High Priority Interrupt Service Routine
          GOTO    HIGH_ISR             

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRLV     CODE    0x0018
          
          ; Run the High Priority Interrupt Service Routine
          GOTO    LOW_ISR             

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

ISRH      CODE                        ; let linker place high ISR routine

HIGH_ISR  

          ; Insert High Priority ISR Here

          RETFIE  FAST

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

ISRL      CODE                        ; let linker place low ISR routine

LOW_ISR
          ; Context Saving for Low ISR
          MOVWF   W_TEMP              ; save W register
          MOVFF   STATUS, STATUS_TEMP ; save status register
          MOVFF   BSR, BSR_TEMP       ; save bankselect register

          ; Insert Low Priority ISR Here

          ; Context Saving for Low ISR
          MOVFF   BSR_TEMP, BSR       ; restore bankselect register
          MOVF    W_TEMP, W           ; restore W register
          MOVFF   STATUS_TEMP, STATUS ; restore status register
          RETFIE

;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

MAIN_PROG CODE                        ; let linker place main program

START

          ; Insert User Program Here
	  ;MOVLW 0x0
	  ;MOVWF INTCON
	  MOVLW 0x0F		    
	  MOVWF ADCON1, 0
	  CLRF LATC
Wait:	  MOVLW 0x00		    
	  MOVWF TRISC, 0		    
	 ; MOVLW 0b00000000		    
	  ;MOVWF LATC, 0
	  MOVLW 0x03
	  MOVWF PORTC, 0
	 ; MOVLW 0x02
	  ;MOVWF PORTC, 0	  
	  ;CLRF 0xF8A
	  
	 ; MOVLW 0x01		    
	  ;MOVWF LATC		  
	  GOTO Wait		    
    
          END