コード例 #1
0
static void initISR(timer16_Sequence_t timer)
{  
#if defined (_useTimer1)
  if(timer == _timer1) {
    TCCR1A = 0;             // normal counting mode 
    TCCR1B = _BV(CS11);     // set prescaler of 8 
    TCNT1 = 0;              // clear the timer count 
#if defined(__AVR_ATmega8__)|| defined(__AVR_ATmega128__)
    TIFR |= _BV(OCF1A);      // clear any pending interrupts; 
    TIMSK |=  _BV(OCIE1A) ;  // enable the output compare interrupt  
#else
    // here if not ATmega8 or ATmega128
    TIFR1 |= _BV(OCF1A);     // clear any pending interrupts; 
    TIMSK1 |=  _BV(OCIE1A) ; // enable the output compare interrupt 
#endif    
#if defined(WIRING)       
    timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service); 
#endif	
  } 
#endif  


#if defined (_useTimer3)
  if(timer == _timer3) {
    TCCR3A = 0;             // normal counting mode 
    TCCR3B = _BV(CS31);     // set prescaler of 8  
    TCNT3 = 0;              // clear the timer count 
#if defined(__AVR_ATmega128__)
    TIFR |= _BV(OCF3A);     // clear any pending interrupts;   
	ETIMSK |= _BV(OCIE3A);  // enable the output compare interrupt     
#else  
    TIFR3 = _BV(OCF3A);     // clear any pending interrupts; 
    TIMSK3 =  _BV(OCIE3A) ; // enable the output compare interrupt      
#endif
#if defined(WIRING)    
    timerAttach(TIMER3OUTCOMPAREA_INT, Timer3Service);  // for Wiring platform only	
#endif  
  }
#endif

#if defined (_useTimer4)
  if(timer == _timer4) {
    TCCR4A = 0;             // normal counting mode 
    TCCR4B = _BV(CS41);     // set prescaler of 8  
    TCNT4 = 0;              // clear the timer count 
    TIFR4 = _BV(OCF4A);     // clear any pending interrupts; 
    TIMSK4 =  _BV(OCIE4A) ; // enable the output compare interrupt
  }    
#endif

#if defined (_useTimer5)
  if(timer == _timer5) {
    TCCR5A = 0;             // normal counting mode 
    TCCR5B = _BV(CS51);     // set prescaler of 8  
    TCNT5 = 0;              // clear the timer count 
    TIFR5 = _BV(OCF5A);     // clear any pending interrupts; 
    TIMSK5 =  _BV(OCIE5A) ; // enable the output compare interrupt      
  }
