/*******************************************************************************
 *	TestClock.c		Greenpower CarComputer Test Program
 *				T.Barnaby,	BEAM Ltd,	2008-02-28
 *
 *	Copyright (c) Beam Ltd and Chipping Sodbury School
 *******************************************************************************
 *
 * Function:	Test sthe Display's 4 switches
 * Version:	1.0
 */
#include <string.h>
#include <pic18f2520.h>
#include <picLib3.c>

#define	CLOCK		4000000		// Clock frequency


void main(void) {
	char	str[16];
	
	// Set up Oscillator
	OSCCON = 0x62;				// Internal 4MHZ

	// Setup Ports
	TRISA = 0xFF;				// PORTA Input
	TRISB = 0x0F;           		// PORTB top 4 bits Output
	TRISC = 0xFF;				// PORTC Input

	PORTB = 0;				// LED's off

	// Initialise system
	i2cInit();
	lcdInit();
	
	// Set time
	str[0] = 0x00;
	str[1] = 0x00;
	str[2] = 0x00;
	str[3] = 0x03;
	str[4] = 0x01;
	str[5] = 0x01;
	str[6] = 0x00;
	str[7] = 0x10;
	i2cWrite(0xD0, 0, I2cFast8, str, 8);

        while(1){
		delayMs(1000);
		i2cRead(0xD0, 0, I2cSlow8, str, 8);
		
		lcdWriteStr(0, 0, "");
		lcdPutHexByte(str[0]);
		lcdPutHexByte(str[1]);
		lcdPutHexByte(str[2]);
		lcdPutHexByte(str[3]);
		lcdPutHexByte(str[4]);
		lcdPutHexByte(str[5]);
		lcdPutHexByte(str[6]);
		lcdPutHexByte(str[7]);
        }
}
