; *******************************************************************
; PICkit 2 Lesson 2 - "Blink"
;
; First lesson showed how to make an LED turn on,
; Now we'll look at how to make it blink.  Delay loops are necessary
; to slow down the on and off commands so they are visible to humans.
;
; *******************************************************************
; *    See 44-pin Demo Board User's Guide for Lesson Information    *
; *******************************************************************

#include <p16F88.inc>
	__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
	__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF


     cblock 0x20
Delay1               ; Define two file registers for the
Delay2               ; delay loop
     endc
     
     org 0
Start:
	 BANKSEL	OSCTUNE
	 movlw	B'00011111'
	 movwf	OSCTUNE
;	 BANKSEL	OSCCON
;	 bsf	OSCCON,IRCF0
;	 bsf	OSCCON,IRCF1
	 bsf	OSCCON,IRCF2	; 1 MHz

     BANKSEL	TRISA	      ; select Register Bank 1
     bcf	TRISA,6       ; make IO Pin RD0 an output
     BANKSEL	PORTA	      ; back to Register Bank 0
MainLoop:
     bsf       PORTA,6        ; turn on LED RD0
OndelayLoop:
     decfsz    Delay1,f       ; Waste time.  
     goto      OndelayLoop    ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
     decfsz    Delay2,f       ; The outer loop takes and additional 3 instructions per lap * 256 loops
     goto      OndelayLoop    ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
                              ; call it two-tenths of a second.
     
     bcf       PORTA,6        ; Turn off LED RD0
OffDelayLoop:
     decfsz    Delay1,f       ; same delay as above
     goto      OffDelayLoop
     decfsz    Delay2,f
     goto      OffDelayLoop
     goto      MainLoop       ; Do it again...

     end
     
