#include "p18f4550.h"
#include "./USB/usb.h"
#include "./USB/usb_function_cdc.h"
#include "main.h"
#include "adc.h"
#include "delays.h"
void user(void)
{
//Blink the LEDs according to the USB device status
BlinkUSBStatus();
// User Application USB tasks
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
//-- clear adc interrupt and turn off adc if in case was on prerviously---
TRISAbits.TRISA5=1; //RA5/AN4 as analog input
CloseADC();
Delay10TCYx(5);
/**********Iitialize ADC***********
ADC configured for:
* FOSC/64 as conversion clock
* Result is right justified
* Aquisition time of 20 TAD
* Channel 4 for sampling
* ADC interrupt off
* ADC reference voltage from VDD & VSS
**********************************************/
OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_20_TAD, ADC_CH4 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS,
7);
SetChanADC(ADC_CH4);
Delay10TCYx(5);
ConvertADC();
while(BusyADC());
Delay10TCYx(3);
if(USBUSARTIsTxTrfReady())
{ USB_In_Buffer[0] = ADRESL; // pack the ADC result to the packet buffer
USB_In_Buffer[1] = ADRESH; // LSB first
putUSBUSART(USB_In_Buffer,2);
}
CDCTxService();}