Exemple #1
0
int main(void)
{

  char lcd_text_main[100];

    lcd_init();
    lcd_drawBackground(20,60,250);
    lcd_drawBGPersimmon(20, 60, 250);
    LCD_SetColors(LCD_COLOR_WHITE-1,LCD_COLOR_WHITE);

    LCD_SetFont(&Font8x12); 

    terminalBufferInitilization();

    /* Begin timer period capture example */


    TIM2_Initialization();

    terminalWrite("Welcome to our termainal .\n");     Delay_1us(1000000);
  while (1){


     sprintf(lcd_text_main,"\nPeriod = %ld us",timebaseCapture_output);
     terminalWrite(lcd_text_main); 
     Delay_1us(10000);
  }  
}
Exemple #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);
  }
  
}
Exemple #3
0
void Delay_Nus(u16 Cnt)
{
  while (Cnt--)
  {
    Delay_1us();
  }  
}
Exemple #4
0
void IMU_Initialization(){
  // receivedData = readSPI4(0x75); //75 WHO_AM_I
  // sprintf(lcd_text_main,"My Name is : %d    \n", receivedData); terminalWrite(lcd_text_main);
  // Delay_1us(500000);

  writeSPI4(0x6B,0x80); //PWR_MGMT_1   
  Delay_1us(100000);
  writeSPI4(0x6B,0x03); //PWR_MGMT_1   
  //writeSPI4(0x1A,0x02); //CONFIG
  writeSPI4(0x1B,0x18); //GYRO_CONFIG  

  // receivedData = readSPI4(0x6B);
  // sprintf(lcd_text_main,"PWR_MGMT_1 : %X    \n", receivedData); terminalWrite(lcd_text_main);
  // Delay_1us(100000);

  // receivedData = readSPI4(0x1A);
  // sprintf(lcd_text_main,"CONFIG : %X    \n", receivedData); terminalWrite(lcd_text_main);
  // Delay_1us(100000);

  // receivedData = readSPI4(0x1B);
  // sprintf(lcd_text_main,"GYRO_CONFIG : %X    \n", receivedData); terminalWrite(lcd_text_main);
  // Delay_1us(100000);

  EstV.G.X = 0.0; //pitch
  EstV.G.Y = 0.0; //roll 0
  EstV.G.Z = -1.0; //yaw 1
}
/*=====================================================================================================*/
int main( void )
{
  u32 i = PWM_MOTOR_MIN;

  SystemInit();
  GPIO_Config();
  PWM_Config();

  while(1) {
    LED_G = ~LED_G;

    while(KEY_WU == 1) {
      PWM1  = i;
      PWM2  = i;
      PWM3  = i;
      PWM4  = i;
      PWM5  = i;
      PWM6  = i;
      PWM7  = i;
      PWM8  = i;
      PWM9  = i;
      PWM10 = i;
      PWM11 = i;
      i++;
      if(i>=PWM_MOTOR_MAX) {
        i = PWM_MOTOR_MIN;
        LED_R = ~LED_R;
      }
      Delay_1us(500);
    }

    Delay_10ms(10);
  }
}
/******************************************************************************
* Function Definitions
*******************************************************************************/
static void cs_low()
{
#ifdef __GNUC__
    printf( "CS_LOW\n" );
#else
    MAGNETO_CS = 0;
    Delay_1us();  // tL Time between CS falling edge and CLK rising edge 350ns
#endif
}
Exemple #7
0
/*引脚初始化*/
void Rest(void)
{
	LPC_GPIO2->FIODIR |= (1<<0);			//复位脚设置成输出
	LPC_GPIO2->FIODIR |= (1<<7);  			//数据脚设置成输出
	LPC_GPIO2->FIOPIN &= ~(1<<0); 			//复位脚拉低
 
	Delay_1us(100); 
	LPC_GPIO2->FIOPIN |= (1<<7);			 //数据较保持高电平 
	LPC_GPIO2->FIOPIN |= (1<<0);			 //复位脚拉高
}
static void cs_high()
{
#ifdef __GNUC__
    printf( "CS_HIGH\n" );
#else
    //Delay_1us();  // tH Time between last falling edge of CLK and rising edge of CS 50ns
    MAGNETO_CS = 1;
    Delay_1us();  // TcsnH High time of CS bwtween two transmissions 350ns
#endif
}
Exemple #9
0
/*=====================================================================================================*/
void LED_PWM( u8 LED_Mode , u16 LED_Sel, u16 LED_DelayTime )
{
    u16 i = 0;

    if(LED_Mode == LED_ON) {
        for(i=LED_PWM_Min; i<LED_PWM_Max-10; i=i+2) {
            if((LED_Sel&0x01) == 0x01)	LED5 = i;
            if((LED_Sel&0x02) == 0x02)	LED6 = i;
            if((LED_Sel&0x04) == 0x04)	LED7 = i;
            if((LED_Sel&0x08) == 0x08)	LED8 = i;
            Delay_1us(LED_DelayTime);
        }
    }
    else {
        for(i=LED_PWM_Max; i>LED_PWM_Min+10; i=i-2) {
            if((LED_Sel&0x01) == 0x01)	LED5 = i;
            if((LED_Sel&0x02) == 0x02)	LED6 = i;
            if((LED_Sel&0x04) == 0x04)	LED7 = i;
            if((LED_Sel&0x08) == 0x08)	LED8 = i;
            Delay_1us(LED_DelayTime);
        }
    }
}
/*=====================================================================================================*/
void nRF_TX_Mode(void)
{
	NRF_CE = 0;
	nRF_WriteBuf(NRF_WRITE + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);  // 寫TX節點地址
	nRF_WriteBuf(NRF_WRITE + RX_ADDR_P0, RX_ADDRESS, RX_ADR_WIDTH); // 設置TX節點地址, 主要為了使能ACK
	nRF_WriteReg(NRF_WRITE + EN_AA, 0x01);    // 使能通道0的自動應答
	nRF_WriteReg(NRF_WRITE + EN_RXADDR, 0x01); // 使能通道0的接收地址
	nRF_WriteReg(NRF_WRITE + SETUP_RETR, 0x05); // 設置自動重發間隔時間:250us + 86us;最大自動重發次數:5次
	nRF_WriteReg(NRF_WRITE + RF_CH, CHANAL);  // 設置RF通道為CHANAL
	nRF_WriteReg(NRF_WRITE + RF_SETUP, 0x0f); // 設置TX發射參數,0db增益,2Mbps,低噪聲增益開啟
	nRF_WriteReg(NRF_WRITE + CONFIG, 0x0e);   // 配置基本工作模式的參數;PWR_UP,EN_CRC,16BIT_CRC,發射模式,開啟所有中斷
	NRF_CE = 1;

	Delay_1us(12); // CE要拉高一段時間才進入發送模式
}
Exemple #11
0
/***********************************************
函数名称:sFLASH_SendByte
功    能:向W25Q64 FLASH发送一个字节数据。
入口参数:dat:发送的数据
返 回 值:无	
备    注:无
************************************************/
void sFLASH_SendByte(unsigned char dat)
{
unsigned char i;	       //定义计数器
//送出数据
for(i=0;i<8;i++)		 	
{	W25Q64_WCK_Clr();
//先发送高字节
if( (dat&0x80)==0x80 )
{W25Q64_WDI_Set();}
else
{W25Q64_WDI_Clr();}
 Delay_1us();	
W25Q64_WCK_Set();
//数据左移
	dat<<=1;								
}  
}
Exemple #12
0
/***********************************************
函数名称:sFLASH_ReadByte
功    能:从W25Q64 FLASH读取一个字节数据。
入口参数:无
返 回 值:unsigned char:读出的数据。	
备    注:无
************************************************/
unsigned char sFLASH_ReadByte(void)
{
unsigned char i;
unsigned char dat = 0;
W25Q64_WDO_Set();
W25Q64_WCK_Clr();
for (i=0; i<8; i++)             //8位计数器
{W25Q64_WCK_Set();           //时钟线拉高
Delay_1us();
dat <<= 1;	                //数据右移一位
if (WDO) 
{dat |= 0x01;            //读取数据
}
W25Q64_WCK_Clr();           //时钟线拉低
}
return dat;
}
Exemple #13
0
//硬复位MP3
//返回1:复位失败;0:复位成功	   
u8 VS_HD_Reset(void) {
	u8 retry = 0;
	VS_RST_LOW;
	Delay_1ms(20);
	VS_XDCS_HIGH; //取消数据传输
	VS_XCS_HIGH; //取消数据传输
	VS_RST_HIGH;
	while (VS_DREQ_STATE == 0 && retry < 200) //等待DREQ为高
	{
		retry++;
		Delay_1us(50);
	};
	Delay_1ms(20);
	if (retry >= 200)
		return 1;
	else
		return 0;
}
Exemple #14
0
void LCD_init(void)      //
{
    LCD_GPIO_Init();
#if 1
    Delay_1ms(20);
    w_4bit_INIT_LCD1602(0x30);     //写第一次0x3N命令(N为任意值)
    Delay_1ms(10);       //至少延迟4.1ms
    w_4bit_INIT_LCD1602(0x30);    //写第二次0x3N命令(N为任意值)
    Delay_1us(200);       //至少延迟100us
    w_4bit_INIT_LCD1602(0x30);    //写第三次0x3N命令(N为任意值)
    Delay_1us(100);       //至少延迟40us
    w_4bit_INIT_LCD1602(0x20);    //设置为4位模式
    Delay_1us(100);        //至少延迟40us
    LCD_write_command(0x28);      //设置为4位模式,2行字符,5 x 7点阵/每字符
    Delay_1us(100);       //至少延迟40us
    LCD_write_command(0x06);     //写入新数据后光标右移,写入新数据后显示屏不移动
    Delay_1us(100);       //至少延迟40us
    LCD_write_command(0x0e);     //显示功能开,有光标,光标不闪烁
    Delay_1us(100);       //至少延迟40us
    LCD_write_command(0x01);     //清除液晶显示器
    Delay_1ms(10);          //至少延迟1.64ms
    GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN);
    Delay_1ms(10);
