;**********************************************************************
;                                                                     *
;    Filename:         MagiDavid AL101 - Lab 002.asm                  *
;    Date:             10/15/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.  

#DEFINE		LED1_AN		PORTA,0
#DEFINE		LED1_CA		PORTA,1

LED_VAR		UDATA_SHR
LED_LOOP	RES 1
LED_LOOP2	RES 1
LED_COUNT	RES 1
FX_TEMP		RES 1

;------------------------------------------------------------------------------
; 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

;------------------------------------------------------------------------------
; MAIN CODE
;------------------------------------------------------------------------------
MAIN
	BANKSEL	PORTA
	CALL	LED1_RED
	CALL	LED_PAUSE

	CALL	LED1_GREEN
	CALL	LED_PAUSE

	CALL	LED1_OFF
	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

LED1_RED
	BSF	LED1_AN
	BCF	LED1_CA
	RETURN

LED1_GREEN
	BCF	LED1_AN
	BSF	LED1_CA
	RETURN

LED1_OFF
	BCF	LED1_AN
	BCF	LED1_CA
	RETURN

          END