#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL3,CPUDIV1,VREGEN
#use delay(clock=20M)
#define USB_HID_DEVICE FALSE //deshabilitamos el uso de las directivas HID
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 1 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 3 //size to allocate for the rx endpoint 1 buffer
#define USB_EP2_TX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint2) for IN bulk/interrupt transfers
#define USB_EP2_RX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint2) for OUT bulk/interrupt transfers
#define USB_EP2_TX_SIZE 1 //size to allocate for the tx endpoint 2 buffer
#define USB_EP2_RX_SIZE 3 //size to allocate for the rx endpoint 2 buffer
#include <pic18_usb.h> //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <PicUSB.h> //Configuración del USB y los descriptores para este dispositivo
#include <usb.c> //handles usb setup tokens and get descriptor reports
#define LEDV PIN_C0
#define LEDR PIN_C1
#define LED_ON output_high
#define LED_OFF output_low
Int Val_AN0,Val_AN1;
Float Sensor1,Sensor2;
#use standard_io(a)
#use fast_io(b)
void Leer_ADC1(void){
setup_adc(adc_clock_div_32);
setup_adc_ports(AN0|VSS_VDD);
set_adc_channel(0);
delay_us (200);
Val_AN0=read_adc();
usb_put_packet(1, Val_AN0, 1, USB_DTS_TOGGLE);
}
void Leer_ADC2(void){
setup_adc(adc_clock_div_32);
setup_adc_ports(AN0|VSS_VDD);
set_adc_channel(1);
delay_us (200);
Val_AN1=read_adc();
usb_put_packet(2, Val_AN1, 1, USB_DTS_TOGGLE);
}
void main(void) {
LED_OFF(LEDV);
LED_ON(LEDR);
usb_init(); //inicializamos el USB
usb_task(); //habilita periferico usb e interrupciones
usb_wait_for_enumeration(); //esperamos hasta que el PicUSB sea configurado por el host
LED_OFF(LEDR);
LED_ON(LEDV); //encendemos led verde
while (TRUE)
{
if(usb_enumerated()) //si el PicUSB está configurado
{
Leer_ADC1();
Leer_ADC2();
}
}
}