Advertisement
Guest User

Timer

a guest
Jan 9th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. void TC0_Handler(void){
  2.   // Some code to read temperature.
  3. }
  4.  
  5. void Init_Timer(){
  6.   int n = 0;
  7.  
  8.   // Select Timer_Clock1 - Clear all first 7 bits for: clock selected: TCLK1
  9.   *TC0_CMR1 = ~(~*TC0_CMR1 | 0x0007);
  10.  
  11.   // ETRGEDG: External Trigger Edge Selection - Edges
  12.   *TC0_CMR1 |= 3 << 8;
  13.  
  14.   // ABETRG: TIOA External Trigger Selection
  15.   *TC0_CMR1 |= 1 << 10;
  16.  
  17.   // LDRA: RA Loading Selection
  18.   *TC0_CMR1 |= 2 << 16;
  19.   // LDRB: RB Loading Selection
  20.   *TC0_CMR1 |= 1 << 18;
  21.  
  22.   //TC1XC1S: External Clock Signal 1 Selection -  Signal connected to XC1: TIOA0
  23.   *TC0_BMR |= 2 << 2;
  24.  
  25.   // Enable pin B25
  26.   *AT91C_PIOB_PER = 1 << 25;
  27.  
  28.   // Multiplex PB25 => TIOA0
  29.   *AT91C_PIOB_ABMR = 1 << 25;
  30.   *AT91C_PIOB_ABSR |= 1 << 25;
  31.  
  32.   NVIC_EnableIRQ(TC0_IRQn);
  33.  
  34.   // Enable interrupt
  35.   // LDRBS: RB Loading
  36.   *TC0_IER1 = 1 << 6;
  37.  
  38.   // Enable clock
  39.   *TC0_CCR1 = 1 << 0;
  40.   // Reset/Start clock
  41.   *TC0_CCR1 = 1 << 2;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement