;**************************************************
; Pic by example
; LED.ASM
;
; (c) 2004, Sergio Tanzilli 
; http://www.tanzilli.com
;**************************************************

        PROCESSOR       16F84A
        RADIX           DEC
        INCLUDE         "P16F84A.INC"
        ERRORLEVEL      -302

        ;Setup of PIC configuration flags

        ;XT oscillator
        ;Disable watch dog timer
        ;Enable power up timer
        ;Disable code protect

        __CONFIG        0x3FF1

LED     EQU     0

        ORG     0x0C

Count   RES     2

        ;Reset Vector
        ;Start point at CPU reset

        ORG     0x00

        bsf     STATUS,RP0

        movlw   B'00011111'
        movwf   TRISA 

        movlw   B'11111110'
        movwf   TRISB 

        bcf     STATUS,RP0

        bsf     PORTB,LED

MainLoop

        call    Delay

        btfsc   PORTB,LED
        goto    SetToZero

        bsf     PORTB,LED
        goto    MainLoop

SetToZero

        bcf     PORTB,LED
        goto    MainLoop


        ;Subroutines

        ;Software delay

Delay
        clrf    Count
        clrf    Count+1

DelayLoop

        decfsz  Count,1
        goto    DelayLoop

        decfsz  Count+1,1
        goto    DelayLoop

        return

        END

