Пример #1
0
void USART1_Init(void)
{
	USART1_GPIO_Configuration();	
	USART1_Configuration();	
	NVIC_Configuration();
	USART_ClearFlag(USART2,USART_FLAG_TC);
}
Пример #2
0
int main(void)
{
  uint8_t colorR =0 ,colorG =0 ,colorB =0 ;
  uint8_t colorR_dir =0 ,colorG_dir =0 ,colorB_dir =0 ;
  char lcd_text_buff[100];

  float GyX =0.0f, GyY =0.0f, GyZ =0.0f;
  float X_offset =0.0f,Y_offset =0.0f,Z_offset =0.0f;
  uint32_t i=0;
  float delay_count=1000.0f;

  GPIO_Configuration();
  USART1_Configuration();
  CANx_Config();
  CANx_NVIC_Config();
  lcd_init();
  lcd_drawBackground(20,60,250);
  lcd_drawBGPersimmon(20, 60, 250);


    LCD_SetColors(LCD_COLOR_WHITE-1,LCD_COLOR_WHITE);
    LCD_SetFont(&Font16x24);
    LCD_DisplayStringLine(LINE(1), (uint8_t*)" CAN Bus DEMO  ");
    DrawNeedle(120,120,60,300.0f,0.0f,200.0f);
  while (1)
  {
    CANx_Transmit();
    GPIO_ToggleBits(LED4);

    Delay_1us(1000);
  }
  
}
Пример #3
0
/***********************************************************
*   函数说明:系统硬件初始化函数                           *
*   输入:    无                                           *
*   输出:    无                                           *
*   调用函数:Port_Init()  RCC_Configuration()             *
***********************************************************/
void Device_Init(void)
{
	RCC_Configuration();
	get_sig_cfg_param(1);

	PORT_Init();/*此处需要修改  malooei  2012/11/14*/

	USART2_Configuration(); /* 用于连接pc */

	USART1_Configuration(); /* 用于向光纤传输数据 */
	DMA_USART1_Configuration( );

	adc1_dma_cfg();
	ADC1_Configuration();

	//box_tmper_ctrl_init();

#if !USE_PVD_CHECK_POWEROFF
	Exti_Init();
#else
	Exti_Pvd_Init();
#endif

	spi1_cfg4ads8329();
	delay_us(500*1000); /* 240ms, cpu最低工作电压为2.0V, ads8329最低工作电压为2.7V, David */
	init_ads8329();

	TIM3_Configuration();

	NVIC_Configuration();

	return;
}
Пример #4
0
//! Initialize the USART
void usartinit() {
    RCC_Configuration();

    GPIO_Configuration();

    USART1_Configuration();
}
Пример #5
0
//Main Function
int main(void)
{
	//RCC_Configurastatic();
	GPIO_Configuration();
	USART1_Configuration();
	LCD_SetColors(0x1188, 0x0000);
	LCD_SetFont(&Font8x8);
	t_queue = xQueueCreate(1, sizeof(int));
	if (!t_queue) {
		ReportError("Failed to create t_queue");
		while(1);
	}

	t_mutex = xSemaphoreCreateMutex();
	if (!t_mutex) {
		ReportError("Failed to create t_mutex");
		while(1);
	}

	prvInit();
	
	//LCD_DisplayStringLine(LCD_LINE_1,text);
	//xTaskCreate(usart_text, (char *) "Draw Graph Task", 256,
	//	             NULL, tskIDLE_PRIORITY + 2, NULL);
xTaskCreate(r3d, (char *) "Draw Graph Task", 256,
		             NULL, tskIDLE_PRIORITY + 2, NULL);
	
	
	RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
        RNG_Cmd(ENABLE);

	//Call Scheduler
	vTaskStartScheduler();
}
Пример #6
0
int main(void)
{ 
  RCC_Configuration();		 	//配置RCC
	initDesireAngles();
	
	TIMER4_Enable();					//定时器4
	TIMER4_Configuration();		//配置中断
	
  USART1_GPIO_Config();		 	//配置GPIO
	USART1_NVIC_Config();			//配置中断
  USART1_Configuration();	 	//配置串口1
	
	USART2_GPIO_Config();
	USART2_Configuration();

	I2C_GPIO_Config();				//配置IIC使用端口
  Delayms(10);				 			//延时
	Init_MPU6050();		     //初始化MPU6050
	
	PWM_Configuration();
		
	while(1)
	{

	}
	 			//回车
	
}
Пример #7
0
void Init(void)
{
    //时钟配置
    RCC_Configuration();
    NVIC_Configuration();
    delay_init(72);

    //串口配置
    USART1_Configuration();
    USART2_Configuration();
    USART3_Configuration();
    UART4_Configuration();
    UART5_Configuration();
    USART_ITEnable();

    //PWM配置
    PWMTIM_Configuration(72000/5,0);	      //不分频。PWM频率=Freq

    //指南针配置
    COMPASS_Init();

    //舵机配置
    SERVOS_Init();

    //设置到初始值
    PWM_Configuration(MOTOR_Speed);
    s3010_SeTAngle(SERVOS_Angle);
}
Пример #8
0
int main(void)
{
    RCC_Configuration();
    GPIO_Configuration();
    USART1_Configuration();
    LED_Initialization();
    USART1_puts("Hello World!\r\n");
    USART1_puts("Just for STM32F429I Discovery verify USART1 with USB TTL Cable\r\n");
    while(1)
    {
        //LED3_Toggle();

        //Recieve
        if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET){ // == SET
        char t = USART_ReceiveData(USART1);
        if(t == 'a') LED3_Toggle();
        else if(t == 'b') LED4_Toggle();

        //Transmitt
        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
        USART_SendData(USART1, t);

        }

    }

    while(1); // Don't want to exit
}
Пример #9
0
/***************************************************************************
Declaration : void init_mcu (void)

Function :    Initializes ATmega88 MCU
***************************************************************************/
void init_mcu (void)
{
#ifdef DEBUG
  debug();
#endif
  /* System Clocks Configuration */
  RCC_Configuration();
       
  /* Configure the GPIO ports */
  GPIO_Configuration();
 
  /* Configure EXTI Line9 to generate an interrupt on falling edge */
  EXTI_Configuration();

  /* SPI the GPIO ports */
  SPI_Configuration(); 
   
  /* USART  Configuration as SPI */
  USART1_Configuration();
  
  /* TIM2 Configuration */
  TIM2_Configuration();
  
  /* TIM3 Configuration */
  TIM3_Configuration();
  
  /* TIM4 Configuration */
  TIM4_Configuration();
  
   /* Configure RTC clock source and prescaler */
  RTC_Configuration(); 
   
  /* NVIC configuration */
  NVIC_Configuration();
}
Пример #10
0
/*! \fn USART_Configuration(void)
 *	\brief in this function, we need to configure each usart individually, also the usart buf.
 */
