void main (void)
{
	//Set Clock Frequency = 500kHz
	OSCCONbits.IRCF2 = 0;
	OSCCONbits.IRCF2 = 1;
	OSCCONbits.IRCF2 = 1;


	// Enable Global interrupts
	INTCONbits.GIE = 1;		//  Enable High priority interrupt

	//Setup IR Sensor
	setupIRSensor();
	
	//Initializes the timer2 for PWM for Motor and Servo
	setTimer2PWM();
	
	//Setup Motor
	setupMotor();
	
	//Setup Timer for servo
	startTimer0();	

	//Setup Timer for timed water
	startTimer1();
	
	//SetupButtonInterupt
	setupButtons();

	while (1)
    {
		// This area loops forever
    }
}
Beispiel #2
0
int main (void)
{
    // inicializamos la placa
    initBoard();
    
    // configuramos el pin como salida
    configPinOut(&salida);

    // configuramos el timer0 con prescaler 3 = fclk/64; cada vez que llegue a 256 cuentas llamará a la interrupción
    configTimer0(3, time);
    
    // arrancamos el timer
    startTimer0();
    
    // Bucle infinito
    while(1)
    {
        togglePin(&LED[0]);  // parpadear el led para saber que esta vivo
        delay_ms(500);  // demora para que podamos apreciar el parpadeo
    }
    
    return 0; 
}
Beispiel #3
0
void initPWM0(uint16_t prescaler, _t_pwm_pol pol)
 {
	/* Override previous PWM init */
	initTimer0(prescaler, TMR_CLK_RISE, FAST_PWM, CLKOSC, INT_OFF);
	/* DC = 0%*/
	if ((pol == PWM_NORMAL_A)||(pol == PWM_INVERT_A))
	{
		set_pwmPol0A = 0;	
		sbi(DDRD, DDD6);
		cbi(PORTD, PORTD6); /* out low */
	}
	if ((pol == PWM_NORMAL_B)||(pol == PWM_INVERT_B))
	{
		set_pwmPol0B = 0;
		sbi(DDRD, DDD5);
		cbi(PORTD, PORTD5); /* out low */
	}		
	pwm0Pins(pol);
	if (pol == PWM_NORMAL_A)
	{
		setDutyPWM0(0, PWM_A);
	}
	if (pol == PWM_NORMAL_B)
	{
		setDutyPWM0(0, PWM_B);
	}
	if (pol == PWM_INVERT_A)
	{
		setDutyPWM0(0xff, PWM_A);
	}
	if (pol == PWM_INVERT_B)
	{
		setDutyPWM0(0xff, PWM_B);
	}
	startTimer0();
}
Beispiel #4
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(); }

    }

}