                TITLE   "QwikLoader Test: three instruction goto at reset
                ; $Id: goto3.asm,v 1.2 2003/09/22 02:14:36 jerry Exp $
                ; $Source: /home/cvsroot/qwikloader/test/goto3.asm,v $
                LIST    P=16F877
                INCLUDE "P16F877.INC"

                ; Suppress warning errors from MPASM
                errorlevel -306
                errorlevel -302

;*************************************************************************
;  This program is part of the test suite for QwikLoader. It starts with
;  a three instruction goto sequence at the reset vector.
;
;  The body of this program flashes an LED connected to pin C0 at about
;  1Hz rate.
;*************************************************************************
;
;               Clock           20.00MHz
;
;*************************************************************************
;               CPU Configuration Fuses

 __CONFIG  _BODEN_ON&_CP_OFF&_WRT_ENABLE_ON&_PWRTE_ON&_WDT_ON&_HS_OSC&_DEBUG_OFF&_CPD_OFF&_LVP_OFF

;*************************************************************************
;  Working space
DLYCNT  equ     20h


;*************************************************************************
;               Reset Vector

        org     0000h           ;hardware reset vector

        movlw   07h             ;select bank 0 for calls and gotos
        movwf   PCLATH
        goto    BEGIN

;*************************************************************************
;               Interrupt Vector

        org     0003h           ;user code reset vector

        nop

;*************************************************************************
;       Flash LED
;
BEGIN   bcf     STATUS,RP1      ;page 0 or 1 (org x800h)
        bsf     STATUS,RP0      ;switch to memory page 1
        bcf     PORTC,0         ;(TRISC,0) Make the bit an output
        movlw   B'01010111'     ;TMR0 clk = OSC/256, port-B pull-ups ON
        movwf   OPTION_REG      ;load reg (TMR0 rolls 79.24 times/sec @ 20MHz)

        bcf     STATUS,RP0      ;switch back to page 0

        clrf    INTCON          ;ensure interrupts are turned off

LOOP    clrwdt                  ;kick the watchdog
        bsf     PORTC,0
        call    DELAY
        bcf     PORTC,0
        call    DELAY
        goto    LOOP


;*************************************************************************
;DELAY  Delay about 0.5 seconds
;
DELAY   movlw   D'38'           ;set the delay count (assumes 20MHz)
        movwf   DLYCNT          ;load counter

DLYLOOP clrwdt                  ;kick the watchdog
        btfss   INTCON,T0IF     ;has timer zero rolled?
         goto   DLYLOOP         ;no

        bcf     INTCON,T0IF     ;yes, clear timer roll over flag
        decfsz  DLYCNT,F        ;has time elapsed?
         goto   DLYLOOP         ;no

        return                  ;yes, bail

;*************************************************************************
        end                     ;compiler finish