void USART_Configuration(void)
{
    USART1_Configuration();
//    USART2_Configuration();
  //USART3_Configuration();
   	BUF_INIT(1);
//	BUF_INIT(2); 
}
Пример #11
0
void  BSP_Init (void)
{
    RCC_Configuration();
    NVIC_Configuration();
    USART1_Configuration();
    GPIO_Configuration();
//TODO  Now temporary comment this code, the official version will open his
//     IWDG_Configuration();
}
Пример #12
0
int main(int argc, char* argv[])
{
	int ret;

	RCC_Configuration();
	
	LED_Init(LED1);
	LED_Init(LED2);
	
	LED_On(LED1);
	LED_Off(LED2);

	BOOT_Pin_Init();

	USART1_Configuration();

#if defined(MULTIFLASH_ENABLE)
	probe_flash();
#endif

	/* Load Configure Infomation */
	load_S2E_Packet_from_storage();

	/* Check MAC Address */
	check_mac_address();

	W5500_SPI_Init();
	W5500_Init();
	Timer_Configuration();

	Net_Conf();
	TFTP_init(SOCK_TFTP, socket_buf);

	ret = application_update();

	if((get_bootpin_Status() == 0) && (ret != TFTP_FAIL)) {
		uint32_t tmp;

#if !defined(MULTIFLASH_ENABLE)
		tmp = *(volatile uint32_t *)APP_BASE;
#else
		tmp = *(volatile uint32_t *)flash.flash_app_base;
#endif

		if((tmp & 0xffffffff) != 0xffffffff) {
			application_jump();
		}
	}

	while (1) {
		do_udp_config(SOCK_CONFIG);
	}
}
Пример #13
0
void USART1_Init(unsigned long baud)
{	
	u8 MemTestErr;
	USART1RecvPtrW = 0;
	USART1RecvPtrR = 0;
	USART1SendQBoxHost = 0;
	USART1SendQBoxTail = 0;
	USART1SendQFree = USART1_SEND_MAX_BOX;

	USART1_Configuration(baud);
	OSQUSART1Index=(OSMEMTcb *)OSMemCreate(OSUSART1MemQ,OS_MEM_USART1_BLK,OS_MEM_USART1_MAX/OS_MEM_USART1_BLK, &MemTestErr);
}
Пример #14
0
//Main Function
int main(void)
{
	prvInit();
	RCC_Configuration();
	GPIO_Configuration();
	USART1_Configuration();

	if( STM_EVAL_PBGetState( BUTTON_USER ) )
		demoMode = 1;
	srand(5566);
	xTaskCreate( Uart, (signed char*) "Uart", 128, NULL, tskIDLE_PRIORITY + 1, NULL );
	xTaskCreate( GameTask, (signed char*) "GameTask", 128, NULL, tskIDLE_PRIORITY + 1, NULL );
	xTaskCreate( GameEventTask1, (signed char*) "GameEventTask1", 128, NULL, tskIDLE_PRIORITY + 1, NULL );
	xTaskCreate( GameEventTask2, (signed char*) "GameEventTask2", 128, NULL, tskIDLE_PRIORITY + 1, NULL );
	xTaskCreate( GameEventTask3, (signed char*) "GameEventTask3", 128, NULL, tskIDLE_PRIORITY + 1, NULL );

	//Call Scheduler
	vTaskStartScheduler();
}
Пример #15
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
    u8 res=0;
	delay_init();
    RCC_Configuration();  // Configure the system clocks
    NVIC_Configuration(); // NVIC Configuration
    GPIO_Configuration();
	
