/*******************************************************************************
 *	TestSwitch.c		Greenpower CarComputer Test Program
 *				T.Barnaby,	BEAM Ltd,	2008-02-28
 *
 *	Copyright (c) Beam Ltd and Chipping Sodbury School
 *******************************************************************************
 *
 * Function:	To light the RED LED in pressing SW1
 * 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) {
	// Set up Oscillator
	OSCCON = 0x62;				// Internal 4MHZ

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

	while(1){
		if(PORTCbits.RC0)
			PORTBbits.RB7 = 1;
		else
			PORTBbits.RB7 = 0;
	}
}
