;************************************************************************
;                                                                       *
;   Filename:       BA_L4-PB_LED-direct.asm                             *
;   Date:           15/9/07                                             *
;   File Version:   1.0                                                 *
;                                                                       *
;   Author:         David Meiklejohn                                    *
;   Company:        Gooligum Electronics                                *
;                                                                       *
;************************************************************************
;                                                                       *
;   Architecture:   Baseline PIC                                        *
;   Processor:      12F508/509                                          *
;                                                                       *
;************************************************************************
;                                                                       *
;   Files required: none                                                *
;                                                                       *
;************************************************************************
;                                                                       *
;   Description:    Lesson 4, example 1a                                *
;                                                                       *
;   Demonstrates reading a switch                                       *
;                                                                       *
;   Turns on LED when pushbutton on GP3 is pressed (active low)         *
;                                                                       *
;************************************************************************
;                                                                       *
;   Pin assignments:                                                    *
;       GP1 - LED                                                       *
;       GP3 - pushbutton switch                                         *
;                                                                       *
;************************************************************************

    list        p=12F509 
    #include    <p12F509.inc>

                ; int reset, no code protect, no watchdog, 4Mhz int clock
    __CONFIG    _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC


;************************************************************************
RESET   CODE    0x000           ; effective reset vector
        movwf   OSCCAL          ; update OSCCAL with factory cal value 


;***** MAIN PROGRAM

;***** Initialisation
start			
        movlw   b'111101'       ; configure GP1 (only) as an output
        tris    GPIO            ; (GP3 is an input)
        clrf    GPIO	        ; start with GPIO clear (GP1 low)

;***** Main loop
loop
        btfss   GPIO,3          ; if button pressed (GP3 low)
        bsf     GPIO,1          ;   turn on LED
        btfsc   GPIO,3          ; if button up (GP3 high)
        bcf     GPIO,1          ;   turn off LED

        goto    loop            ; repeat forever


        END