//    USART3_Configuration();	
    USART1_Configuration();
	
    Timer_Configuration();
	LED_GPIO_Configuration();
  	LED1_ON;;		

    Reset_W5500();
    WIZ_SPI_Init();

    ZC_Init();
    WIZ_Config(); // network config & Call Set_network ();
    Get_ChipInfo();
    presentTime = my_time; // For TCP client's connection request delay
    // Start Application
    printf("\r\n\r\n------------------------------------------- \r\n");
    printf("Loopback using W5500\r\n");  
    printf("------------------------------------------- ");
//    AC_ConfigWifi();

 do{
    res = Dhcp_Task();
    }while(res!=0);
    
   HF_WakeUp();
    while(1)
    {
     
      HF_Cloudfunc();
      
    }

}
Пример #16
0
  /*
********************************************************************************
** 函数名称 : main(void)
** 函数功能 : 主函数
** 输    入	: 无
** 输    出	: 无
** 返    回	: 无
********************************************************************************
*/
int main(void)
{ 
  RCC_Configuration();		 //配置RCC
  GPIO_Configuration();		 //配置GPIO
  USART1_Configuration();	 //配置串口1
  I2C_GPIO_Config();		 //配置IIC使用端口
  Delayms(10);				 //延时
  Init_MPU3050();		     //初始化MPU3050
  while(1)
 {
	READ_MPU3050();	         //读取MPU3050数据
    DATA_printf(TX_DATA,T_X);//转换X轴数据到数组
	Send_data('X');			 //发送X轴数
	DATA_printf(TX_DATA,T_Y);//转换Y轴数据到数组
	Send_data('Y');			 //发送Y轴数
	DATA_printf(TX_DATA,T_Z);//转换Z轴数据到数组
	Send_data('Z');			 //发送Z轴数
	DATA_printf(TX_DATA,T_T);//转换温度数据到数组
	Send_data('T');			 //发送温度数据
	USART1_SendData(0X0D);	 //换行
	USART1_SendData(0X0A);	 //回车
	Delayms(5);				 //延时
  }
}
Пример #17
0
void USART1_Configuration(void)
{
    USART_InitTypeDef USART_InitStructure;

    /* USARTx configuration ------------------------------------------------------*/
    /* USARTx configured as follow:
     *  - BaudRate = 57600 baud
     *  - Word Length = 8 Bits
     *  - One Stop Bit
     *  - No parity
     *  - Hardware flow control disabled (RTS and CTS signals)
     *  - Receive and transmit enabled
     */
    USART_InitStructure.USART_BaudRate = 57600;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    //START USART
    USART_Init(USART1, &USART_InitStructure);
    USART_Cmd(USART1, ENABLE);

    //Using Interrupt
    USART_ClearFlag(USART1, USART_FLAG_TC);

    //Enable RX interrupt & Disable TX interrupt
    USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    /* NVIC Initialization */
    NVIC_InitTypeDef NVIC_InitStruct = {
      .NVIC_IRQChannel = USART1_IRQn,
      .NVIC_IRQChannelPreemptionPriority = 0,
      .NVIC_IRQChannelSubPriority = 0,
      .NVIC_IRQChannelCmd = ENABLE
    };
    NVIC_Init(&NVIC_InitStruct);

}

void USART1_puts(char* s)
{
    while(*s) {
        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
        USART_SendData(USART1, *s);
        s++;
    }
}

