Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. /* Configure Timer 2 and start it
  2. */
  3. void Timer2_Init(void)
  4. {
  5. //* 1. Set the Basic Configuration Register for Timer 2
  6. //* 2. Set the Clock Source in relation with system Oscillator frequency
  7. T2CLKCON = 0x06; //sets CS to SOSC freq (pg 440))
  8. //* 3. T2PSYNC Not Synchronized; T2MODE Software control; T2CKPOL Rising Edge; T2CKSYNC Not Synchronized; Timer Mode
  9. T2HLT = 0x00; //sets mode to free running with software gate. (424))
  10. //* 4. T2RSEL set reset source to Pin selected by T2INPPS (pg 443_)
  11. T2RST = 0x00;
  12. //* 5. Set PR2 255;
  13. PR2 = 255; //Timer2 Module Period Register
  14. //* 6. Set TMR2 Prescale Value to 0
  15. T2CON |= 0x00; //Prescale is 0
  16. //* 7. Clearing IF for timer 2
  17. PIR4 &= 0x01; //clears only the Timer2 interrupt flag
  18. //* 8. Start Timer2
  19. T2CON |= 0x80; //turn timer 2 on.
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement