Ejemplo n.º 1
0
void usartWriteBuffer(uint8_t* buffer,uint16_t lenght)
{
 for(uint16_t i=0;i<lenght;i++)
 {
    usartWriteByte(buffer[i]);
 }
}
Ejemplo n.º 2
0
// ============================================================================
int main( void )
{
	int	ch = 0;
	uint32_t ccount = 0;
	uint32_t lastTick;
	int pwm;

	SystemCoreClockUpdate();
	SysTick_Config( SystemCoreClock / HB_HZ);

	// Enable peripheral clocks
	// TODO:	Remove GPIOCEN when moving to the smaller CPU
	RCC->AHBENR |= (RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | RCC_AHBENR_GPIOCEN);
	
#ifdef USE_USART
	InitUSART(400);
#endif	// USE_USART

	InitLED();
	InitServo();

	configButtons();

	while( 1 ) {
		if ( curTick > (HB_HZ) ) {
			curTick -= (HB_HZ);

			// Once per second processing...

		}
		if ( curTick != lastTick ) {
			lastTick = curTick;

			// On each timer tick move the turnout slightly closer to the new position
			for ( int idx=0; idx<SERVO_COUNT; ++idx ) {
				if ( servo[idx].currentPos < servo[idx].targetPos ) {
					servo[idx].currentPos += SERVO_DELTA;
					if ( servo[idx].currentPos > servo[idx].targetPos ) {
						servo[idx].currentPos = servo[idx].targetPos;
					}
				}
				else
				if ( servo[idx].currentPos > servo[idx].targetPos ) {
					servo[idx].currentPos -= SERVO_DELTA;
					if ( servo[idx].currentPos < servo[idx].targetPos ) {
						servo[idx].currentPos = servo[idx].targetPos;
					}
				}
			}

			TIM1->CCR1 = servo[SERVO1].currentPos;
			TIM1->CCR2 = servo[SERVO2].currentPos;
			TIM1->CCR3 = servo[SERVO3].currentPos;
			TIM1->CCR4 = servo[SERVO4].currentPos;

			btnCheck();
		}
#ifdef USE_USART
		if ( usartTxEmpty() ) {
			usartWriteByte(ch+33);
			++ch;
			ch &= 0x3F;
		}
#endif	// USE_USART
	}
}