/**************************************************************************************/
int main(void)
{
    RCC_Configuration();
    GPIO_Configuration();
    USART1_Configuration();
    LED_Initialization();
    USART1_puts("Hello World!\r\n");
    USART1_puts("Just for STM32F429I Discovery verify USART1 with USB TTL Cable\r\n");

    while(1)
    {
        //LED4_Toggle();

        //Delay_1us(10000);
        //USART1_puts(i);        
    }
}
Пример #18
0
void init_rs232(void)
{
    USART1_RCC_Configuration();
    USART1_GPIO_Configuration();
    USART1_Configuration();
}
Пример #19
0
void  BSP_Init (void)
{
	// Clock Config: HSE 72 MHz
#if __RTC_ENABLE == ON
	RTC_Configuration();
#else
	RCC_Configuration();
#endif


#if __USART1_ENABLE == ON
	// USART1 Config ==> FTDI
	USART1_Configuration();
#endif

#if __USART3_ENABLE == ON
	// USART3 Config ==> Trypano support card
	USART3_Configuration();
#endif


#if __SRAM_ENABLE == OFF && __LED_ENABLE == ON
	// LED Config
		LED_Configuration();
#endif

#if __SWITCH_ENABLE == ON
	// SWITCH Config
	SWITCH_Configuration();
#endif

	// I2C Config
#if __I2C_ENABLE == ON
		I2C_Configuration();
#endif

#if __POT_ENABLE == ON
	// Pot / ADC Config
	ADC_POT_Configuration();
#endif

#if __USB_ENABLE == ON
	//USB Config
	USB_Configuration();
#endif

#if __DAC1_ENABLE == ON
	//DAC Config and start
	DAC1_Configuration();
#endif


#if __SRAM_ENABLE == ON
	// RAM Config
	SRAM_Configuration();
#endif

#if __SDCARD_ENABLE == ON
	// SDCard Config
	SDCARD_Configuration();
#endif

#if __DAC2_ENABLE == ON
	DAC2_Configuration();
#endif

#if __ADCe1_ENABLE == ON
	ADCe1_Configuration();
#endif

}
Пример #20
0
/*
*@功能 主函数入口
*@参数	空
*@返回	空
*/
int main(void)
{
	

	
	
	
	
  /*测试变量部分*/	
	/*******************************************/
	uint8_t t=' ';
	uint8_t usb_code[6]={0x55,0x7A,0xBB,0x01,0x00,0x01};//下位机反复的向上位机发送此命令,用以建立初始化连接
  uint8_t p[6]={0x30,0x31,0x32,0x33,0x34,0x35};
	uint8_t hanzi[11];
	uint8_t *phz;
	uint32_t flash_data;
	uint8_t flash_temp[4];
	uint8_t status;
  uint32_t addr;
	uint8_t nChar;
// 	uint8_t char_buf[50];
// 	uint8_t count;

	uint32_t batt_test=0;
	/*********************************************/
	
	//设置中断向量表的位置在 0x5000,即内部flash的前20K
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000);		


	
	
	SystemTick_Init();
	NVIC_Configuration();
		

	//按键初始化
	Init_Sw_Key_Io();
 	Exit_Line_Init();	



	EXTILine_Mask(EXTI_Line5);
	EXTILine_Mask(EXTI_Line8);	
	EXTILine_Mask(EXTI_Line15);	

	//长按开机,如果长按不够3m则继续保持关机状态,如果长按3m,则退出停机模式,开机
	WKUP_Init();		
	
	EXTILine_Unmask(EXTI_Line5);
	EXTILine_Unmask(EXTI_Line8);
	EXTILine_Unmask(EXTI_Line15);
	
	
	
  //如果没有进入停机模式,则开启显示
	OLED_WR_Byte(0xAF,OLED_CMD); //开启显示
	
	
  longpress=0;
	stop_flag=0;
	
	SPI_FLASH_Init();
	//正常运行后,显示logo
	OLED_Init();
	SPI_FLASH_Init();	
	
	
	OLED_Clear();	
	OLED_DrawBMP(32,2,48,4,hui);
	OLED_ShowUnite(48,2,"合科技");		
	//delay_ms(800);	




	
	USB_BIT_Init();
	
	//为降低功耗的控制位
	/****************************************/
	bluetooth_control_Init();

	max232_control_Init();

	oled_control_Init();
	OLED_ON;
	
	buzzer_control_Init();
	BUZZER_OFF;

	coil_control_Init();	
	COIL_NO_ACTUATE;
	/****************************************/
	
	





	Init_Timer();
	
	//实时时钟初始化
	RTC_init();
	
	//初始化并启动看门狗
	//iwdg_init();
	
	//串口1 USB初始化及配置
	Uart1_Init();
	USART1_Configuration();
	
	//串口2 RFID初始化及配置
	Uart2_Init();
	USART2_Configuration();	
	
	//串口3 bluetooth初始化及配置
	Uart3_Init();
	USART3_Configuration();	
	bluetooth_Configuration();	//蓝牙的EN和BRST配置
	CLR_BT_EN;	//开启蓝牙
	

	
	
	ADC_GPIO_Configuration();
	ADC_Configuration();
	

	
	//flash区域指针初始化
	//SPI_FLASH_WriteWord(INIT_FLAG,1);   //此次下载清flash
 	SPI_FLASH_WriteWord(INIT_FLAG,0);		  //此次下载不清flash
	
	if(SPI_FLASH_ReadWord(INIT_FLAG) ==0x01)		//当初始化标志等于1,就初始化POINT和ROW
	{
	  mykey_init();		//初始化钥匙操作的头指针 ---如何设定在什么情况下重新设置
	}	
	


	

	
// 	 OLED_ClearArea(0,4,128,6);	
// 	 OLED_ShowUnite(24,4,"初始化蓝牙");		
// 	 mac_query_result=bluetooth_mac();
	
	
	
	
	
	/*延时函数测试*/
	/**********************************************/
// 	GPIO_Configuration();
// 	while(1)
// 	{
// 		GPIO_SetBits(GPIOB,GPIO_Pin_0);
// 		delay_ms(1000);
// 		GPIO_ResetBits(GPIOB,GPIO_Pin_0);
// 		delay_ms(3000);	
// 	}
	/**********************************************/

	
	/*OLED测试*/
	/**********************************************/
