Exemplo n.º 1
0
int main(void)
{
	int flag = 0;
	TIM2_Init();
  InitIO();

 while(1)
 {	 
	 		if(tick_1ms >= 5)//500
		{
			tick_1ms = 0;
			flag = !flag;
			if(flag == 0)
			{
				GPIO_SetBits(GPIOA , 0xaaaa);
				GPIO_SetBits(GPIOB , 0xaaaa);
				GPIO_SetBits(GPIOC , 0xaaaa);
				GPIO_SetBits(GPIOD , 0xaaaa);
				GPIO_SetBits(GPIOE , 0xaaaa);
				GPIO_SetBits(GPIOF , 0xaaaa);
				GPIO_SetBits(GPIOG , 0xaaaa);
				
				GPIO_ResetBits(GPIOA , 0x5555);
				GPIO_ResetBits(GPIOB , 0x5555);
				GPIO_ResetBits(GPIOC , 0x5555);
				GPIO_ResetBits(GPIOD , 0x5555);
				GPIO_ResetBits(GPIOE , 0x5555);
				GPIO_ResetBits(GPIOF , 0x5555);		
				GPIO_ResetBits(GPIOG , 0x5555);	
				
			}else
			{
				GPIO_ResetBits(GPIOA , 0xaaaa);
				GPIO_ResetBits(GPIOB , 0xaaaa);
				GPIO_ResetBits(GPIOC , 0xaaaa);
				GPIO_ResetBits(GPIOD , 0xaaaa);
				GPIO_ResetBits(GPIOE , 0xaaaa);
				GPIO_ResetBits(GPIOF , 0xaaaa);
				GPIO_ResetBits(GPIOG , 0xaaaa);
				
				GPIO_SetBits(GPIOA , 0x5555);
				GPIO_SetBits(GPIOB , 0x5555);
				GPIO_SetBits(GPIOC , 0x5555);
				GPIO_SetBits(GPIOD , 0x5555);
				GPIO_SetBits(GPIOE , 0x5555);
				GPIO_SetBits(GPIOF , 0x5555);		
				GPIO_SetBits(GPIOG , 0x5555);				
			}
			
		}
		
 }
}
Exemplo n.º 2
0
int main(void)
{
	delay_init();
	GPIOCLKInit();
	UserLEDInit();
	LCD1602Init();
	//IRCtrolInit();
	TIM2_Init();
	MotorInit();
	ServoInit();
	
	RedRayInit();
	//USART3Conf(9600);

 while(1)
 {	 
	 		if(tick_5ms >= 5)
		{
			tick_5ms = 0;
			tick_200ms++;
			if(tick_200ms >= 40)
			{
				tick_200ms = 0;
				LEDToggle(LED_PIN);
			}
//			continue_time--;//200ms 无接收指令就停车
//			if(continue_time == 0)
//			{
//				continue_time = 1;
//				CarStop();
//			}
			//do something
			SearchRun();
			if(ctrl_comm_last != ctrl_comm)//指令发生变化
			{
				ctrl_comm_last = ctrl_comm;
				switch(ctrl_comm)
				{
					case COMM_UP:    CarGo();break;
					case COMM_DOWN:  CarBack();break;
					case COMM_LEFT:  CarLeft();break;
					case COMM_RIGHT: CarRight();break;
					case COMM_STOP:  CarStop();break;
					default : break;
				}
				Delayms(10);//防抖
				LCD1602WriteCommand(ctrl_comm);
			}
		}
		
 }
}
Exemplo n.º 3
0
int main(void)
{
	delay_init();
	GPIOCLKInit();
	UserLEDInit();
	//LCD1602Init();
	//IRCtrolInit();
	TIM2_Init();
	MotorInit();
	UltraSoundInit();
	//RedRayInit();
	ServoInit();

 while(1)
 {	 
	 		if(tick_5ms >= 5)
		{
			tick_5ms = 0;
			tick_200ms++;
			if(tick_200ms >= 40)
			{
				tick_200ms = 0;
				LEDToggle(LED_PIN);
				//LCD1602WriteDistance(distance_cm);//更新距离
			}
//			continue_time--;//200ms 无接收指令就停车
//			if(continue_time == 0)
//			{
//				continue_time = 1;
//				CarStop();
//			}
			//do something
			Distance();//计算距离
			BarrierProc();
//			if(ctrl_comm_last != ctrl_comm)//接收到红外信号
//			{
//				ctrl_comm_last = ctrl_comm;
//				switch(ctrl_comm)
//				{
//					case COMM_UP:    CarGo();break;
//					case COMM_DOWN:  CarBack();break;
//					case COMM_LEFT:  CarLeft();break;
//					case COMM_RIGHT: CarRight();break;
//					case COMM_STOP:  CarStop();break;
//					default : break;
//				}
//				LCD1602WriteCommand(ctrl_comm);
//			}
		}
		
 }
}
Exemplo n.º 4
0
int main(void)
{
	delay_init();
	GPIOCLKInit();
	UserLEDInit();
	LCD1602Init();
	IRCtrolInit();
	TIM2_Init();
	MotorInit();
	ServoInit();

 while(1)
 {	 
	 		if(tick_5ms >= 5)
		{
			tick_5ms = 0;
			tick_200ms++;
			if(tick_200ms >= 40)
			{
				tick_200ms = 0;
				LEDToggle(LED_PIN);
			}
			
			continue_time--;//200ms 无接收指令就停车
			if(continue_time == 0)
			{
				continue_time = 1;
				CarStop();
			}
			//do something
			if(ir_rec_flag == 1)//接收到红外信号
			{
				ir_rec_flag = 0;
				switch(ctrl_comm)
				{
					case COMM_UP:    CarGo();break;
					case COMM_DOWN:  CarBack();break;
					case COMM_LEFT:  CarLeft();break;
					case COMM_RIGHT: CarRight();break;
					case COMM_STOP:  CarStop();break;
					default : break;
				}
				LCD1602WriteCommand(ctrl_comm);
			}
		}
		
 }
}
Exemplo n.º 5
0
void System_init(void)
{
	//系统时钟初始化 内部16M
	System_Clock_init();
  //串口初始化 9600
	UART1_Init();
	//串口发送函数绑定
	HekrInit(UART1_SendChar);
	//16M主频延迟初始化
	delay_init(16);
	//通过上电次数选择模式 必须先初始化延迟 串口
	Bright_ModeInit();

	//PWM 初始化
	TIM2_Init();
	//亮度调整定时器
	TIM1_Init();
	_asm("rim");
}
Exemplo n.º 6
0
void timer2_init(uint32 counter_ms)
{
	TIM2_Init(counter_ms);
	NVIC_Configuration();	
}
Exemplo n.º 7
0
//extern s8 CarSTARTFLAG;
void IR_init(void)
{
    TIM2_Init();
    EXTI0_Init();
}
Exemplo n.º 8
0
/****************************************************************************
* 名	称:void TIM2_Config(void)
* 功	能:配置定时器
* 入口参数:无
* 出口参数:无
* 说	明:无
****************************************************************************/	   
void TIM2_Config(void)
{
	TIM2_Init();			   	//定时器初始化
	TIM2_NVIC_Init();			//中断向量表初始化
}
Exemplo n.º 9
0
Arquivo: main.c Projeto: kenziD/ANO
int main(void)
{
    float q[4];
    u8 tmp_buf[32] = {0};
    float test = 0;
    static u8 led_on = 0;

    RCC_HSE_Configuration();
    SysTick_Init();
    NVIC_Configuration();
    USART1_Config(115200);
    LED_Init();
    LED3_Flash(2,100);
    ANO_TC_I2C2_INIT(0xA6, 400000, 1, 1, 3, 3);
    //硬实时
    Tim3_Init(500);//0.005s
    TIM2_Init(999, 0);

    Mpu6050init();
    MOT_GPIO_init();
    MOT_PWM_init();
    Set_PWM(0, 0, 0, 0);
    NRF24L01_Init();
    while (NRF24L01_Check())
    {
        LED2_Flash(2,500000);
    }

    //TX mode
    NRF24L01_Mode_Config(4);
    PID_Init();
    ADC1_Init();
    while (1)
    {
        if (getMpu6050Data == 1)
        {
            //0.01ms?
            Read_Mpu6050();
            Mpu6050_Analyze();
            getMpu6050Data = 0;
        }
        if (calculateAngle == 1)//2ms period
        {
            //0.2ms T
            //LED2_ON;

            //100us
            IMU_Quateration_Update((float)fGYRO_X , (float)fGYRO_Y , (float)fGYRO_Z , (float)fACCEL_X, (float)fACCEL_Y, (float)fACCEL_Z,ypr);
            //LED2_OFF;
            calculateAngle = 0;
        }
        if (sendData == 1)//2ms period
        {
            if(led_on)
            {
                LED2_OFF;
                led_on = 0;
            }
            else
            {
                LED2_ON;
                led_on = 1;
            }

            if (NRF24L01_RxPacket(tmp_buf) == 0)
            {
                //10us
                Rc_Data_Analyze(tmp_buf,&Rc_Data);
            }
            //if wait for the IRQ it need 9ms
            //if not wait for IRQ it runtime need 100us*1.2=0.12ms

            sendSenser((int16_t)fACCEL_X, (int16_t)fACCEL_Y, (int16_t)fACCEL_Z, (int16_t)fGYRO_X, (int16_t) fGYRO_Y, (int16_t)fGYRO_Z, (int16_t)(ypr[0] * 100), (signed short int)(ypr[1] * 100));
            send_wave(32);

            //0.14ms run time
            sendPwmVoltage(&Rc_Data,(uint16_t)(motor0 / 1000.0 * 100), (uint16_t)(motor1 / 1000.0 * 100), (uint16_t)(motor2 / 1000.0 * 100), (uint16_t)(motor3 / 1000.0 * 100));//0.00003974s
            send_wave(32);

            sendData = 0;
        }
        //moveFilterAccData(fACCEL_X, fACCEL_Y, fACCEL_Z, AngleOut);

        if (!strcmp(Rc_Data.status, "stop"))
        {
            Set_PWM(0, 0, 0, 0);
        }
        else if (!strcmp(Rc_Data.status, "start"))
        {
            //LED2_ON;
            expRoll = Rc_Data.roll;
            expPitch = Rc_Data.pitch;
            expThro = Rc_Data.throttle;
            surRoll = ypr[2];
            surPitch = ypr[1];
            PID_Set();
            Set_PWM(motor0, motor1, motor2, motor3);
            //LED2_OFF;
        }
        ////Uart1_Send_PID(320,PID_ROLL.KI,PID_ROLL.KD,1,0,0);
        ////send_wave(32);
        // if (STA == 1)
        // {
        // 	receive_Data();
        // 	STA = 0;
        // 	p = 0;
        // }
    }
}
Exemplo n.º 10
0
void TIM2_Init_All(void)
{
		TIM2_NVIC_Init();
		TIM2_Init();
		TIM2_GPIO_RCC_Init();
}
Exemplo n.º 11
0
void Encoder_Init(void){
	TIM3_Init();
	TIM2_Init();
	EXTI4_Encoder_Init();
}
Exemplo n.º 12
0
/*
 *berif: Initialize the encoding module
 *param: None
 *reval: None
*/
void Init_Encoder(void)
{
    TIM2_Init();		//Timer
    TIM3_Init();		//Counter(R)
    TIM4_Init();		//Counter(L)
}