You are on page 1of 2

//////////////////////////////////////////////////////////

//***** ENVIAR EL VALOR DEL ADC POR EL PUERTO USB********


//////////////////////////////////////////////////
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
////////////////////////////////////////////////////////////////////////////////
///////////////////
//
// CCS Library dynamic defines. For dynamic configuration of the CCS Library
// for your application several defines need to be made. See the comments
// at usb.h for more information
//
////////////////////////////////////////////////////////////////////////////////
///////////////////
#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 32 // size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 32 // size to allocate for the rx endpoint 1 buffer
////////////////////////////////////////////////////////////////////////////////
///////////////////
//
// Include the CCS USB Libraries. See the comments at the top of these
// files for more information
//
////////////////////////////////////////////////////////////////////////////////
///////////////////
#include <pic18_usb.h> // Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB
driver
#include <header.h> // Configuracin del USB y los descriptores para este disposit
ivo
#include <usb.c> // handles usb setup tokens and get descriptor reports
#define LED_VERDE
PIN_E0
#define Enciende Output_High
#define Apaga Output_Low
//#define Conmuta Output_Toggle
#define RecCommand recbuf[0]
#define LedParam recbuf[1]
#define COMMAND_FIRMWARE 99
#define COMMAND_LEDS 88
#define COMMAND_ADC 01
const int8 Lenbuf = 32;
////////////////////////////////////////////////////////////////////////////////
///////////////////
//
// RAM, RAM, RAM
//
////////////////////////////////////////////////////////////////////////////////
///////////////////
char Version[] = "v.1.0";
int8 recbuf[Lenbuf];
//int8 sndbuf[Lenbuf];
////////////////////////////////////////////////////////////////////////////////
///////////////////

//
// M A I N
//
////////////////////////////////////////////////////////////////////////////////
///////////////////
void main(void) {
int adc0[];
char voltage[9];
setup_adc_ports(AN0|VSS_VDD);//para escoger el canal cero y el vss y vdd
SETUP_ADC(ADC_CLOCK_INTERNAL);//la frecuencia de muestreo es 2-6us
SET_ADC_CHANNEL(0);
delay_ms(500);
usb_init();
usb_task();
usb_wait_for_enumeration();
enable_interrupts(global);
while (TRUE){
if(usb_enumerated()){
if (usb_kbhit(1)){
usb_get_packet(1, recbuf, Lenbuf);
if(RecCommand==COMMAND_FIRMWARE){
usb_put_packet(1,Version,5,USB_DTS_TOGGLE);
}
if(RecCommand==COMMAND_ADC){
adc0 = read_adc(); //para leer el valor del adc0
enciende(LED_VERDE); //enciende un led solo para verificar que se realiz
o bien la comparacion
sprintf(voltage, "%f", (float)adc0 * 0.1960784); //esta instruccion nos
permite convertir el valor del adc en un string.
voltage[4] = '\0';
usb_put_packet(1,voltage,4,USB_DTS_TOGGLE);//con esta instruccion mandam
os el arrglo que se creo en la instruccion anterior
}
}
}
}
}

You might also like