//   while(1)
//   {
// 		OLED_Clear();
// 		OLED_ShowChinese(0,0,0);  //中
// 		OLED_ShowChinese(18,0,1); //景
// 		OLED_ShowChinese(36,0,2); //园
// 		OLED_ShowChinese(54,0,3); //电
// 		OLED_ShowChinese(72,0,4); //子
// 		OLED_ShowChinese(90,0,5); //科
// 		OLED_ShowChinese(108,0,6);//技
// 		OLED_ShowString(0,3,"1.3' OLED TEST");
// 		//OLED_ShowString(8,2,"ZHONGJINGYUAN");  
// 	  //OLED_ShowString(20,4,"2014/05/01");  
// 		OLED_ShowString(0,6,"ASCII:");  
// 		OLED_ShowString(63,6,"CODE:");  
// 		OLED_ShowChar(48,6,t);//显示ASCII字符	   
// 		t++;
// 		if(t>'~')
// 			t=' ';
// 		OLED_ShowNum(103,6,t,3,16);//显示ASCII字符的码值 	
// 			
//     delay_ms(8000);
//     //OLED_Clear();
// 		
// 		OLED_DrawBMP(0,0,128,8,BMP1);  //图片显示(图片显示慎用,生成的字表较大,会占用较多空间,FLASH空间8K以下慎用)
// 		delay_ms(800);
// 		
//     //OLED_Display_On();
//     //delay_ms(800);		
// 		
// 		OLED_DrawBMP(0,0,128,8,BMP2);
// 		delay_ms(800);	
// 		
//    //OLED_Display_Off();	
//    //delay_ms(800);				
//   }
	/**********************************************/
	
	
	
	
	/*OLED+字库测试*/
	/**********************************************/	
// 	phz="字库";
// 	hanzi[0]=*phz;
// 	hanzi[1]=*(phz+1);
// 	hanzi[2]=*(phz+2);
// 	hanzi[3]=*(phz+3);
// 	hanzi[4]=*(phz+4);	
// 	
// 	
// 	OLED_ShowChinese(0,0,"汉");
// 	OLED_ShowChinese(16,0,"字");
// 	
// 	OLED_ShowUnite(0,2,"你很不错");
// 	OLED_ShowUnite(0,4,"ABCDEF");		
// 	OLED_ShowUnite(0,6,"123456");		
	
	
	/**********************************************/	
	
/*
		STM32F103C8串口有3个
		串口1通过USB接充电器,与上位机PC通信
		串口2通过串口读RFID的数据
		串口3通过蓝牙与PDA通信
*/	
	
	
 	/*串口1 USB测试*/
	/**********************************************/
	
// 	while(1)
// 	{
// 		UART1nSendChar(1,"12345",5);
// 		delay_ms(1000);
// 	}
	//UART1nSendChar(1,usb_code,6);	
	
	//USB_Cheak_init();
	
	//Test_Usb_Data();


// 	UART1SendwordHex(1, 0x123456);

//   UART1nSendChar(1,"汉字",5);	

// 	while(1);
	
	/**********************************************/
	
	
	
	
 	/*串口2 RFID测试*/
	/**********************************************/
// 	while(1)
// 	{
// 			OLED_ShowUnite(32,2,"RFID");
// 			delay_ms(1000);	
// 			UART1nSendChar(1,"12345",5);
// 			//OLED_Clear();	    //清屏
// 			nChar =Read_RfidData(2,Rfid_Buff,0xff);
// 			m_UB2;
// 			if(nChar ==5) 
// 			{
// 				if(Rfid_Buff[0]==0&&Rfid_Buff[1]==0&&Rfid_Buff[2]==0&&Rfid_Buff[3]==0)
// 					;
// 				else		//至少有一个不为零
// 				{
// 					UART1nSendChar(1,Rfid_Buff,5);
// 					OLED_ShowNumHex(32,4,Rfid_Buff[0],2,16);
// 					OLED_ShowNumHex(48,4,Rfid_Buff[1],2,16);
// 					OLED_ShowNumHex(64,4,Rfid_Buff[2],2,16);
// 					OLED_ShowNumHex(80,4,Rfid_Buff[3],2,16);
// 					delay_ms(1000);						
// 					break;
// 				}
// 			}
// 	}
// 	while(1);		
	
	
	
	
	
	/**********************************************/	
	
	
	
	
 	/*串口3 bluetooth测试*/
	/**********************************************/
// 	CLR_BT_EN;
// 	CLR_BT_BRTS;
// 	
// 	while(1)
// 	{
// 		UART3nSendChar(3,"012345",6);
// 		delay_ms(1000);
// 	}
// 		while(1)
// 		{
// 			UART3nSendChar(3,"TTM:MAC-?",9);

// 			count=UART3GetCount(3);
// 			UART3nReadChar(3,char_buf,count);
// 			
// 			
// 			
// 			
// 			UART1nSendChar(1,char_buf,count);

// 			delay_ms(1000);
// 		}

	/**********************************************/	
	
	
	/*flash测试*/
	/**********************************************/	
	
	
//   SPI_FLASH_WriteWord(AUTHOR_ROW,0x456789);
// 	
// 	SPI_FLASH_BufferRead(flash_temp,AUTHOR_ROW,4);	
// 	
// 	flash_data=SPI_FLASH_ReadWord(AUTHOR_ROW);

// 	UART1nSendChar(1,flash_temp,4);	
//   
// 	OLED_ShowNum(0,6,flash_data,8,16);	
// 	
// 	//SPI_FLASH_WriteEnable();
//   status=SPI_FLASH_ReadStatusReg();
// 	OLED_ShowNum(112,6,status,1,16);	
	
//  SPI_FLASH_BulkErase();
	
// 	SPI_FLASH_BufferWrite("98765",0x100002,6);
// 	SPI_FLASH_BufferRead(p,0x100002,6);
	
	
// 	SPI_FLASH_Write("98765",0x1f0005,6);
// 	SPI_FLASH_Read(p,0x1f0005,6);	
// 	while(1)
// 	{
// 		UART1nSendChar(1,p,6);	
// 		delay_ms(1000);
// 	}
	
	/**********************************************/	
	


	//菜单测试
	/**********************************************/	
	
  //Main_Lcd_Show();   //主界面显示	
	//Main_Lcd_Show2();	
	
// 	mode=1;
// 	
// 	OLED_ShowChar(0,0,'A');
// 	
// 	OLED_ShowChinese(0,2,"我");
// 	
// 	OLED_ShowUnite(0,4,"你很不错");
// 	
// 	while(1);
// 	
// 	mode=0;
// 	delay_ms(1000);

	//ShowMenu(HsMenu);
	
	
// 	Choose_MenuOp1();

//  Choose_MenuOp4(); 

// 	Choose_MenuOp4_1();
//  Choose_MenuOp4_2();
// 	Choose_MenuOp4_22();
// 	Choose_MenuOp4_3();
// 	Choose_MenuOp4_4();

// 	Choose_MenuOp5();

// 	Choose_MenuOp5_1();
// 	Choose_MenuOp5_3();
// 	Choose_MenuOp5_4();	

// 		while(1)
// 		{
// 			Main_Oled_Time();	
// 			Main_Oled_Power();
// 			delay_ms(1000);
// 		}	

	

// 		while(1);
	/**********************************************/		
	
	
	
	
	
	//蜂鸣器测试
  /**********************************************/	
// 	while(1)
// 	{
// 		BUZZER_OFF;
// 		delay_ms(1000);
// 		
// 		BUZZER_ON;
// 		delay_ms(1500);	
// 	}
	
	/**********************************************/		
	
	
	
	
	
	//协议测试
	/**********************************************/	
	//OLED_Clear();
// 	OLED_ShowUnite(32,2,"通信中..");
// 	OLED_ShowUnite(0,4,"你很不错");
// 	delay_ms(1000);
// 	addr=0xFFFF;
// 	OLED_ShowNumHex(0,6,addr,8,16);
	
	//USB_Cheak_init();
  //USB_transmit();

//  		bluetooth_uart_switch=1;
// 		Test_Usb_Data();
//  		while(1);


	


//   SPI_FLASH_WriteWord(AUTHOR_POINT,AUTHOR_START);		

//   addr= SPI_FLASH_ReadWord(AUTHOR_POINT);   

//   OLED_ShowNum(0,0,addr,8,16);
	/**********************************************/	
	
	
	
	
	//ADC测试
	/**********************************************/		
	
// 	while(1)
// 	{
// 		OLED_Clear();
// 		batt_test=ADC_GetConversionValue(ADC1);
// 		OLED_ShowNum(24,2,batt_test,8,16);
// 		delay_ms(1000);
// 	}
// 	
	
	
	/**********************************************/		
	
	
	
	//定时器2测试
	/**********************************************/
	
	
// 	GPIO_Configuration();
// 	GPIO_ResetBits(GPIOB,GPIO_Pin_6);
// 	delay_ms(10);
// 	GPIO_SetBits(GPIOB,GPIO_Pin_6);
//   g_WaitTimeOut = 0;
//   SetTimer(TIMER_TIMEOUT,1,Do_TimeOut,THREE_MIN);
// 	while(g_WaitTimeOut == 0)
// 	{
// 		GPIO_ResetBits(GPIOB,GPIO_Pin_6);

// 	}	
//   KillTimer(TIMER_TIMEOUT);	
// 	GPIO_SetBits(GPIOB,GPIO_Pin_6);
	
//   g_WaitTimeOut = 0;
//   SetTimer(TIMER_TIMEOUT,10,Do_TimeOut,THREE_MIN);
// 	while(g_WaitTimeOut == 0)
// 	{
// 			nChar =Read_RfidData(2,Rfid_Buff,0xff);
// 			if(nChar ==5)
// 			{
// 					OLED_ShowUnite(32,80,Rfid_Buff);
// 					++rfidrow;
// 					delay_ms(1000);		
// 					for(i=0;i<4;i++)
// 					{
// 							for(k =0;k<40;k++)
// 								msDelay(500);
// 							WritEDAta(CAIMA_START+8*rfidrow+4+i,Rfid_Buff[i]);
// 					}				
// 					break;
// 			}

// 	}	
//   KillTimer(TIMER_TIMEOUT);		
	/**********************************************/	
	
	
	
	
	
	
	
// 	OLED_ClearArea(0,4,128,6);
// 	OLED_ShowUnite(24,4,"初始化完成");		
// 	delay_ms(100);
	
	
	//bluetooth_uart_switch=0;
// 	for(int iter=0;iter<3;iter++)
// 		Power_Cheak();	

  //主循环测试
	g_State=ST_IDLE;
	while(1)																					 
	{   
		switch (g_State)				//g_State是一个全局函数
		{
			
			 case ST_IDLE:    			//#define  ST_IDLE          0XFF
			 ST_Idle();		    			//空闲时做状态检测,可改变g_State
			 break;			
			
			 case ST_USB: 					//#define  ST_USB	          0XFD         
			 USB_transmit();				//USB传输
			 break;
			 	 
// 			 case ST_KEY:
// 			 Key_Trismit();  				//读钥匙的RFID,判断是否已经连接上
// 			 break;
			 
			 case ST_LCDMENU:   		//#define  ST_LCDMENU      0XFA			多选择菜单操作
			 Choose_MenuOp1();
			 break;
			 
			 default:break;

			}
	 }		
}
Пример #21
0
void init(void)
{
	SystemInit();
	//Setup SystickTimer
	if (SysTick_Config(SystemCoreClock / 1000)){ColorfulRingOfDeath();}

	GPIO_Configuration();

#ifdef USE_MICROUSB
	USBD_Init(&USB_OTG_dev,
	            USB_OTG_FS_CORE_ID,
	            &USR_desc,
	            &USBD_CDC_cb,
	            &USR_cb);
#endif

#ifdef USE_SDIO
	UB_Fatfs_Init();
#endif

#ifdef USE_ADC
	ADC_Configuration();
#endif

#ifdef USE_I2C
	I2C_Configuration();
#endif

#ifdef USE_SPI
	SPI_Configuration();
#endif

#ifdef USE_ENCODER
	TIM_encoder_Configuration();
#endif

#ifdef USE_USART1
	USART1_Configuration();
#endif

#ifdef USE_USART2
	USART2_Configuration();
#endif

#ifdef USE_USART3
	USART3_Configuration();
#endif

#ifdef USE_CAN
	CAN_Configuration();
#endif

#ifdef USE_PWM
	TIM_pwm_Configuration();
#endif

#ifdef USE_EXTI
	EXTI_Configuration();
#endif
	NVIC_Configuration();
}
Пример #22
0
int main(void)
{  	
	u8 i;
	u8 RecvBuf[32];
	u8 SendBuf[32];
	u8 offline = 0;
	u8 recv_flag = 0;
	u32 pd2ms=0,pd20ams=0,pd20bms=0,pd100ms=0;

	SystemInit();
	RCC_Configuration();
	NVIC_Configuration();
	GPIO_Configuration();
	
	USART1_Configuration();
	dbgPrintf(" Init Ticktack !\r\n");
	cycleCounterInit();
	SysTick_Config(SystemCoreClock / 1000);	
	for(i=0;i<2;i++)
	{
		OP_LED1;OP_LED2;OP_LED3;OP_LED4;
		delay_ms(500);
		OP_LED1;OP_LED2;OP_LED3;OP_LED4;
		delay_ms(500);
	}
	FilterInit();
	controllerInit();

	dbgPrintf(" Init eeprom!\r\n");
	FLASH_Unlock();	
	EE_Init();
	EE_Read_ACC_GYRO_Offset();
	/* 如果PID丢失或者错误,将下面两行注释去掉,重新编译烧写,运行一遍,可将PID还原,然后重新注释,再烧写一遍 */
	//EE_Write_PID();
	//EE_Write_Rate_PID();
	EE_Read_PID();
	EE_Read_Rate_PID();

	dbgPrintf(" Init adc!\r\n");
	ADC_DMA_Init();

	dbgPrintf(" Init NRF24L01 !\r\n");
	SPI_NRF_Init();	
	Nrf24l01_Init();
	NRF24l01_SetRxMode();
	
	while(Nrf24l01_Check())	
	{
		dbgPrintf("NRF24L01 Fault !\r\n");
		delay_ms(500);
	}
	dbgPrintf("NRF24L01 Is Detected !\r\n");

	dbgPrintf("Init MPU6050...\r\n");
	IIC_Init();
	MPU6050_initialize();


	dbgPrintf("Init Motor...\r\n");
	Motor_Init();
	Motor_SetPwm(0,0,0,0);


	pd20bms = TIMIRQCNT + 10*ITS_PER_MS;
	while(1)
	{
		if(TIMIRQCNT>pd2ms + 2*ITS_PER_MS-1)	// every 4ms
		{
			GetEulerAngle();
			if(lock_flag==UNLOCK) 
				AttitudeToMotors(angle.y,angle.x,angle.z);
			else
			{
				MOTOR1=0;	 			
				MOTOR2=0;				
				MOTOR3=0;				
				MOTOR4=0;				
			}
			Motor_SetPwm(MOTOR1,MOTOR2,MOTOR3,MOTOR4);
			pd2ms = TIMIRQCNT;
		}
		
		if(TIMIRQCNT>pd20ams + 20*ITS_PER_MS-1)	// every 20ms
		{
				if(NRF24l01_Recv(RecvBuf)>10)
				{
						if((RecvBuf[RecvBuf[2]+3]==CheckSum(RecvBuf, RecvBuf[2]+3))&&(RecvBuf[0]==0xAA))
						{
								if(RecvBuf[1]!=0xC0)		
									OP_LED1;		
								offline=0;
								switch(RecvBuf[1])
								{
										case 0xC0:  //control
												Getdesireddata(RecvBuf);
												OP_LED2;
												break;
										case 0x10:  //W PID
												SetPID(RecvBuf);
												break;
										case 0x11:  //W Attitude
												SetAccGyroOffset(RecvBuf);
												break;
										case 0x12:  //W Control offset
												break;
										case 0x14:  //W Rate PID
												SetRatePID(RecvBuf);
												break;
										case 0x20:  //R PID
												recv_flag = RESEND;
												GetPID(SendBuf);
												break;
										case 0x21:  //R Attitude
												recv_flag = RESEND;
												GetAccGyroOffset(SendBuf);
												break;
										case 0x22:  //R Control offset
												break;
										case 0x24:  //R Rate PID
												recv_flag = RESEND;
												GetRatePID(SendBuf);
												break;
										case 0x40:	//校准姿态
												EnableCalibration();
												break;
										case 0x41:	//校准遥控器零点												
												break;
									 default:
												break;
								}
						}
				}
				pd20ams = TIMIRQCNT;
		}
		if(TIMIRQCNT>pd20bms + 20*ITS_PER_MS-1)	// every 20ms
		{
			if(recv_flag==0)
         		GetState(SendBuf);
      		else
         		recv_flag--;
			NRF_SendData(SendBuf);
			OP_LED3;
			pd20bms = TIMIRQCNT;
		}
		
		if(TIMIRQCNT>pd100ms + 100*ITS_PER_MS-1)	// every 100ms
		{
			if(offline>20)
				lock_flag = LOCK;
			offline++;
//			OP_LED4;
			pd100ms = TIMIRQCNT;
		}
	}
}
Пример #23
0
/*******************************************************************************
* Function Name  : USART_Configuration
* Description    : Configures the USART1.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void USART_Configuration(void)
{
	USART1_Configuration();
	USART2_300_7E1();
}
Пример #24
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
    /* Periph clock enable */
    RCC_Configuration();

    /* Config the LED GPIO */
    LED_Configuration();

    /* Config the USART1 */
    USART1_Configuration();

    printf("NOR Flash Init!\n\r");

    /* EXMC nor flash init */
    EXMC_NorFlash_Init();

    /* Read Nor Flash ID and printf */
    NOR_ReadID(&NOR_ID);
    printf("\n\rNor Flash ID:0x%X 0x%X 0x%X 0x%X\n\r",NOR_ID.Manufacturer_Code,NOR_ID.Device_Code,
                                                      NOR_ID.Block_Protection_Indicator,NOR_ID.Block_Protection_Status);

    NOR_ReturnToReadMode();

    /* Erase the nor flash block to be written data */
    Status = NOR_EraseBlock(WRITE_READ_ADDR);
    if(NOR_SUCCESS == Status)
    {
        printf("\n\rErase nor flash block successfully!\n\r");
    }
    else
    {
        printf("\n\rErase nor flash block failure!\n\r");
    }

    /* Whether address cross-border */
    if((WRITE_READ_ADDR + BUFFER_SIZE ) > NOR_MAX_ADDRESS)
    {
        printf("\n\rAddress cross-border\n\r");
        GPIO_SetBits(LED_GPIO, LED4_PIN | LED5_PIN);
        while(1)
        {

        }
    }

    /* Fill WriteBuffer with the specified value */
    Fill_Buffer(WriteBuffer, BUFFER_SIZE, 0x1234);

    /* Write data to nor flash, WRITE_READ_ADDR: the starting address of the write data */
    Status = NOR_WriteBuffer(WriteBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
    if(NOR_SUCCESS == Status)
    {
        printf("\n\rWrite data to nor flash block successfully!\n\r");
    }
    else
    {
        printf("\n\rWrite data to nor flash block failure!\n\r");
    }

    /* Read data from nor flash, WRITE_READ_ADDR: the starting address of the read data*/
    NOR_ReadBuffer(ReadBuffer, WRITE_READ_ADDR, BUFFER_SIZE);

    /* Read and write data comparison for equality */
    WriteReadStatus = 0;
    for (Index = 0x00; Index < BUFFER_SIZE; Index++)
    {
        if (ReadBuffer[Index] != WriteBuffer[Index])
        {
            WriteReadStatus++;
            break;
        }
    }

    printf("\n\rThe result to access the nor flash:\n\r");
    if (WriteReadStatus == 0)
    {
         printf("\n\rAccess nor flash successfully!\n\r");
         GPIO_SetBits(LED_GPIO, LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN);
    }
    else
    { 
         printf("\n\rAccess nor flash failure!\n\r"); 
         GPIO_SetBits(LED_GPIO, LED2_PIN | LED3_PIN);
    }

    printf("\n\rPrintf data to be read: \n\r");
    printf("\n\r");
    for(Index = 0; Index < BUFFER_SIZE; Index++)
    {
        printf("%X ",ReadBuffer[Index]);
    }

    while(1)
    {

    }
}