 title  "Simple 16F88 LED Blinker"
; by Brooke Clarke, N6GCE
; Working 5 June 2006
; http://www.PRC68.com
;
; ----- Hardware Notes -----
; /MCLR  pin 4 thru 10 k resistor to +5 Volts
; Vss pin 5 to ground
; Vdd pin 14 to +5
; LEDs can be connected to one or more of the 15 the unused pins. 
; Each LED should be connected to ground using a
; resistor (say 220 to 470 Ohms).  LED flat towards ground.
;
; A large electrolytic cap 10 to 50 uF at >= 16 V across +5 to gnd.
; A 0.1 or 0.01 uF ceramic across +5 to gnd.
; A 1N400x diode across +5 to gnd with the cathode (band) to +5.
; This diode does nothing normally, but if you hook up the power
; supply backwards the diode will protect the PIC.
;
; Optional, but handy a resistor (say 220 to 470 Ohms) between
; +5 and LED.  LED flat to gnd.  This is the Power ON indicator.
;
; Aproxiamte ouptuts
; A0 pin 17 = 5363 Hz = 190 us
; A1 pin 18 = 2632 Hz = 380 us
; A2 pin  1 = 1316 Hz = 760 us
; A3 pin  2 =  658 Hz = 1.52 ms
; A4 pin  3 =  333 Hz	= 3 ms
; A5 pin  4 = /MCLR no output
; A6 pin 15 =  83 Hz = 12 ms
; A7 pin 16    41 Hz = 24 ms
;
; B0 pin  6 =   20 Hz = 48 ms
; B1 pin  7 =   10 Hz = 100 ms
; B2 pin  8 =    5 Hz = 200 ms
; B3 pin  9 =    2.5 Hz = 400 ms
; B4 pin 10 =    1.2 Hz = 800 ms
; B5 pin 11 =    0.6 Hz = 1.6 sec
; B6 pin 12 =    0.3 Hz = 3.2 sec
; B7 pin 13 =    0.1 Hz = 6.4 sec

	LIST P=16F88, R=DEC, n=61, c=78	
;Wordpad margins T.5, L.75, R.5, B.5
  errorlevel 0,-305
  #INCLUDE "p16F88.inc"
  
 ; -------------Note _CONFIG1 is at 2007 and can only be set at burn time--------------
 ; for use with ICD2 MCLR needs a 10k pull up resistor and MCLR_ON in the config word.
 ; Once everything has been tested (except any RA5 functions) the internal MCLR_OFF configuration
 ; can be used.  Note that RA5 pin can only be used for an input so the 10k resistor can be left
 ; there and a switch added. maybe using the RC filter debounce ckt.
	__CONFIG	_CONFIG1, _CPD_OFF & _CP_OFF & _DEBUG_OFF & _LVP_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _WRT_PROTECT_OFF & _INTRC_IO & _BODEN_OFF
; 
; --------The Internal RC Frequency can be set at any time after ORG -----------------------
;
;  Register Usage
 CBLOCK 0x20	;  Start Registers at End of the Values
d1			    ;  Delay counters
Ashadow
Bshadow
 ENDC

;================= Start of Code =================
  org    0
	goto Start
	org 4
Start	
;  Enable all of A & B for Output
	clrf	STATUS
	clrf	PORTA
	clrf	PORTB
	movlw  0x000
	banksel TRISA	
	movwf  TRISA
	banksel TRISB
	movwf  TRISB
	banksel ANSEL
	clrf ANSEL
	banksel OSCCON 
	
	; Now set 4 MHz clock
	bsf	OSCCON, IRCF2
	bsf	OSCCON, IRCF1
	bcf	OSCCON, IRCF0
	bcf	OSCCON,SCS0
	bcf	OSCCON,SCS1

	nop	; allow some time for oscillator to settle
	nop
	banksel OSCTUNE
	bsf	OSCTUNE,TUN5
	bcf	OSCTUNE,TUN4
	bsf	OSCTUNE,TUN3
	bsf	OSCTUNE,TUN2
	banksel PORTA


	CLRF PORTA
	CLRF PORTB
;--------------------------------------	
Loop
	call	Delay80us
	incfsz	Ashadow
	goto	UpdateA
	goto UpdateAB

UpdateA
	movf Ashadow,W
	movwf	PORTA
	goto Loop
	
UpdateAB
	movf Ashadow,W
	movwf	PORTA
	INCF Bshadow
	movf Bshadow,W
	movwf PORTB
	goto Loop		
;-----------------------------------
; On line PIC delay code generator
; http://www.piclist.com/techref/piclist/codegen/delay.htm
; variable d1 moved up int top cblock 

Delay80us
			;76 cycles
	movlw	0x19
	movwf	d1
Delay80us_0
	decfsz	d1, f
	goto	Delay80us_0

			;4 cycles (including call)
	return
;-------------------------------------------

  end
