/*******************************************************************************
 *	TestLed.c		Greenpower CarComputer Test Program
 *				T.Barnaby,	BEAM Ltd,	2008-02-28
 *******************************************************************************
 *
 * Function:	To flash the 4 LED's
 * Version:	1.0
 */
#include <pic18f2520.h>

#define	CLOCK		4000000		// Clock frequency

typedef unsigned char	uchar;
typedef unsigned short	ushort;
typedef unsigned long	ulong;

/*******************************************************************************
 *	Misc functions
 *******************************************************************************
 */

// Millisecond delay based on 4MHz Clock
void delayMs(unsigned int n){
	unsigned char	c;

	while(n--){
		for(c = 0; c < 250; c++){
			_asm nop _endasm;
		}
	}
}

void main(void) {
	uchar	v;
	
	// Set up Oscillator
	OSCCON = 0x62;				// Internal 4MHZ

	TRISB = 0x0F;           		// PORTB top 4 bits Output
	PORTB = 0;

	// Do this forever
	while(1){
		// Increments the top 4 bits from 0 - 15 to flash the LEDS in a count
		for(v = 0; v < 16; v++){
			PORTB = v << 4;
			delayMs(100);
		}
	}
}
