Título: Ayuda con pic18f2550 Publicado por: Fdelilah en 10 Noviembre 2011, 06:43 am Hola a todas y todos, :) bueno soy nueva en el foro y en esto de la programación utilizando pics, nunca antes había trabajado con ellos la verdad y quisiera que me hicieran el enorme favor de revisarme y corregirme el siguiente código que he hecho. Mi proyecto consiste en calcular el tiempo que tarda digamos una bolita en llegar de un punto a otro, para eso utilizo sensores infrarrojos emisor-receptor; estos sensores están conectados a una compuerta OR y cuando pase la bolita a traves de uno de ellos, se envia una señal al pic y almacena un tiempo, utilizo el modulo ccp... además utilizare una conexion usb.
El código es el siguiente: #include <18F2550.h> #FUSES NOWDT //No Watch Dog Timer #FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale #FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD #FUSES NOPROTECT //Code not protected from reading #FUSES NOBROWNOUT //No brownout reset #FUSES BORV20 //Brownout reset at 2.0V #FUSES NOPUT //No Power Up Timer #FUSES NOCPD //No EE protection #FUSES STVREN //Stack full/underflow will cause reset #FUSES NODEBUG //No Debug mode for ICD #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #FUSES NOWRT //Program memory not write protected #FUSES NOWRTD //Data EEPROM not write protected #FUSES IESO //Internal External Switch Over mode enabled #FUSES FCMEN //Fail-safe clock monitor enabled #FUSES PBADEN //PORTB pins are configured as analog input channels on RESET #FUSES NOWRTC //configuration not registers write protected #FUSES NOWRTB //Boot block not write protected #FUSES NOEBTR //Memory not protected from table reads #FUSES NOEBTRB //Boot block not protected from table reads #FUSES NOCPB //No Boot Block code protection #FUSES MCLR //Master Clear pin enabled #FUSES LPT1OSC //Timer1 configured for low-power operation #FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) #FUSES PLL12 //Divide By 12(48MHz oscillator input) #FUSES CPUDIV4 //System Clock by 4 #FUSES USBDIV //USB clock source comes from PLL divide by 2 #FUSES VREGEN //USB voltage regulator enabled #device adc=8 #use delay(crystal=40000000, clock=10000000) #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 #include <pic18_usb.h> #include "PicUSB.h" //Configuración del USB y los descriptores para este dispositivo //#include <usb.h> #include <usb.c> // VARIABLES GLOBALES. int16 tiempo1=0, tiempo2=0, tiempoFinal=0; long des =0; #int_ccp1 void ccp1_int() { if(tiempo1==0) tiempo1 = CCP_1; else tiempo2 = CCP_1; } #int_TIMER1 void TIMER1_isr(void) { des++; } void main() { long conteo; enable_interrupts(int_ccp1); // Habilita la interrupción externa. enable_interrupts(global); // Habilita en forma global las interrupciones. // ext_int_edge (0, H_TO_L); // La interrupción se produce cuando se produce un flanco descendente. setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); setup_ccp1(CCP_CAPTURE_RE); output_high(PIN_A1);//Encender led en el pin A1 output_low(PIN_A0); usb_init(); //inicializamos el usb usb_task(); //habilitamos el periferico usb e interrupciones usb_wait_for_enumeration(); //esperamos hasta que el picusb sea configurado por el host si no se queda igual output_low(PIN_A1);//Encender led en el pin A1 output_high(PIN_A0); while(1) { if(usb_enumerated()) { if (usb_kbhit(1)) { conteo=des*65536; tiempofinal=tiempo2-tiempo1+conteo; usb_put_packet(1, tiempoFinal, 2 ,USB_DTS_TOGGLE); } } } } Creanme que les agradecería muchísimo su ayuda! :D |