예제 #1
0
void setTimer2IntRate(void)
{
    stopTimer2();
    /* T2 clock speed is 62500Hz          */
    PR2 = (62500 / termGetFillRate());
    startTimer2();
}
예제 #2
0
void initPWM2(uint16_t prescaler, _t_pwm_pol pol, uint8_t clkSrc)
{
	/* Override previous PWM init */
	initTimer2(prescaler, FAST_PWM, INT_OFF, clkSrc);
	/* DC = 0%*/
	if ((pol == PWM_NORMAL_A)||(pol == PWM_INVERT_A))
	{
		set_pwmPol2A = 0;
		sbi(DDRB, DDB3);
		cbi(PORTB, PORTB3); /* out low */
	}
	if ((pol == PWM_NORMAL_B)||(pol == PWM_INVERT_B))
	{
		set_pwmPol2B = 0;
		sbi(DDRD, DDD3);
		cbi(PORTD, PORTD3); /* out low */
	}		
	pwm2Pins(pol);
	if (pol == PWM_NORMAL_A)
	{
		setDutyPWM2(0, PWM_A);
	}
	if (pol == PWM_NORMAL_B)
	{
		setDutyPWM2(0, PWM_B);
	}
	if (pol == PWM_INVERT_A)
	{
		setDutyPWM2(0xff, PWM_A);
	}
	if (pol == PWM_INVERT_B)
	{
		setDutyPWM2(0xff, PWM_B);
	}
	startTimer2();

}
예제 #3
0
int main(void)
{
	static uint8_t oldPosition;
	static uint8_t divVal, modVal;

	cli();
	wdt_disable();
	set_sleep_mode( SLEEP_MODE_IDLE );
	initDevice();

	DDRD = 0b11111111;
	DDRB = 0b11111111;

	initTimer2();
	initTimer0();
	sei();
	startTimer2();
	startTimer0();
	
	frame	= buf1;
	buffer 	= buf2;

	CLEAR_BUFFER( frame );
	CLEAR_BUFFER( buffer );

	setAnimationFunction( anim_fillDot, TRUE, TRUE );
	animation.loop = TRUE;

    while ( 1 )
    {
		if( animation.tick )
		{
			animationTick();
			clearTick();
		}

		if( currentScanPixel == 0 )
		{
			if( animation.nextFrameReady )
			{
				animationBufferSwap();
			}
		}

		if( oldPosition != currentScanPixel )
		{
			modVal = currentScanPixel % 8;
			
			//we need to change columns only so often
			if( modVal == 0 )
			{
				divVal = currentScanPixel / 8;
				COL_PIXEL( divVal );
			}
			
			if( frame[ divVal ] & _BV( modVal ) )
			{
				ROW_PIXEL( modVal );
			}
			else
			{
				ROW_OFF();
			}
			oldPosition	 = currentScanPixel;
		}

		//if( TIME TO SLEEP ) { sleep_mode(); }

    }

}
예제 #4
0
/*******************************************************************************
* main()
*
* Description:
*   Main application code
*
* See also:
*
* Arguments:
*   void
*
* Returns:
*   void
*
* Callers: C start-up code
*
* Notes :
*
*******************************************************************************/
int main(void)
{
    CBUFFNUM    testBufferNum;
    CBUFFNUM    uartOutBufferNum;
    volatile unsigned int x = 0;
    /* Initialise all used hardware and   */
    /* related interrupts                 */
    initLEDs();
    initUart2();
    initTimer2();
    initInterrupts();
    termInit();

    /* Create circular buffers            */
    cbuffInit();
    testBufferNum = cbuffCreate(testBuffer, TESTBUFFERSIZE,
                                &testBufferObj);
    uartOutBufferNum = cbuffCreate(uartOutBuffer, UARTOUTBUFFERSIZE,
                                   &uartOutBufferObj);

    /* Check buffers were created         */
    if (testBufferNum == 0 || uartOutBufferNum == 0)
    {
        error();
    }

    /* Get handles to buffers             */
    hTestBuffer = cbuffOpen(testBufferNum);
    hUartOutBuffer = cbuffOpen(uartOutBufferNum);
    /* Check buffers were opened          */
    if (hTestBuffer == (HCBUFF) 0 || hUartOutBuffer == (HCBUFF) 0)
    {
        error();
    }
    /* Start Timer based data generation  */
    startTimer2();
    /* Output statistics                  */
    while(1)
    {
        triggerUART2(hUartOutBuffer);

        updateStats(hTestBuffer);

        //termOutput(hUartOutBuffer);

        if(termIsAutomatic())
        {
            if(cbuffGetSpace(hTestBuffer) <= termGetEmptyTrigger())
            {
                termCheckBuffer(hTestBuffer);
                termFullScreenUpdate();
            }
        }
        else if(emptyBuffer == 1)
        {
            emptyBuffer = 0;
            termCheckBuffer(hTestBuffer);
            termFullScreenUpdate();
        }

        if (x >= 0x0FFF)
        {
            termOutput(hUartOutBuffer);
            x = 0;
        }
        else
        {
            x++;
        }
    }
}