;************************************************************************
;                                                                       *
;   Filename:      BA_L7-Sleep_LED_off.asm                              *
;   Date:          9/6/09                                               *
;   File Version:  1.2                                                  *
;                                                                       *
;   Author:        David Meiklejohn                                     *
;   Company:       Gooligum Electronics                                 *
;                                                                       *
;************************************************************************
;                                                                       *
;   Architecture:  Baseline PIC                                         *
;   Processor:     12F508/509                                           *
;                                                                       *
;************************************************************************
;                                                                       *
;   Files required: none                                                *
;                                                                       *
;************************************************************************
;                                                                       *
;   Description:    Lesson 7, example 1b                                *
;                                                                       *
;   Demonstrates use of sleep mode                                      *
;                                                                       *
;   Turn on LED, wait for button press, turn off LED, then sleep        *
;                                                                       *
;************************************************************************

    list        p=12F509 
    #include    <p12F509.inc>

    radix       dec


;***** CONFIGURATION
                ; int reset, no code protect, no watchdog, 4MHz int clock
    __CONFIG    _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC

; pin assignments
    #define     LED     GPIO,1      ; indicator LED on GP1
    constant    nLED=1              ;   (port bit 1)
    #define     BUTTON  GPIO,3      ; pushbutton on GP3


;************************************************************************
RESET   CODE    0x000           ; effective reset vector
        movwf   OSCCAL          ; update OSCCAL with factory cal value 


;***** MAIN PROGRAM

;***** Initialisation
start
        movlw   ~(1<<nLED)      ; configure LED pin (only) as an output
        tris    GPIO

        bsf     LED             ; turn on LED

waitlo  btfsc   BUTTON          ; wait for button press (low)
        goto    waitlo

        bcf     LED             ; turn off LED

        sleep                   ; enter sleep mode

        goto    $               ; (this instruction should never run)


        END

