/*****
Created by: Chris @ PyroElectro.com
4/2/2008
--Accel_Test.c--
This Program is meant to test out one input from an
ADXL320 Accelerometer
*******/

#include <p18f452.h>
#include <adc.h>
#include <stdlib.h>
#include <delays.h>

int result;
int flash;
void main(void)
{

			//Set Port B Output & Clear
TRISB = 0x00;
PORTB = 0x00;


			//Initialize The A/D Converter
OpenADC( ADC_FOSC_32 
		& ADC_RIGHT_JUST 
		& ADC_8ANA_0REF, 
		ADC_CH0 & ADC_INT_OFF );

while(1)
{
			//Flash At The Determined Rate
PORTB = 0x00;
Delay1KTCYx(flash);
PORTB = 0x01;
Delay1KTCYx(flash);

			//Get A/D Converted Value
Delay10TCYx(5);
ConvertADC();
while( BusyADC() );
	result = ReadADC();

	
				//If Within Normal Range Blink Slowly
if(result > 506 && result < 518)
	flash = 200;
	
				//If Slightly Tilted Blink Faster
if(result > 518 && result < 550)
	flash = 100;

if(result > 545 && result < 506)
	flash = 100;
	
				//If Really Tilted Blank FAST!	
if(result >= 550)
	flash = 25;

if(result <= 450)
	flash = 25;

}

}
