#include <18F2553.h>
#device ADC = 12
//configure a 20MHz crystal to operate at 48MHz
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
//#use rs232(baud = 115200, xmit = PIN_C6, rcv = PIN_C7)
#include <usb_cdc.h>
//#include <input.c>
//#include <stdlib.h>
unsigned int16 adc_data;
int32 i=0;
int8 s2r=1; //s2r - Seconds to record
int32 c2t; //c2r - Cycles to transmit
//Initializing the RTOS Program
#use rtos(timer = 0, minor_cycle = 10us)
#task(rate = 100us, max = 10us) // 100uS -> 10kHz
void transmit_over_usb()
{
//adc_data = read_adc();
printf(usb_cdc_putc, "%Lu\n\r", read_adc());
if(++i==10000)//(i == c2t)
rtos_terminate( );
}
void main()
{
#use standard_io(A)
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_64); // for 48MHz OSC
//setup_adc(ADC_CLOCK_DIV_16); // For 20 MHz OSC
set_adc_channel(0);
delay_us(10);
usb_cdc_init();
usb_init();
while(!usb_cdc_connected()) {}
do
{
usb_task();
if (usb_enumerated())
{
wait_usb: // Label
while (usb_cdc_getc() != 'r') ;
i=0;
s2r=1;
c2t = (s2r*1e6)/250; // How many cycles to transmit the data. NOTE: Denumerator should be equal to "rate" in main RTOS task
output_high(PIN_B0);
rtos_run();
output_low(PIN_B0);
// printf("Done!\n\r");
printf(usb_cdc_putc,"5002\n\r");
goto wait_usb;
}
} while (TRUE);
}