Detector de Movimiento

4
Diseño Integrado Universidad de Sevilla Pág. 159 Anexo D: Códigos en C Código escrito con el compilador CCS C que convierte el valor de tensión leído desde el convertidor A/D a una variable binaria que encienda los Leds que muestren el rango en el que se encuentra Convierte Entrada Analógica Secuencia LED Binario //****************************************************************** // // PROYECTO FIN DE CARRERA // PLACA DETECTOR DE MOVIMIENTO // Lectura Canal AN2 // // Realizado: MARTA ARENAS MAS // Fecha: 22-Mayo-2008 // Versión: v1 // //****************************************************************** // // Ficheros Utilizados: P18F2550.h // //****************************************************************** #include <18F2550.h> //Permite incluir fichero en el programa #device adc=10 #FUSES NOWDT //Deshabilitado el Watch Dog Timer #FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled #FUSES NOPROTECT //Code not protected from reading #FUSES NOLVP //No low voltage prgming, B5(PIC18) used for I/O #FUSES NODEBUG //No Debug mode for ICD #FUSES USBDIV //USB clock source comes fron PLL divide by 2 #FUSES PLL1 //No PLL PreScaler #FUSES CPUDIV1 //No System Clock Postscaler #FUSES VREGEN //USB voltage regulator enabled #use delay(clock=4000000) //Permite definir la frencia del oscilador del PIC //El Compilador lo utiliza para realizar cálculos de tiempo void main(){ int16 q; int8 Valor; float p;

description

Detector creado con proyecto de Pics

Transcript of Detector de Movimiento

  • DDiisseeoo IInntteeggrraaddoo

    Universidad de Sevilla Pg. 159

    Anexo D: Cdigos en C

    Cdigo escrito con el compilador CCS C que convierte el valor de tensin ledo desde el convertidor A/D a una variable binaria que encienda los Leds que muestren el rango en el que se encuentra

    Convierte Entrada Analgica Secuencia LED Binario

    //****************************************************************** // // PROYECTO FIN DE CARRERA // PLACA DETECTOR DE MOVIMIENTO // Lectura Canal AN2 // // Realizado: MARTA ARENAS MAS // Fecha: 22-Mayo-2008 // Versin: v1 // //****************************************************************** // // Ficheros Utilizados: P18F2550.h // //****************************************************************** #include //Permite incluir fichero en el programa #device adc=10 #FUSES NOWDT //Deshabilitado el Watch Dog Timer #FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled #FUSES NOPROTECT //Code not protected from reading #FUSES NOLVP //No low voltage prgming, B5(PIC18) used for I/O #FUSES NODEBUG //No Debug mode for ICD #FUSES USBDIV //USB clock source comes fron PLL divide by 2 #FUSES PLL1 //No PLL PreScaler #FUSES CPUDIV1 //No System Clock Postscaler #FUSES VREGEN //USB voltage regulator enabled #use delay(clock=4000000) //Permite definir la frencia del oscilador del PIC //El Compilador lo utiliza para realizar clculos de tiempo void main(){ int16 q; int8 Valor; float p;

  • DDiisseeoo ANEXO D IInntteeggrraaddoo Cdigo en C

    Pg. 160 Universidad de Sevilla

    set_tris_B(0xF1); //Configura I/O puerto B setup_adc_ports(AN0_TO_AN2|VSS_VDD);

    //Canales AN0, AN1 y AN2 analgicos de entrada ADCON1 setup_adc(ADC_CLOCK_DIV_2); //Fuente de reloj ADCON2 for (;;){ //Bucle sin fin set_adc_channel(2); // Habilitacin canal 2 delay_us(20); // Espera Tiempo de Adquisicin q=read_adc(); // Opcin por defecto de la funcin. // Habilitacin y lectura de la conversin p=5.0*q/1024.0; // Obtenemos el valor de la tensin leida if (p==5){ Valor=5;} else { if (p>=3){ Valor=4;} else { if(p>=2){ Valor=3;} else { if(p>=1){ Valor=2;} else{ if(p>0){ Valor=1;} else{ Valor=0;} } } } } swap(Valor); //Intercambia los bit de mayor y menor peso Valor=(Valor

  • ANEXO D

    Cdigo en C DDiisseeoo IInntteeggrraaddoo

    Universidad de Sevilla Pg. 161

    //***************************************************************************************** // // PROYECTO FIN DE CARRERA // PLACA DETECTOR DE MOVIMIENTO // USB CDC Lectura AN1 // // Realizado: MARTA ARENAS MAS // Fecha: 22-Mayo-2008 // Versin: v1 // //****************************************************************** // // Ficheros Utilizados: P18F2550.h // //****************************************************************** #include //Permite incluir fichero en el programa #device adc=10 #FUSES NOWDT //Deshabilitado el Watch Dog Timer #FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled #FUSES NOPROTECT //Code not protected from reading #FUSES NOLVP //No low voltage prgming, B5(PIC18) used for I/O #FUSES NODEBUG //No Debug mode for ICD #FUSES USBDIV //USB clock source comes fron PLL divide by 2 #FUSES PLL1 //No PLL PreScaler #FUSES CPUDIV1 //96MHz PLL dividido entre 2 = 48MHz reloj sistema #FUSES VREGEN //USB voltage regulator enabled #use delay(clock=48000000) //Permite definir la frencia del oscilador del PIC //El Compilador lo utiliza para realizar clculos de tiempo #include //Driver que permite utilizar una clase de dispositivo CDC USB, emulando //un dispositivo RS232 y lo muestra como un puerto COM en Windows #include //Fichero con los descriptores de dispositivo #define LED1 PIN_B7 #define LED2 PIN_B6 #define LED_ON output_high #define LED_OFF output_low void main(){ int16 buffer=0; int16 i=0; int iL=0; int iH=0; int bufferL=0; int bufferH=0;

  • DDiisseeoo ANEXO D IInntteeggrraaddoo Cdigo en C

    Pg. 162 Universidad de Sevilla

    set_tris_B(0xF1); //Configura I/O puerto B set_tris_A(0xFF); //Configura entrada Puerto A LED_ON(LED1); //Encendemos el LED1, comienza ejecucin del programa usb_cdc_init(); usb_init(); //Inicializamo los registros USB usb_wait_for_enumeration(); //Esperamos hasta terminar la enumeracin. if(usb_enumerated()) //Si el dispositivo est configurado { LED_OFF(LED1); //Apagamos el LED1 delay_ms(2000); LED_ON(LED2); //Encendemos el LED2 } do{ usb_task(); //Controla la deteccin de conexin. Resetea en caso de que falle if(usb_enumerated()) //Si el dispositivo est configurado { if(i==0) { buffer=0; i=1; } else if (i==1) { buffer=1; i=2; } else if (i==2) { buffer=2; i=0; } //Enviamos valor de la i y del buffer iL=make8(i,0); iH=make8(i,1); if(usb_cdc_putready()) usb_cdc_putc(iL); if(usb_cdc_putready()) usb_cdc_putc(iH); bufferL=make8(buffer,0); bufferH=make8(buffer,1); if(usb_cdc_putready()) usb_cdc_putc(bufferL); if(usb_cdc_putready()) usb_cdc_putc(bufferH); //Esperamos 0.5s para enviar el siguiente delay_ms(500); } }while(TRUE);

    }