Gerard-Meier

Gerjo - IVIbot default settings

Feb 19th, 2011
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. void InitializeSystem(void) {
  2.     // Setup for basic usage:
  3.     ADCON1 |= 0b00001111;   // Default all pins PORTA to digital
  4.     TRISB   = 0b00000000;   // Leds are all set to output.
  5.     TRISA   = 0b00010000;   // RA4 is PGM (program) button
  6.  
  7.     // Setup for IR LEDS:
  8.     TRISD = 0x00;           // Set all PORTD pins to output (Note: room for improvement)
  9.     PORTDbits.RD2 = 0x01;   // left IR LED
  10.     PORTDbits.RD1 = 0x01;   // front IR LED
  11.     PORTDbits.RD0 = 0x01;   // right IR LED
  12.  
  13.     // Setup for IR light detection:
  14.     TRISA   = 0b11011111;   // All input port A5 as output
  15.     ADCON1  = 0b00001011;   // Use AN0 to AN3, 4 channel
  16.     ADCON2  = 0b10100110;   // Select AD acquisition time and AD conversion clock, ADCON2
  17.     ADCON0 |= 0b00000001;   // Turn on AD module, ADCON0 bit 0;
  18.  
  19.     // Setup for both engines:
  20.     PR2     = 0b11111111;   // Set PR2 register to set PWM period to 19.53 kHz before prescale
  21.     T2CON   = 0b00000101;   // Set T2CON register/timer TMR2 to prescale 1:4 gives a PWM freq of 5 khz
  22.  
  23.     TRISCbits.TRISC2 = 0;   // Set as output
  24.     CCP1CON =  0b0001100;   // Enable PWM
  25.  
  26.     TRISCbits.TRISC1 = 0;   // Set as output
  27.     CCP2CON = 0b0001100;    // Enable PWM
  28.  
  29.     TRISEbits.TRISE0 = 0;   // Set as output
  30.     TRISEbits.TRISE1 = 0;   // Set as output
  31.  
  32.     // Setup for tachometer:
  33.     // TODO: make this work
  34. }
Advertisement
Add Comment
Please, Sign In to add comment