;**********************************************************************
;                                                                     *
;    Filename:         MagiDavid A101 - Lab 001.asm                   *
;    Date:             10/2/2011                                      *
;    File Version:     1.0                                            *
;                                                                     *
;    Author:           David Hoffman                                  *
;    Company:          NeoLoch, LLC                                   *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required: P16F882.INC                                      *
;                                                                     *
;**********************************************************************
;                                                                     *
;    License: Creative Commons                                        *
;    Attribution-NonCommercial-ShareAlike 3.0 Unported License.       *
;             http://creativecommons.org/licenses/by-nc-sa/3.0        *
;                                                                     *
;**********************************************************************

     LIST      p=16F882            ; list directive to define processor
     #INCLUDE <p16F882.inc>        ; processor specific variable definitions

     __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT 
     __CONFIG _CONFIG2, _WRT_OFF & _BOR40V

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
; Note that the _DEBUG_ON is changed by selecting a debugger or programmer.  
; There isn't much advantage to setting it in the code.  

; UDATA declares a section of uninitialized data
VARIABLES   UDATA           ; VARIABLES is the name of the section of memory
myvar1      RES     1       ; uninitialized data, placed by linker in GPR's. 
myvar2      RES     1

LED_VAR		UDATA_SHR
LED_LOOP	RES 1
LED_LOOP2	RES 1
LED_COUNT	RES 1
FX_TEMP		RES 1

GLOBAL	FX_TEMP

;#INCLUDE <EFT.h>
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F882 has 128 bytes of non-volatile EEPROM, starting at address 0x2100
; 
;------------------------------------------------------------------------------

          ORG   0x2100
          DE    0x00, 0x01, 0x02, 0x03

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RESET_VECTOR    CODE   0x0000
          goto    START             ; When using debug header, ICD2 may not stop
                                    ; on instruction 0 during reset.

;------------------------------------------------------------------------------
; CONFIGURATION CODE
;------------------------------------------------------------------------------
;START	ORG	0X05
MAIN_PROG       CODE
START
	BANKSEL PORTA
	CLRF	PORTA

	BANKSEL	ANSEL
	CLRF	ANSEL

	BANKSEL	TRISA
	MOVLW	0X00
	MOVWF	TRISA

	MOVLW	0X01
	MOVWF	LED_COUNT

	BANKSEL	STATUS
	BCF	STATUS,C

;------------------------------------------------------------------------------
; MAIN CODE
;------------------------------------------------------------------------------
MAIN
	BANKSEL	PORTA
	RRF	LED_COUNT,F
	MOVF	LED_COUNT,W
	MOVWF	PORTA
	CALL	LED_PAUSE
	GOTO	MAIN

LED_PAUSE
	MOVLW	0XFF
	MOVWF	LED_LOOP2

LED_PAUSE2
	CLRF	LED_LOOP
	DECFSZ	LED_LOOP,F
	GOTO	$-1
	DECFSZ	LED_LOOP2,F
	GOTO	LED_PAUSE2
	RETURN

#include <EFT.asm>
          END