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 }
// Setup ports and ADC config void setup() { SET_TRIS_C(0); // Sets PORT C to output only setup_adc_ports(sAN2); setup_adc(adc_clock_internal); set_adc_channel(2); }
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 Ini_USART(){ // Son necesarios definir los bits /* ***** // Transmicion #BYTE TXSTA = 0x98 #BYTE SPBRG = 0x99 #BYTE TXREG = 0x19 // Recepcion #BYTE RCREG = 0x1A #BYTE RCSTA = 0x18 ***** */ TXSTA = 0x20; SPBRG = 15; // V=9766 BAUD XTAL=10MHz RCSTA = 0x90; TXREG = 0x00; RCREG = 0x00; SET_TRIS_C(0x80); }
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(); } } }