void init_pic() { setup_adc_ports(AN0); setup_adc(ADC_CLOCK_DIV_32); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RTCC); enable_interrupts(INT_EXT); enable_interrupts(GLOBAL); EXT_INT_EDGE(L_TO_H); OUTPUT_B(0); OUTPUT_C(0); SET_TRIS_B(0b01000111); //pins B0, B1, B2 and B6 are set to give inputs. B0 is the external interuupt pin //B0, B1 & B2 are used for people counting. B6 for zero crossing detection in fan controlling SET_TRIS_C(0b00000000); SET_TRIS_D(0b00000000); //D port except D0 pin, is used for lcd panel set_adc_channel(0); //the next read_adc call will read channel 0 }
//--------------------------------- void main() { //#byte TRISB=0b11000000; SET_TRIS_B(0xC0); //configura PORTB entrada / 0=salida / 1=entrada OUTPUT_D(0x00); //inicializando PORTD en 0x00 //#byte PORTB=0x00; setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);//|RTCC_8_bit); //51.2 us overflow // setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //13.1 ms overflow // setup_ccp1(CCP_COMPARE_SET_ON_MATCH); // enable_interrupts(INT_RTCC); enable_interrupts(INT_RTCC); enable_interrupts(GLOBAL); cont=0; comp1=0; while(TRUE) { set_adc_channel(0); delay_ms(1);//tiempo de offset necesario comp1=((read_adc())/1024.0*250.0); delay_ms(1);//tiempo de offset necesario } }
void init_pic() { setup_adc_ports(AN0); setup_adc(ADC_CLOCK_DIV_32); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RTCC); enable_interrupts(INT_EXT); enable_interrupts(GLOBAL); EXT_INT_EDGE(L_TO_H); OUTPUT_B(0); OUTPUT_C(0); SET_TRIS_B(0b01000111); //pins B0, B1 and B2 are set to give inputs. b0 is the external interuupt pin SET_TRIS_C(0b00000000); SET_TRIS_D(0b00000000); set_adc_channel(0); //the next read_adc call will read channel 0 }
void Cargar_configuracion(){ SET_TRIS_B(0xF0); //configura PORTB entrada / 0=salida / 1=entrada SET_TRIS_D(0x00); //configura PORTD salida lcd_init(); //c=0; }
void main() { SET_TRIS_B(0x00); while(TRUE) { output_high(PIN_B0); delay_ms(50); output_low(PIN_B0); delay_ms(50); } }
void main() { setup_timer_2(T2_DIV_BY_16,255,1); //4.0 ms overflow, 4.0 ms interrupt setup_ccp1(CCP_PWM); setup_ccp2(CCP_PWM); set_pwm1_duty((int16)200); set_pwm2_duty((int16)200); enable_interrupts(INT_SSP); enable_interrupts(GLOBAL); SET_TRIS_B(0); stop(); //delay_ms(500); while(TRUE) { if(hasCommand) { hasCommand= FALSE; if(buffer[0] == 's'){ show(); } else switch(buffer[1]) { case 1: go_forward(); break; case 2: go_backward(); break; case 3: turn_right(); break; case 4: turn_left(); break; case 5: stop(); break; default : break; } } } }
void main() { SET_TRIS_B(0xFF); //configura PORTB entrada / 0=salida / 1=entrada SET_TRIS_A(0x00); //configura PORTD salida OUTPUT_A(0x00); //inicializando PORTD en 0x00 while(true) { if (input(PIN_B1) == 1 ){ output_low(PIN_A0); //establece la salida del PORTD }else { output_high(PIN_A0); } } }
main() { /* Vista frontal, motor detras de la barra |------|------|------|------|------|------|------|------| 0 128 256 384 512 640 768 896 1024 */ SET_TRIS_A( 0xFF ); SET_TRIS_B( 0x00 ); SET_TRIS_C( 0x00 ); inicializar(); while(true) { leer(); if(lectura < 128) { giro_derecha100(); } else if(lectura < 256) { giro_derecha75(); } else if(lectura < 384) { giro_derecha50(); } else if(lectura < 512) { giro_derecha25(); } else if(lectura < 640) { giro_izquierda25(); } else if(lectura < 768) { giro_izquierda50(); } else if(lectura < 896) { giro_izquierda75(); } else if(lectura < 1024) { giro_izquierda100(); } } }
void Cargar_configuracion() { SET_TRIS_B(0xFF); //configura PORTB entrada / 0=salida / 1=entrada SET_TRIS_D(0x00); //configura PORTD salida OUTPUT_D(0x00); //inicializando PORTD en 0x00 estado_alarma = 0; }
void Cargar_configuracion(){ SET_TRIS_B(0xFF); //configura PORTB entrada / 0=salida / 1=entrada SET_TRIS_D(0x00); //configura PORTD salida OUTPUT_D(0x00); //inicializando PORTD en 0x00 angulo = 2; // inicializando el angulo de dispario en 2ms }
// **************************************************************** // Definicion de Funciones void Configuracion(){ SET_TRIS_B(0xFF); //configura PORTB entrada / 0=salida / 1=entrada SET_TRIS_A(0x00); //configura PORTD salida OUTPUT_A(0x00); //inicializando PORTD en 0x00 CMCON = 0x07; }