All pastes #2132295 Raw Edit

Something

public text v1 · immutable
#2132295 ·published 2012-03-26 20:26 UTC
rendered paste body
/*
 * Timer1.cpp
 *
 *  Created on: Mar 26, 2012
 *      Author: Realisations
 */

#include "Timer0.h"

bool ledState_ = false;

ISR(TCC0_OVF_vect, ISR_BLOCK)
{
	if (ledState_)
	{
		ledState_ = false;
		PORTB.OUT |= 0x01;
	}
	else
	{
		ledState_ = true;
		PORTB.OUT &= ~0x01;
	}
}



Timer0::Timer0() {

	TCC0.CTRLA = TC_CLKSEL_DIV1_gc; //timer setté à clock/4 //timer ON
	TCC0.INTCTRLA = TC_OVFINTLVL_MED_gc; //active interruption on overflow, priotité low

	TCC0.PERL = 0xff; //valeur pour un overflow
	TCC0.PERH = 0xff; //dois toujours écrire PERL avant PERH (opération atomique en passant par un buffer)

	TCC0.CNTL = 0x00; //initialise le compteur à 0
	TCC0.CNTH = 0x00; //dois toujours écrire CNTL avant PERH (opération atomique en passant par un buffer)

	//interruption
	//setting the global interrupt enable bit (I-bit) in the CPU Status Register
	//enable interrupt level
	PMIC.CTRL |= PMIC_MEDLVLEN_bm; //active les low levels interrupts dans le PMIC
	SREG |= CPU_I_bm; //sei(), Global Interrupt Enable

}

Timer0::~Timer0() {

}