#else
    LCD_write_command(0x33);
    Delay_1ms(5);

    LCD_write_command(0x28);
    Delay_1ms(5);

    LCD_write_command(0x28);
    Delay_1ms(5);

    LCD_write_command(0x28);
    Delay_1ms(5);

    LCD_en_write();
    Delay_1ms(5);

    LCD_write_command(0x28); //4
    Delay_1ms(5);

    LCD_write_command(0x0c); //    显示开
    Delay_1ms(5);

    LCD_write_command(0x01); //    清屏
    Delay_1ms(5);

    GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN);
#endif
}
Exemple #15
0
/*发送命令函数:参数H = 1 为高速,H = 0 为低速 ; m 为接收字节的个数*/
void ReceArt(char H,char m)	   		   		   
{
	unsigned char i,n;
	unsigned char cIO;
	LPC_GPIO2->FIODIR = 0x0000007f;// io口为输入
	for(n=0;n<m;n++)
	{	
		while(LPC_GPIO2->FIOPIN & (1<<7));
		cIO = 0x00;
		if(H == 1)				   //H = 1 时为高速通讯
		{
			Delay_1us(1);	
		}
		else if(H == 0)			   //H = 0 时为低速通讯
		{
			Delay_1us(30);
		}
		for(i=0;i<8;i++)   		   //读一个字节函数 
		{
			if(H == 1)			   //H = 1 时为高速通讯每位时间
			{
				Delay_1us(4);
			}
			else if(H == 0)			//H = 0 时为高速通讯每位时间
			{
				Delay_1us(100);
			} 
			cIO >>= 1;
			if(LPC_GPIO2->FIOPIN & (1<<7))
			{
				cIO |= 0x80;
			}
		}
		buf[n] =cIO;
		if(H == 1)
		{
			Delay_1us(12);	
		}
		else if(H == 0)
		{
			Delay_1us(100);
			Delay_1us(200);
		}	
	}
}
Exemple #16
0
int main(void)
{
  
    RCC_Configuration();
    LED_Initialization();     //PG13 (GREEN) & PG14 (RED)
    USART1_Initialization();  //PA9 (TX) & PA10 (RX)
    SPI1_Initialization();    //PB3 (SCK) & PB4 (MISO) & PB5 (MOSI)
    Delay_1us(1000000);
    NRF2401_Initialization();
    Timer2_Initialization();

    // LED3_On();
    USART1_puts("\r\nHello World\r\n");
    // Delay_1us(500000);
    // LED3_Off();
    // Delay_1us(500000);    

    while(1)
    {
      if(task == 1){
        LED4_Toggle();

        /* NRF2401 TX Mode */
        NRF2401_SendData_1CH("KU");

        /* NRF2401 RX Mode */
        // uint8_t i;
        // for(i = 0; i < 24; i++){
        //   receivedData = NRF2401_ReceiveData_1CH()[i];
        //   USART_SendData(USART1, receivedData);
        // }
        // USART1_puts("\r\n");

        // NRF2401_ReceiveData_1CH();
        task = 0;
      }
    }

    while(1); // Don't want to exit
}
Exemple #17
0
/*发送命令函数:参数H = 1 为高速,H = 0 为低速 ; m 为发送字节的个数 ; SendBuf[]发送命令数组*/
void SendChar(char H,char m,char SendBuf[])
{
    char i,n,flag,uChar;

	 LPC_GPIO2->FIODIR = 0x000000ff;	 //设置成输出
	 
	for(n = 0 ;n<m ; n++)
	{	
		uChar  = SendBuf[n] ;
		flag = 0; 
		LPC_GPIO2->FIOPIN &= ~(1<<7);
		for(i=0;i<8;i++)			   //发送一个字节
		{
			if(H == 1)
			{
				Delay_1us(4);	
			}
			else if(H == 0)
			{
				Delay_1us(103);
			}	
			
			if(uChar & 0x01)
			{
				LPC_GPIO2->FIOPIN |= (1<<7);   //用于判断偶校验位
			    flag++;
			}
			else
			{
				LPC_GPIO2->FIOPIN &= ~(1<<7);
			}
			uChar >>=1;
		}

		if(H == 1)
		{
			Delay_1us(4);		
		}
		else if(H == 0)
		{
				Delay_1us(100);
		}

		if(flag%2 == 1)								//判断校验位
		{
			LPC_GPIO2->FIOPIN |= (1<<7);
		}
		else
		{
			LPC_GPIO2->FIOPIN &= ~(1<<7);
		}
		if(H == 1)									 //延时一个校验位
		{
			Delay_1us(4);	
		}
		else if(H == 0)
		{
			Delay_1us(100);
		}	
		LPC_GPIO2->FIOPIN |= (1<<7);				//延时两个停止位
		if(H == 1)
		{
			Delay_1us(8);	
		}
		else if(H == 0)
		{
			Delay_1us(200);
		}		   		
	}
}
Exemple #18
0
int main(void)
{

            CanTxMsg TxMessage;
  float X_offset =0.0f,Y_offset =0.0f,Z_offset =0.0f;
  float test_float=0.0f; uint8_t test_int=0;
  float GyX =0.0f, GyY =0.0f, GyZ =0.0f;
  float GyX_prev=0.0f,GyY_prev=0.0f,GyZ_prev=0.0f;
      uint16_t x_len=240;
      uint16_t y_len=320;

      uint16_t i=0;
      uint16_t buffer_screen[x_len][y_len];

      /* For gyro receiving  */
     float receivedGyro1=0,receivedGyro1_prev=0;
     float receivedGyro2=0,receivedGyro2_prev=0;
     float receivedGyro3=0,receivedGyro3_prev=0;
     uint8_t *ptr = & receivedGyro1;


      // uint16_t *buf_ptr = &buffer_screen;
      float runner=-8.0;

      rectangular_t rect1;
      rectangular_t prev_rect;
      rectangular_t rect_screen;


    char lcd_text_main[100];

    /* LCD Initialization */
    lcd_init();
    lcd_drawBackground(20,60,250);
    //lcd_drawBGPersimmon(20, 60, 250);



    /* LED Initialization */
    LED_Initialization();

    /* CAN Initialization */
    CAN2_Config();
    CAN2_NVIC_Config();

    /* MEMS Initialization */
    Demo_GyroConfig();

    Delay_1us(10000);
      #define CALIBRATE_COUNT 1000
      for (i=0;i<CALIBRATE_COUNT ;i++){
        Demo_GyroReadAngRate (Buffer);
        X_offset+= Buffer[0];
        Y_offset+= Buffer[1];
        Z_offset+= Buffer[2];
      }

      X_offset = X_offset/ (float)CALIBRATE_COUNT;
      Y_offset = Y_offset/ (float)CALIBRATE_COUNT;
      Z_offset = Z_offset/ (float)CALIBRATE_COUNT;


        rect_screen.xlen = x_len;
        rect_screen.ylen = y_len;
        rect_screen.xpos = 0;
        rect_screen.ypos = 0;

        #define NEEDLE_RADIUS 65
        #define NEEDLE_BASE_WIDTH 14
        #define NEEDLE_FRAME_THICKNESS 5
        
        #define NEEDLE1_CENTER_X 80
        #define NEEDLE1_CENTER_Y 100

        #define NEEDLE2_CENTER_X 80
        #define NEEDLE2_CENTER_Y 200

        #define NEEDLE3_CENTER_X 80
        #define NEEDLE3_CENTER_Y 300

        /* Drawing Needle frame 1 */
        LCD_SetLayer(LCD_BACKGROUND_LAYER);

        DrawThickCircle(NEEDLE1_CENTER_X ,NEEDLE1_CENTER_Y,NEEDLE_RADIUS+NEEDLE_FRAME_THICKNESS, 4,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
       
        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        DrawThickCircle(NEEDLE1_CENTER_X ,NEEDLE1_CENTER_Y,NEEDLE_BASE_WIDTH, 6,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        
        LCD_SetLayer(LCD_BACKGROUND_LAYER);
        LCD_SetColors(ASSEMBLE_RGB(20, 60, 250),LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE1_CENTER_X- NEEDLE_RADIUS-NEEDLE_FRAME_THICKNESS*2,NEEDLE1_CENTER_Y+ NEEDLE_BASE_WIDTH+3,NEEDLE_RADIUS*2+NEEDLE_FRAME_THICKNESS*4,NEEDLE_RADIUS);

        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE1_CENTER_X- NEEDLE_RADIUS,NEEDLE1_CENTER_Y+ NEEDLE_BASE_WIDTH,NEEDLE_RADIUS*2,NEEDLE_FRAME_THICKNESS-1);

        /* Drawing Needle frame 2 */
        LCD_SetLayer(LCD_BACKGROUND_LAYER);

        DrawThickCircle(NEEDLE2_CENTER_X ,NEEDLE2_CENTER_Y,NEEDLE_RADIUS+NEEDLE_FRAME_THICKNESS, 4,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
       
        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        DrawThickCircle(NEEDLE2_CENTER_X ,NEEDLE2_CENTER_Y,NEEDLE_BASE_WIDTH, 6,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        
        LCD_SetLayer(LCD_BACKGROUND_LAYER);
        LCD_SetColors(ASSEMBLE_RGB(20, 60, 250),LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE2_CENTER_X- NEEDLE_RADIUS-NEEDLE_FRAME_THICKNESS*2,NEEDLE2_CENTER_Y+ NEEDLE_BASE_WIDTH+3,NEEDLE_RADIUS*2+NEEDLE_FRAME_THICKNESS*4,NEEDLE_RADIUS);

        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE2_CENTER_X- NEEDLE_RADIUS,NEEDLE2_CENTER_Y+ NEEDLE_BASE_WIDTH,NEEDLE_RADIUS*2,NEEDLE_FRAME_THICKNESS-1);


        /* Drawing Needle frame 2 */
        LCD_SetLayer(LCD_BACKGROUND_LAYER);

        DrawThickCircle(NEEDLE3_CENTER_X ,NEEDLE3_CENTER_Y,NEEDLE_RADIUS+NEEDLE_FRAME_THICKNESS, 4,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
       
        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        DrawThickCircle(NEEDLE3_CENTER_X ,NEEDLE3_CENTER_Y,NEEDLE_BASE_WIDTH, 6,LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        
        LCD_SetLayer(LCD_BACKGROUND_LAYER);
        LCD_SetColors(ASSEMBLE_RGB(20, 60, 250),LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE3_CENTER_X- NEEDLE_RADIUS-NEEDLE_FRAME_THICKNESS*2,NEEDLE3_CENTER_Y+ NEEDLE_BASE_WIDTH+3,NEEDLE_RADIUS*2+NEEDLE_FRAME_THICKNESS*4,NEEDLE_RADIUS);

        LCD_SetLayer(LCD_FOREGROUND_LAYER);

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_BLACK);
        LCD_DrawFullRect(NEEDLE3_CENTER_X- NEEDLE_RADIUS,NEEDLE3_CENTER_Y+ NEEDLE_BASE_WIDTH,NEEDLE_RADIUS*2,NEEDLE_FRAME_THICKNESS-1);

        /* Clear drawing buffer */
        PadRectangular(&buffer_screen,x_len,y_len,LCD_COLOR_WHITE, &rect_screen);




      while(1)
      {

        board_ID = PIN_ID_Read();

        LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
        sprintf(lcd_text_main," CAN Demo ID:%d    ",board_ID);
        LCD_DisplayStringLine(LINE(0), (uint8_t*)lcd_text_main);

        Demo_GyroReadAngRate (Buffer);

        //Delay_1us(1000);

        /* MEMS Filtering */
        #define LP_ALPHA 0.1f
        GyX = GyX*(1.0f - LP_ALPHA) + (Buffer[0] - X_offset)*LP_ALPHA;
        GyY = GyY*(1.0f - LP_ALPHA) + (Buffer[1] - Y_offset)*LP_ALPHA;
        GyZ = GyZ*(1.0f - LP_ALPHA) + (Buffer[2] - Z_offset)*LP_ALPHA;

        if(GyX >  90.0f)  GyX =  90.0f;
        if(GyX < -90.0f)  GyX = -90.0f;
        if(GyY >  90.0f)  GyY =  90.0f;
        if(GyY <  -90.0f) GyY = -90.0f;
        if(GyZ >  90.0f)  GyZ =  90.0f;
        if(GyZ < -90.0f)  GyZ = -90.0f;

        /* Start drawing rectangular */
        prev_rect = rect1;

        rect1.xlen = 25;
        rect1.ylen = 30;
        rect1.xpos = x_len/2+ (int16_t)(GyY)-10;
        rect1.ypos = y_len/2 + (int16_t)(GyX)-10;


        if(board_ID == 1){


          MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_GREEN,NEEDLE1_CENTER_X,NEEDLE1_CENTER_Y,-GyZ,-GyZ_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);

        }else if(board_ID == 2){

          MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_GREEN,NEEDLE2_CENTER_X,NEEDLE2_CENTER_Y,-GyZ,-GyZ_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);

        }else {

          MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_GREEN,NEEDLE3_CENTER_X,NEEDLE3_CENTER_Y,-GyZ,-GyZ_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);

        }

            CAN2_TransmitGyro(board_ID,GyZ);

            /* Received Data */
            if( can2_rx_isr_flag ==1){

              do{

            if( can2_rx_isr_flag ==1){
                  can2RxMessage = CAN2_PassRXMessage();
                  can2_rx_isr_flag=0;
                }else{

                  CAN_Receive(CAN2, CAN_FIFO0, &can2RxMessage);
                }
                  GPIO_ToggleBits(GPIOG,GPIO_Pin_14);

                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];


                    if(( can2RxMessage.ExtId &   0x0000FFFF) == 1){
                        ptr = & receivedGyro1;
                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];


                        MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_RED,NEEDLE1_CENTER_X,NEEDLE1_CENTER_Y,-receivedGyro1,-receivedGyro1_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);
                        
                    receivedGyro1_prev = receivedGyro1;
                    }else if (( can2RxMessage.ExtId & 0x0000FFFF) == 2){
                        ptr = & receivedGyro2;
                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];
                        MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_RED,NEEDLE2_CENTER_X,NEEDLE2_CENTER_Y,-receivedGyro2,-receivedGyro2_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);
                        
                    receivedGyro2_prev = receivedGyro2;
                    }else if (( can2RxMessage.ExtId & 0x0000FFFF) == 3){
                        ptr = & receivedGyro3;
                    ptr[0] = can2RxMessage.Data[0];
                    ptr[1] = can2RxMessage.Data[1];
                    ptr[2] = can2RxMessage.Data[2];
                    ptr[3] = can2RxMessage.Data[3];
                        MoveNeedle(LCD_BACKGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_RED,NEEDLE3_CENTER_X,NEEDLE3_CENTER_Y,-receivedGyro3,-receivedGyro3_prev,NEEDLE_RADIUS,NEEDLE_BASE_WIDTH);
                        
                    receivedGyro3_prev = receivedGyro3;
                    }
                  // LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
                  // sprintf(lcd_text_main," ID :%d         ", can2RxMessage.StdId);
                  // LCD_DisplayStringLine(LINE(1), (uint8_t*)lcd_text_main);
                  // LCD_SetColors(LCD_COLOR_BLACK,LCD_COLOR_WHITE-1);
                  // sprintf(lcd_text_main," Data :%f        ", receivedGyro);
                  // LCD_DisplayStringLine(LINE(2), (uint8_t*)lcd_text_main);
                }while(CAN_MessagePending(CAN2, CAN_FIFO0) > 0);



            }



          // {
          //   uint8_t status=0;



          //   while(CAN_TransmitStatus(CAN2, 0) != CAN_TxStatus_Ok ){

          //     status = CAN_TransmitStatus(CAN2, 0);
          //        if(status == CAN_TxStatus_Failed){

          //         GPIO_ToggleBits(GPIOG,GPIO_Pin_14);


          //        }
          //  }

          // }
            // TxMessage.StdId = (uint32_t)board_ID;
            // TxMessage.RTR = CAN_RTR_DATA;
            // TxMessage.IDE = CAN_ID_STD;
            // TxMessage.DLC = 8;
            // TxMessage.Data[0] = 0x01;
            // TxMessage.Data[1] = 0x01;
            // TxMessage.Data[2] = 0x01;
            // TxMessage.Data[3] = 0x01;
            // TxMessage.Data[4] = 0x01;
            // TxMessage.Data[5] = 0x01;
            // TxMessage.Data[6] = 0x01;
            // TxMessage.Data[7] = 0x01;
            // CAN_Transmit(CAN2, &TxMessage);

        //CAN2_TransmitGyro(test_int++,test_float);

        test_float += 0.1f;

        GyX_prev = GyX;
        GyZ_prev = GyZ;
        GyY_prev = GyY;

        runner += 1.0f;


        /* Faster method */
        //MoveAndUpdateRectangular(LCD_FOREGROUND_LAYER,&buffer_screen,x_len,y_len,LCD_COLOR_BLACK,&prev_rect, &rect1);
        
        /* Regular method */
        // PadRectangular(&buffer_screen,x_len,y_len,LCD_COLOR_WHITE, &prev_rect);
        // PadRectangular(&buffer_screen,x_len,y_len,LCD_COLOR_BLACK, &rect1);
         //DrawBufferToScreen(LCD_FOREGROUND_LAYER,buf_ptr,0,0, x_len,y_len);

      }

    
  
}
Exemple #19
0
int main(void)
{
    RCC_Configuration();
    GPIO_Configuration();
    LED_Initialization();
    uint8_t i=1,c=1;
    while(1)
    {

      //sevro
      if(PushButton_Read())
      {
        if(c==1)
        {
          c=0;
          if(PushButton_Read())
          {
            if(i==1)
            {
              i=2;
            }
            else if(i==2)
            {
              i=3;
            }
            else
            {
              i=1;
            }
          }
        }
      }
      if(PushButton_Read())
      {
        c=0;
      }
      else
      {
        c=1;
      }
      

      //
        if(i==1)
        {
          v13_on();
          v14_on();
          v15_on();
          Delay_1us(1000);
          v13_off();
          Delay_1us(500);
          v14_off();
          Delay_1us(500);
          v15_off();
          Delay_1us(18500);
        }
        if(i==2)
        {
          v13_on();
          v14_on();
          v15_on();
          Delay_1us(1000);
          v14_off();
          Delay_1us(500);
          v15_off();
          Delay_1us(500);
          v13_off();
          Delay_1us(18500);
        }
        if(i==3)
        {
          v13_on();
          v14_on();
          v15_on();
          Delay_1us(1000);
          v15_off();
          Delay_1us(500);
          v13_off();
          Delay_1us(500);
          v14_off();
          Delay_1us(18500);
        }
      
      // if(PushButton_Read())
      // {
      //   LED4_Off();
      //   for(i=0;i<90;i++)
      //   {
      //     LED3_Toggle();
      //     Delay_1us(100000-i*1000);

      //     if (PushButton_Read())
      //     {

      //     }
      //     else
      //       break;
      //   }
      // }
      // else
      // {

      //   LED4_Toggle();
      // Delay_1us(100000);
      //   LED3_Off();
      // }
      

    }

    while(1); // Don't want to exit
}
Exemple #20
0
void Disarm_Func(){
  if(f.arm == 1){
    f.arm = 0;
    Delay_1us(500000);
  }
}
Exemple #21
0
void Arm_Func(){
  if(f.arm == 0){ 
    f.arm = 1;
    Delay_1us(500000);
  }
}
Exemple #22
0
int main(void)
{
  PWM_Initialization();
  TIM1->CCR2 = 1000;
  TIM1->CCR3 = 1000;
  Delay_1us(500000);

  RCC_Configuration();
  PushButton_Initialization();
  LED_Initialization();
  //LCD_Initialization();
  //terminalBufferInitilization();

  Delay_1us(100000);
  SPI_Initialization();
  Delay_1us(100000);
  IMU_Initialization();
  Delay_1us(100000);
  Timer5_Initialization(); //Filter
  Timer2_Initialization(); //Print
  Timer4_Initialization(); //Read IMU

  USART3_Configuration();
  USART3_puts("\r\nHello World!\r\n");
    
  while(1)
  {
    if(PushButton_Read()){
      if(f.arm == 0){ 
        f.arm = 1;
        Delay_1us(500000);
      }
      else if(f.arm == 1){
        f.arm = 0;
        Delay_1us(500000);
      }
    }

    if(f.imu == 1){
      //LED3_Toggle();
      readIMU(gyroRaw, GYRO_DATA_REGISTER);
      gyro_remove_offset(gyroRaw);
      readIMU(accRaw, ACC_DATA_REGISTER);
      f.imu = 0;
    // }  

    // if(f.filter == 1){
      //LED4_Toggle();
      Filter(gyroRaw, gyroAngle, accRaw, accAngle, Angle);
      if(f.arm == 1){
        PID_control(Angle);
      }
      else{
        TIM1->CCR2 = 1000;
        TIM1->CCR3 = 1000;

        errorI = 0;
        errorD = 0;
        previous_error = 0;
      }

      //f.filter = 0;
    }

    strcmd_main();      

    //if(f.print == 1){
      
      // sprintf(lcd_text_main,"%.4f %.4f %d", Angle[0], Angle[1], f.arm);
      // //sprintf(lcd_text_main,"G: %.3f %.3f %.3f", EstV.G.X, EstV.G.Y, EstV.G.Z);
      // LCD_DisplayStringLine(LINE(1), lcd_text_main);
      // //sprintf(lcd_text_main,"A: %.3f %.3f %.3f", EstV.A.X, EstV.A.Y, EstV.A.Z);
      // //sprintf(lcd_text_main,"A: %.3f %.3f", sqX_sqZ, EstV.GA.X*EstV.GA.X + EstV.GA.Z*EstV.GA.Z);
      // // sprintf(lcd_text_main,"%.4f %.4f %.4f \n", gyroAngle[0], gyroAngle[1], gyroAngle[2]);
      // sprintf(lcd_text_main,"%d     ", gyroRaw[2]);
      // LCD_DisplayStringLine(LINE(2), lcd_text_main);
      // sprintf(lcd_text_main,"GA: %.3f %.3f %.3f", EstV.GA.X, EstV.GA.Y, EstV.GA.Z);
      // LCD_DisplayStringLine(LINE(3), lcd_text_main);
      //sprintf(lcd_text_main,"%.3f %.3f %.3f\n", EstV.G.Z, EstV.A.Z, EstV.GA.Z);
      
      //LCD_DisplayStringLine(LINE(2), (uint8_t*)" Ming6842 @ github");
      //terminalWrite(lcd_text_main);
      //PRINT_USART();
      //f.print = 0;
    //}
  }

  while(1); // Don't want to exit
}
Exemple #23
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;
    USART_Init(USART1, &USART_InitStructure);
    USART_Cmd(USART1, ENABLE);

    USART_ClearFlag(USART1, USART_FLAG_TC);

    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)
    {
        LED3_Toggle();

        Delay_1us(10000);


    }

}