Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void InitializeSystem(void) {
- // Setup for basic usage:
- ADCON1 |= 0b00001111; // Default all pins PORTA to digital
- TRISB = 0b00000000; // Leds are all set to output.
- TRISA = 0b00010000; // RA4 is PGM (program) button
- // Setup for IR LEDS:
- TRISD = 0x00; // Set all PORTD pins to output (Note: room for improvement)
- PORTDbits.RD2 = 0x01; // left IR LED
- PORTDbits.RD1 = 0x01; // front IR LED
- PORTDbits.RD0 = 0x01; // right IR LED
- // Setup for IR light detection:
- TRISA = 0b11011111; // All input port A5 as output
- ADCON1 = 0b00001011; // Use AN0 to AN3, 4 channel
- ADCON2 = 0b10100110; // Select AD acquisition time and AD conversion clock, ADCON2
- ADCON0 |= 0b00000001; // Turn on AD module, ADCON0 bit 0;
- // Setup for both engines:
- PR2 = 0b11111111; // Set PR2 register to set PWM period to 19.53 kHz before prescale
- T2CON = 0b00000101; // Set T2CON register/timer TMR2 to prescale 1:4 gives a PWM freq of 5 khz
- TRISCbits.TRISC2 = 0; // Set as output
- CCP1CON = 0b0001100; // Enable PWM
- TRISCbits.TRISC1 = 0; // Set as output
- CCP2CON = 0b0001100; // Enable PWM
- TRISEbits.TRISE0 = 0; // Set as output
- TRISEbits.TRISE1 = 0; // Set as output
- // Setup for tachometer:
- // TODO: make this work
- }
Advertisement
Add Comment
Please, Sign In to add comment