
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;											;
;	led flash version 1.0					;
;	by brad slattery 2008					;
;											;
;	A led flasher for the 8x8 game board	;
;											;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



	LIST p=16f648a 				;	tell the compiler what chip we are using
	include "P16f648a.inc"		;	include the defaults for the chip
	__config h'3f18'			;	sets the configuration settings (oscillator type etc.)

PC equ h'02'					;	The program counter will be refered to as PC

	cblock h'20'				;	start of general purpose registers - this is where we start defining variable names
		counta					;	used in the delay routine
		countb 					;	used in the delay routine
	endc

	org h'0000'					;	org sets the start address for our code 0000 hex


	movlw h'07'					;	turn comparators off	
	movwf CMCON 				;	(we want all I/O pins to be digital only)

	bsf STATUS, RP0 			;	select bank 1 (so we can edit our status bits)
	movlw b'00000000' 			;	set PORTB all outputs
	movwf TRISB					;
	movlw b'00100000' 			;	set PORTA all outputs except for bit 5
	movwf TRISA 				;	remember bit 5 cannot be made an output!
	bcf STATUS, RP0 			;	select bank 0 (now ready to write our program...)



setup						;	Okay, lets get everything setup.
	movlw b'11011010'		;	This basically disables all 74373 outputs, and closes
	movwf PORTA				;	all 74373 latches.


begin						;	Our main program!
	movlw b'10000000'		;	we are only concerned with one led, (the top right one)
	movwf PORTB				;	so we only send a logic 1 out to one pin on the port (and as such - one led)
	bsf PORTA, 0			;	now that the data is on PORTB, latch it to the red 74373 (remember msb is up the top)
	bcf PORTA, 0			;	now close the latches (the data will now be held at the output of the 74373)
	bsf PORTA, 4			;	now send that same 8 bits to the COLUMN data 74373 (remember msb is to the right)
	bcf PORTA, 4			;	now close the latches (the data will now be held at the output of the 74373)
	bcf PORTA, 1			;	now that they both have their required data, we need to enable the outputs
	bcf PORTA, 6			;	PORTA, 1 is the red data output enable, PORTA, 6 is the COLUMN data output enable
	call delay				;	call the delay - this will hold the led on for a split second
	bsf PORTA, 1			;	now disable the red data output and the COLUMN data output,
	bsf PORTA, 6			;	(this will then turn the led off because no data is getting to the display)
	call delay				;	call the delay - this will hold the led off for a split second
	goto begin				;	do it all again!



delay						
		movlw h'ff'					;	You can make the delay longer by
		movwf counta				;	increasing the decimal value. Or you
		movwf countb				;	can make the delay shorter by decreasing
again	decfsz counta, 1			;	the decimal value.
	goto again						;
		decfsz countb, 1			;
	goto again						;	once counta and countb have reached zero
	return							;	it will return to the main program



	end								;	That's it!