#endif
} 
コード例 #2
0
ファイル: uartsw128.c プロジェクト: ericsims/AVRLib
//! enable and initialize the software uart
void uartswInit(void)
{
    // initialize the buffers
	uartswInitBuffers();
	// initialize the ports
	sbi(UARTSW_TX_DDR, UARTSW_TX_PIN);
	cbi(UARTSW_RX_DDR, UARTSW_RX_PIN);
	cbi(UARTSW_RX_PORT, UARTSW_RX_PIN);
	// initialize baud rate
	uartswSetBaudRate(9600);
	
	// setup the transmitter
	UartswTxBusy = FALSE;
	// disable OC2 interrupt
	cbi(TIMSK, OCIE2);
	// attach TxBit service routine to OC2
	timerAttach(TIMER2OUTCOMPARE_INT, uartswTxBitService);
		
	// setup the receiver
	UartswRxBusy = FALSE;
	// disable OC0 interrupt
	cbi(TIMSK, OCIE0);
	// attach RxBit service routine to OC0
	timerAttach(TIMER0OUTCOMPARE_INT, uartswRxBitService);
	// INT2 trigger on rising edge
	sbi(EICRA, ISC20);
	// enable INT2 interrupt
	sbi(EIMSK, INT2);

	// turn on interrupts
	sei();
}
コード例 #3
0
ファイル: uartsw.c プロジェクト: wtos03/Geartronics-Git-Sever
//! enable and initialize the software uart
void uartswInit(void)
{
    // initialize the buffers
	uartswInitBuffers();
	// initialize the ports
	sbi(UARTSW_TX_DDR, UARTSW_TX_PIN);
	cbi(UARTSW_RX_DDR, UARTSW_RX_PIN);
	cbi(UARTSW_RX_PORT, UARTSW_RX_PIN);
	// initialize baud rate
	uartswSetBaudRate(9600);

	// setup the transmitter
	UartswTxBusy = FALSE;
	// disable OC1A interrupt
	cbi(TIMSK, OCIE1A);
	// attach TxBit service routine to OC1A
	timerAttach(TIMER1OUTCOMPAREA_INT, uartswTxBitService);

	// setup the receiver
	UartswRxBusy = FALSE;
	// disable OC1B interrupt
	cbi(TIMSK, OCIE1B);
	// attach RxBit service routine to OC1B
	timerAttach(TIMER1OUTCOMPAREB_INT, uartswRxBitService);
	// attach RxBit service routine to ICP
	timerAttach(TIMER1INPUTCAPTURE_INT, uartswRxBitService);
	// trigger on rising edge
	sbi(TCCR1B, ICES1);
	// enable ICP interrupt
	sbi(TIMSK, TICIE1);

	// turn on interrupts
	sei();
}
コード例 #4
0
ファイル: Servo253.cpp プロジェクト: natosa123/new_robot_code
void Servo253::start()
{
  //digitalWrite(48, HIGH);
  timer2Init();

  // disble timer2 output compare interrupt
  TIMSK &= ~_BV(OCIE2);

  // set the prescaler for timer2
   timer2SetPrescaler(TIMER_CLK_DIV1024);
//timer2SetPrescaler(TIMER_CLK_DIV256);

  // attach the software PWM service routine to timer2 output compare
  timerAttach(TIMER2OUTCOMPARE_INT, service);

///TIMER2_OVF_vect


  // update output compare register
  OCR2 += SERVO_PERIOD;



  // enable the timer2 output compare interrupt
  TIMSK |= _BV(OCIE2);

  // reset position ticks
  _positionTicks = 0;

  // reset current servo
  _current = -1;
}
コード例 #5
0
ファイル: spyglasstest.c プロジェクト: lanwan/avrlib2
void spyglassTest(void)
{
	// initializing Spyglass interface and I2C bus
	rprintf("Initializing Spyglass communication...");
	spyglassInit();
	spyglassLcdInit();
	rprintf("Done!\r\n");
	rprintf("Printing 'Hello World!' message to spyglass LCD.\r\n");

	rprintfInit(spyglassLcdWriteChar);
	spyglassLcdGotoXY(0,0);
	rprintfProgStrM("Hello World!");
	rprintfInit(uartSendByte);

	timerPause(1000);

	// initialize systick timer
	rprintf("Initializing Periodic Timer\r\n");
	timer2SetPrescaler(TIMERRTC_CLK_DIV1024);
	// attach the 'systickHandler' so that it gets called every time Timer2 overflows
	timerAttach(TIMER2OVERFLOW_INT, systickHandler);

	rprintf("Starting local command prompt.  Type '?' to get help.\r\n");
	rprintf("cmd>");

	while(1)
	{
		serviceLocal();
	}
}
コード例 #6
0
ファイル: uartsw2.c プロジェクト: hokim72/AVR-Common
// enable and initialize the software uart
void uartswInit(void)
{
	// initialize the buffers
	uartswInitBuffers();
	// initialize the ports
	sbi(UARTSW_TX_DDR, UARTSW_TX_PIN);
	#ifdef UARTSW_INVERT
	cbi(UARTSW_TX_PORT, UARTSW_TX_PIN);
	#else
	sbi(UARTSW_TX_PORT, UARTSW_TX_PIN);
	#endif
	cbi(UARTSW_RX_DDR, UARTSW_RX_PIN);
	#ifdef UARTSW_INVERT
	cbi(UARTSW_RX_PORT, UARTSW_RX_PIN);
	#else
	sbi(UARTSW_RX_PORT, UARTSW_RX_PIN);
	#endif
	// initialize baud rate
	uartswSetBaudRate(9600);

	// setup the transmitter
	UartswTxBusy = FALSE;
	// disable OC0A interrupt
	cbi(TIMSK0, OCIE0A);
	// attach TxBit service routine to OC0A
	timerAttach(TIMER0OUTCOMPAREA_INT, uartswTxBitService);

	// setup the receiver
	UartswRxBusy = FALSE;
	// disable 0C0B interrupt
	cbi(TIMSK0, OCIE0B);
	// attach RxBit service routine to OC0B
	timerAttach(TIMER0OUTCOMPAREB_INT, uartswRxBitService);
	// INT1 trigger on rising/falling edge
	#ifdef UARTSW_INVERT
	sbi(EICRA, ISC11);
	sbi(EICRA, ISC10);
	#else
	sbi(EICRA, ISC11);
	cbi(EICRA, ISC10);
	#endif
	// enable INT1 interrupt
	sbi(EIMSK, INT1);

	// turn on interrupts
	sei();
}
コード例 #7
0
ファイル: lcdtest.c プロジェクト: BackupTheBerlios/rundfunker
//Main für LCD-Test
int main(void)
{
//u08 a=0;

	// initialize our libraries
	// initialize the UART (serial port)
//	uartInit();
	// make all rprintf statements use uart for output
//	rprintfInit(uartSendByte);
	// turn on and initialize A/D converter
	//a2dInit();
	// initialize the timer system
	timerInit();
	// print a little intro message so we know things are working
//	rprintf("\r\nWelcome to AVRlib!\r\n");
	
	timer1SetPrescaler(4);
	timerAttach(TIMER1OVERFLOW_INT, lcdPrepare);

	// initialize LCD
	//lcdInit();
	// direct printf output to LCD
//	rprintfInit(lcdDataWrite);

	// print message on LCD
	//rprintf("Welcome to AVRlib!");

	//DDRC = 0x00;
	//PORTC = 0x00;

	// display a bargraph of the analog voltages on a2d channels 0,1
	
	while(1)
	{
	//	lcdGotoXY(0,0);
	//	lcdProgressBar(a2dConvert8bit(0), 255, 20);
	//	rprintf(" X: %d", a2dConvert8bit(0));
	//	rprintf(" Sample: %d", a++);
	//	lcdGotoXY(0,1);
	//	lcdProgressBar(a2dConvert8bit(1), 255, 20);
	//	rprintf(" Y: %d", a2dConvert8bit(1));

		if(lcdPrepared){
			lcdClear();
			lcdGotoXY(0,0);
			rprintf("0. Zeile");
			lcdGotoXY(1,1);
			rprintf("1. Zeile %d",'ü');
			lcdGotoXY(2,2);
			rprintf("2. Zeile");
			lcdGotoXY(3,3);
			rprintf("3. Zeile");
		}
	}

	return 0;
}
コード例 #8
0
ファイル: systemtime.c プロジェクト: jan1s/hw-nixieclock-avr
void systemTimeInit(void)
{
	cli();
	milliseconds = 0;
	timer3Init();
	timer3SetMode(TIMER_MODE_CTC_OCR);
	timer3SetOutputModeA(TIMER_OUTMODE_TOGGLE);
	timer3SetCompareValueA(249);
	timerAttach(TIMER3OUTCOMPAREA_INT, systemTimeMillisecondsTick);
	sei();
}
コード例 #9
0
ファイル: pulse.c プロジェクト: BackupTheBerlios/arduino-svn
void pulseT1Init(void)
{
	// try to make sure that timer1 is in "normal" mode
	// most importantly, turn off PWM mode
	timer1PWMOff();

	// set some reasonable initial values
	// in case the user forgets to
	PulseT1AMode = 0;
	PulseT1BMode = 0;
	PulseT1ACount = 0;
	PulseT1BCount = 0;
	PulseT1APeriodTics = 0x8000;
	PulseT1BPeriodTics = 0x8000;

	// attach the pulse service routines to
	// the timer 1 output compare A and B interrupts
	timerAttach(TIMER1OUTCOMPAREA_INT,pulseT1AService);
	timerAttach(TIMER1OUTCOMPAREB_INT,pulseT1BService);
}
コード例 #10
0
//! enable and initialize the software uart
void uartswInit(void)
{
    // initialize the buffers
	uartswInitBuffers();
	// initialize the ports
	sbi(UARTSW_TX_DDR, UARTSW_TX_PIN);
	#ifdef UARTSW_INVERT
	cbi(UARTSW_TX_PORT, UARTSW_TX_PIN);
	#else
	sbi(UARTSW_TX_PORT, UARTSW_TX_PIN);
	#endif
	cbi(UARTSW_RX_DDR, UARTSW_RX_PIN);
	cbi(UARTSW_RX_PORT, UARTSW_RX_PIN);
	// initialize baud rate
	uartswSetBaudRate(9600);
	
	// setup the transmitter
	UartswTxBusy = FALSE;
	// disable OC2 interrupt
	cbi(TIMSK0, OCIE2A);
	// attach TxBit service routine to OC2
	timerAttach(TIMER2OUTCOMPARE_INT, uartswTxBitService);
		
	// setup the receiver
	UartswRxBusy = FALSE;
	// disable OC0 interrupt
	cbi(TIMSK0, OCIE0A);
	// attach RxBit service routine to OC0
	timerAttach(OCIE0A, uartswRxBitService);
	// INT2 trigger on rising/falling edge
	#ifdef UARTSW_INVERT
	sbi(MCUCR, ISC11);	// rising edge
	#else
	cbi(MCUCR, ISC11);	// falling edge
	#endif
	// enable INT2 interrupt
	sbi(PCMSK0, PCINT2);

	// turn on interrupts
	sei();
}
コード例 #11
0
ファイル: rtc.c プロジェクト: 46nori/avr-liberty
void rtcInit(void)
{
	// set up timer for RTC operation
	// initialize real-time registers
	RtcTime.totaltics = 0;
	RtcTime.tics = 0;
	RtcTime.seconds = 0;
	RtcTime.minutes = 0;
	RtcTime.hours = 0;
	RtcTime.day = 1;
	RtcTime.month = 1;
	RtcTime.year = 2000;

	// select the correct RTC timer based on bit defines
	#ifdef AS2
		// use timer2 for most AVRs
		// initialize timer 2
		timer2Init();
		// count with 32.768KHz/8
		timer2SetPrescaler(TIMER_CLK_DIV8);
		// switch to asynchronous input (32KHz crystal)
		sbi(ASSR, AS2);
		// attach service to real-time clock interrupt
		// rtcService() will be called at ((32768/8)/256) = 16Hz
		timerAttach(TIMER2OVERFLOW_INT, rtcService);
	#else
	#ifdef AS0
		// use timer0 for ATmega103, ATmega128
		// initialize timer 0
		timer0Init();
		// count with 32.768KHz/8
		timer0SetPrescaler(TIMER_CLK_DIV8);
		// switch to asynchronous input (32KHz crystal)
		sbi(ASSR, AS0);
		// attach service to real-time clock interrupt
		// rtcService() will be called at ((32768/8)/256) = 16Hz
		timerAttach(TIMER0OVERFLOW_INT, rtcService);
	#endif
	#endif
}
コード例 #12
0
ファイル: scheduler.c プロジェクト: woutercloete/cableguard
u08 schedInit()
{
  u08 cnt;
  
  timerAttach(TIMER1OVERFLOW_INT, schedService);
  schedTicks = 0;
  for (cnt = 0 ; cnt < MAX_SIGNALS ; cnt++)
  {
    signal[cnt] = 0;
  }
  
  return 0;
}
コード例 #13
0
ファイル: keysta.c プロジェクト: leeku11/kbdmod
void
kbd_init(void)
{
	kbd_state = IDLE_START;
	kbd_flags = FLA_CLOCK_HIGH | FLA_TX_OK;

	clockHigh();
	dataHigh();

	timer2Init();
	timer2SetPrescaler(TIMER_CLK_DIV8);
	timerAttach(TIMER2OVERFLOW_INT, timerAction);
    timer2IntEnable();
	outp(COUNT_UP, TCNT2);	/* value counts up from this to zero */
}
コード例 #14
0
ファイル: servo.c プロジェクト: BackupTheBerlios/arduino-svn
//! initializes software PWM system
void servoInit(void)
{
	u08 channel;
	// disble the timer1 output compare A interrupt
	cbi(TIMSK, OCIE1A);
	// set the prescaler for timer1
	timer1SetPrescaler(TIMER_CLK_DIV256);
	// attach the software PWM service routine to timer1 output compare A
	timerAttach(TIMER1OUTCOMPAREA_INT, servoService);
	// enable and clear channels
	for(channel=0; channel<SERVO_NUM_CHANNELS; channel++)
	{
		// set minimum position as default
		ServoChannels[channel].duty = SERVO_MIN;
		// set default port and pins assignments
		ServoChannels[channel].port = _SFR_IO_ADDR(SERVO_DEFAULT_PORT);
		//ServoChannels[channel].port = (unsigned char)&SERVO_DEFAULT_PORT;
		ServoChannels[channel].pin = (1<<channel);
		// set channel pin to output
		// THIS IS OBSOLETED BY THE DYNAMIC CHANNEL TO PORT,PIN ASSIGNMENTS
		//outb(SERVODDR, inb(SERVODDR) | (1<<channel));
	}
	// set PosTics
	ServoPosTics = 0;
	// set PeriodTics
	ServoPeriodTics = SERVO_MAX*9;
	// set initial interrupt time
	u16 OCValue;
	// read in current value of output compare register OCR1A
	OCValue =  inb(OCR1AL);		// read low byte of OCR1A
	OCValue += inb(OCR1AH)<<8;	// read high byte of OCR1A
	// increment OCR1A value by nextTics
	OCValue += ServoPeriodTics; 
	// set future output compare time to this new value
	outb(OCR1AH, (OCValue>>8));			// write high byte
	outb(OCR1AL, (OCValue & 0x00FF));	// write low byte
	// enable the timer1 output compare A interrupt
	sbi(TIMSK, OCIE1A);
}
コード例 #15
0
ファイル: netstacktest.c プロジェクト: hokim72/AVR-Common
int main(void)
{
	struct netEthAddr myEthAddress;

	timerInit();
	uartInit();
	uartSetBaudRate(9600);
	rprintfInit(uartSendByte);
	timerPause(100);
	rprintf("\r\nNetwork Stack Example\r\n");

	// initialize systick timer
	rprintf("Initializing Periodic Timer\r\n");
	timer2SetPrescaler(TIMER_CLK_DIV1024);
	timerAttach(TIMER2OVERFLOW_INT, systickHandler);

	// init network stack
	rprintf("Initializing Network Stack\r\n");
	netstackInit(IPADDRESS, NETMASK, GATEWAY);

	nicGetMacAddress(&myEthAddress.addr[0]);
	rprintfProgStrM("Eth Addr is: "); netPrintEthAddr(&myEthAddress); rprintfCRLF();
	rprintfProgStrM("IP  Addr is: "); netPrintIPAddr(ipGetConfig()->ip); rprintfCRLF();

	rprintf("Network Stack is up!\r\n");
	rprintf("Starting packet receive loop\r\n");

	while (1)
	{
		// service local stuff
		serviceLocal();
		// service the network
		netstackService();
	}
	return 0;
}
コード例 #16
0
ファイル: reflow.c プロジェクト: Kalars/Reflow_Controller
static void avr_init(void)
// Initializes AVR controller
{
	MAX6675S_DDR |= BV(MAX6675_CSPIN);		// setup direction for CS pin
	DISABLE_6675;							// Set CS = high for MAX6675	
	initZerocross();						// init ext Int0
	initTriac();							// init Triac pin & direction


#ifdef REG_PID
//	initPID(&PID_data, 1, 0, 10, 10, -10);

//void pid_Init(int16_t p_factor, int16_t i_factor, int16_t d_factor, struct PID_DATA *pid);
	pid_Init(P_FACTOR, I_FACTOR, D_FACTOR, &PID_data);
#endif

#ifdef REG_PD
	initPD(&PD_data, 800, 1000);
#endif


	//attach functions to timer interrupts
	timerAttach(TIMER0OVERFLOW_INT, sample);
	timerAttach(TIMER2OUTCOMPAREA_INT, stopTriac);
	timerAttach(TIMER1OUTCOMPAREA_INT, fireTriac);

	//enable output compare for timers
	sbi(TIMSK0, TOIE0);
	sbi(TIMSK1, OCIE1A);
	sbi(TIMSK2, OCIE2A);

	//set OCR values. 
//	OCR0A = PHASE_ANGLE_LIMIT_HIGH;				//firing angle of triac
	OCR2A = 1;									//length of firing pulse
	OCR1A = PHASE_ANGLE_LIMIT_HIGH;				//temperature sample frequency

	timer0SetPrescaler(TIMER_CLK_DIV1024);		//start temp. sampling

/*************************************** 
  * Timer0 runs at 24Mhz/1024 = 
  *
  * 
  *
  ***************************************/

#ifndef DEBUG_SIM
	#ifdef DEBUG_SER
	// initialize the UART (serial port)
	uartInit();

	// set the baud rate of the UART for our debug/reporting output
	uartSetBaudRate(57600);

	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);

	// print a little intro message so we know things are working
	rprintf("Reflow!\r\n");

//	vt100SetCursorMode(1);
//	vt100SetAttr(VT100_BLINK_OFF);
//	vt100SetAttr(VT100_USCORE_OFF);
//	vt100SetAttr(VT100_REVERSE);

	//vt100ClearScreen();
	// start command line
//	goCmdline();
 
	#endif

	// initialize SPI interface
	spiInit();
#endif

//	SET_HALF_PHASE;
//	SET_SKIP_PHASE;
//	skips = 15;
	//enable interrupts
	sei();


    return;
}
コード例 #17
0
ファイル: custommacro.c プロジェクト: showjean/ps2avrU
void initCustomMacro(void){
    timer2Init();
    timerAttach(TIMER2OVERFLOW_INT, timerActionCustomMacro);
    stopTimerCustomMacro();
}