Projekt/snake_init.c
void init_timer(){
  //timer 2 interrupt enable and interrupt priority bits
  IEC(0) = IEC(0) | 0b0000000100000000;//set T2IE to 1 (Interrupt Enable Control bit in IEC0 interrupt register)
  IPC(2) = IPC(2) | 0b00000000000000000000000000011100;//set T2IP to ones (Interrupt Priority Control bits)
  
  //init Timer 2 - 16 bit timer
  T2CONCLR = T2CON_ENABLE_BIT; //stops the timer?
  uint32_t target_frequency = 1; //60 Hz / our timer timesout 10 times each second
  uint32_t prescaler = 256; //256 is needed since we need a low frequency 
  uint32_t pb_clock_frequency = 80E6;
  uint16_t period = pb_clock_frequency / (prescaler * target_frequency); //set our max value of the timer = 31250
  T2CON = T2CON_PRESCALER_BITS; //sets prescaler to 256 (see global definition)
  TMR2 = 0; //set the current number of ticks in our timer to 0
  PR2 = period; //set the max number of ticks equal to our period
  
  enable_interrupt();
}
/*
Initializes timer 2 with timeout of 100ms 
when it times out it sets an interrupt bit to 1 and calls render_frame
*/
Initializes timer 2 with timeout of 100ms
when it times out it sets an interrupt bit to 1 and calls render_frame
Initializes timer 2 with timeout of 100ms when it times out it sets an interrupt bit to 1 and calls render_frame
void init_timer(){
  IEC(0) = IEC(0) | 0b0000000100000000;
  IPC(2) = IPC(2) | 0b00000000000000000000000000011100;
  T2CONCLR = T2CON_ENABLE_BIT; 
  uint32_t target_frequency = 1; 
  uint32_t prescaler = 256; 
  uint32_t pb_clock_frequency = 80E6;
  uint16_t period = pb_clock_frequency / (prescaler * target_frequency); 
  T2CON = T2CON_PRESCALER_BITS; 
  TMR2 = 0; 
  PR2 = period; 
  enable_interrupt();
}
void init_timer ( ) { IEC ( 0 ) = IEC ( 0 ) | 0b0000000100000000 ; IPC ( 2 ) = IPC ( 2 ) | 0b00000000000000000000000000011100 ; T2CONCLR = T2CON_ENABLE_BIT ; uint32_t target_frequency = 1 ; uint32_t prescaler = 256 ; uint32_t pb_clock_frequency = 80E6 ; uint16_t period = pb_clock_frequency / ( prescaler * target_frequency ) ; T2CON = T2CON_PRESCALER_BITS ; TMR2 = 0 ; PR2 = period ; enable_interrupt ( ) ; }
Initializes timer 2 with timeout of 100ms
when it times out it sets an interrupt bit to 1 and calls render_frame
Initializes timer 2 with timeout of 100ms when it times out it sets an interrupt bit to 1 and calls render_frame
//timer 2 interrupt enable and interrupt priority bits //set T2IE to 1 (Interrupt Enable Control bit in IEC0 interrupt register) //set T2IP to ones (Interrupt Priority Control bits) //init Timer 2 - 16 bit timer //stops the timer? //60 Hz / our timer timesout 10 times each second //256 is needed since we need a low frequency  //set our max value of the timer = 31250 //sets prescaler to 256 (see global definition) //set the current number of ticks in our timer to 0 //set the max number of ticks equal to our period