Пример #1
0
int main(void) {

	// Initialise the clock to have a /1 prescaler and use the external crystal clock source for accuracy.
	CLK_DeInit();
	CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
	CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
	
	// Reset ("de-initialise") GPIO port D.
	GPIO_DeInit(GPIOD);
	// Initialise pin 0 of port D by setting it as:
	// - an output pin,
	// - using a push-pull driver,
	// - at a low logic level (0V), and
	// - 10MHz.
	GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
	
	LCDInit(); // Init the LCD
	DecodeInit(); // Init the GPS decoding
	DrawScreen(); // Setup Screen and Buffer
	
	// Infinite loop.
	for(;;) {
		// Blink Debug LED
		GPIO_WriteReverse(GPIOD, GPIO_PIN_0);
		
		DrawDemo();	
	}
}
Пример #2
0
/**
  ******************************************************************************
  * @brief Adjustable led blinking speed using touch sensing keys
  * KEY1: LED1 is blinking
  * KEY1: LED1 is blinking faster
  * KEY1: LED1 don't blink anymore
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void ExtraCode_StateMachine(void)
{
  if ((TSL_GlobalSetting.b.CHANGED) && (TSLState == TSL_IDLE_STATE))
  {
    TSL_GlobalSetting.b.CHANGED = 0;

    if (sSCKeyInfo[0].Setting.b.DETECTED) /* KEY 1 touched */
    {
      BlinkSpeed++;
      BlinkSpeed = BlinkSpeed % 4;  // mike - was 3 
    }
  }
/*
  * Mike added - just worked out the action sequence for the stm8s 'new-code-install' 
  they call it download - my ASD get confused with this and freezes - 
  in the project tab - look for the debug and download words
  - debug tab - select a statement in C code in prog and can 'run to ursor' 
  - can go (F5) 
  next to change the case statement to add extra case and toggle an extra LED to be added 
  
  */
  switch (BlinkSpeed)
  {
    case 0 :
      GPIO_WriteHigh(GPIOD, GPIO_PIN_0);
 //     GPIO_WriteHigh(GPIOD, GPIO_PIN_1);
      GPIO_WriteHigh(GPIOD, GPIO_PIN_2);        // mike added
      break;

    case 1 :
      GPIO_WriteLow(GPIOD, GPIO_PIN_2);
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 2*MilliSec);
      }
      break;

    case 2 :
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 1*MilliSec);
      }
      break;
      
    case 3 :
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 1*MilliSec);
  //      GPIO_WriteHigh(GPIOD, GPIO_PIN_1);
          GPIO_WriteReverse(GPIOD, GPIO_PIN_2); // each time we go here we toggle
      }
      break;

    default :
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 1*Sec);
      }
  }
}
Пример #3
0
/*******************************************************************************
* 名    称: App_ModbusQPost
* 功    能: 时间平滑平均滤波
* 入口参数: filter:缓存一段时间内的dat值   dat:当前测量值
* 出口参数: 经过平滑平均函数之后的dat值
* 作  者: Roger-WY
* 创建日期: 2015-05-30
* 修    改:
* 修改日期:
* 备    注:
*******************************************************************************/
void  BSP_LED_Toggle (uint8_t led)
{
    switch (led) {
        case 0:
        GPIO_WriteReverse(LED1_GPIO_PORT, LED1_GPIO_PIN);
        GPIO_WriteReverse(LED2_GPIO_PORT, LED2_GPIO_PIN);
        break;
        case 1:
        GPIO_WriteReverse(LED1_GPIO_PORT, LED1_GPIO_PIN);
        break;
        case 2:
        GPIO_WriteReverse(LED2_GPIO_PORT, LED2_GPIO_PIN);
        break;
        default:
        break;
    }
}
Пример #4
0
/**
  * @brief How to make  a write followed by a read in the E²PROM.
  * @par Examples description
	* - Write 8 bytes on the devive  (E²PROM) 0xA0.
  * - Read back the 8 bytes written on the devive  (E²PROM) 0xA0.
	* - Check the coherency between the written and read Data.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main()
{

    /* Initialize I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST);

    /* Optional: put here as example only */
    I2C_DeInit();

    /* Initialize the I2C */
    I2C_EEInit();

    /* All LEDs are ON per default */
    GPIO_WriteLow(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN));

    /*** WRITE SEQUENCE ***/
   I2C_EE_PageWrite(Buffer, Base_Add, Buffer_size);
    Delay(1000); /* To let eeprom the time to finish the write operation */

    /***  READ SEQUENCE ***/
    I2C_EE_BufferRead(Data, Base_Add, Buffer_size);
        
     /*** Check transmitted and received buffers ***/
    for (i =Buffer_size; i > 0; i--)
    {
        if (Buffer[i-1] != Data[i-1])
        {
            /* Toggle only LED1 if error is detected */
            while (1)
            {
                GPIO_WriteReverse(LEDS_PORT, LED1_PIN);
                Delay((u16)60000);
            }
        }
    }

    /* Toggle all LEDs when I2C communication is terminated and buffers are ok */
    while (1)
    {
        GPIO_WriteReverse(LEDS_PORT, (LED2_PIN | LED3_PIN | LED4_PIN));
        Delay((u16)60000);
    }

}
Пример #5
0
Файл: main.c Проект: msrLi/Robot
void Deal_ExtiA()
{
  uint8_t i;
  flageExtiA=1;
  GPIO_WriteReverse(GPIOA,GPIO_PIN_3);  
  for(i=0;i<8;i++)
  {  
    Send(sendBuff[i]);
   }  
}
Пример #6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{

  /* Initialize I/Os in Output Mode */
  GPIO_Init(LED_GPIO_PORT, (GPIO_Pin_TypeDef)LED_GPIO_PINS, GPIO_MODE_OUT_PP_LOW_FAST);

  while (1)
  {
    /* Toggles LEDs */
    GPIO_WriteReverse(LED_GPIO_PORT, (GPIO_Pin_TypeDef)LED_GPIO_PINS);
    Delay(0xFFFF);
  }

}
Пример #7
0
int main( void ) {

    uint16_t i;

    GPIO_DeInit(GPIOD);
    SPI_DeInit();

    GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
    init_spi();

    // The main loop
    while( 1 ){

        for(i=0;i<150;i++) // A delay loop
        {
            nop();
        }
        GPIO_WriteReverse(GPIOD, GPIO_PIN_0);
//        spi_write_data_8t("keep going...", 0x40);//Random Address 0x40 for now.
        spi_write_data_8t("msg", 0x55);//Random Address 0x40 for now.
    }

}
Пример #8
0
void CharDecode(char c) {
	switch (c) {
		case '\r':
        case '\n': 
		case '#':
			memset(text, 0, sizeof(text));
			strncpy(text,_term,_term_offset);
			text[_term_offset] = '\n';
			_term_offset = 0;
			memset(_term, 0, sizeof(_term));
			return;
			
		case '$':
			// Blink Debug LED
			GPIO_WriteReverse(GPIOD, GPIO_PIN_0);
			return;
	}
	if (_term_offset < sizeof(_term) - 1)
        _term[_term_offset++] = c;
	else {
		strncmp(text,_term,_term_offset);
		_term_offset = 0;
	}
}
Пример #9
0
Файл: main.c Проект: vitfre/STM8
int main( void )
{
  uint32_t Address_EEPROM=EEPROM_START+4;
  uint32_t n0=0;
  uint32_t n1=0;
  uint32_t k0=0;
  uint32_t k1=0;
  uint8_t ERR=2;
  uint8_t rr=0;

  CLK_Init();
  UART_Init();
  GP_IO_Init();
  TIMR2_Init();
  FLASH_EEPROM_Unlock();
  A_D_C_Init();

 //enableInterrupts(); //Разрешаем прерывания.

 while(1)
 {
   /*
   if(GPIO_ReadInputPin(GPIOC, GPIO_PIN_2)==0)
   {
      GPIO_WriteLow(GPIOB, GPIO_PIN_6);
      delay_ms(50);
      GPIO_WriteHigh(GPIOB, GPIO_PIN_6);
      while(GPIO_ReadInputPin(GPIOC, GPIO_PIN_2)==0){delay_ms(10);};
   };
   
   if(GPIO_ReadInputPin(GPIOE, GPIO_PIN_5)==0)
   {
      GPIO_WriteLow(GPIOB, GPIO_PIN_7);
      delay_ms(50);
      GPIO_WriteHigh(GPIOB, GPIO_PIN_7);
      while(GPIO_ReadInputPin(GPIOE, GPIO_PIN_5)==0){delay_ms(10);};
   };
   */
   if(GPIO_ReadInputPin(GPIOC, GPIO_PIN_1)==0)
   {
      ERR=0;
      GPIO_WriteHigh(GPIOB, GPIO_PIN_5);
      GPIO_WriteHigh(GPIOB, GPIO_PIN_6);
      while(GPIO_ReadInputPin(GPIOC, GPIO_PIN_1)==0){delay_ms(10);};
   };
   
  if(ERR==0)
  {
    GPIO_WriteLow(GPIOB, GPIO_PIN_7);
    //delay_ms(6);              
    FLASH_ProgramWord(Address_EEPROM, n0);
    //FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
    GPIO_WriteHigh(GPIOB, GPIO_PIN_7);
    delay_ms(4);
    n1 = FLASH_ReadWord(Address_EEPROM);
    if(n1!=n0)
    {
      ERR=1;
    }else
    {
      n0++;
      GPIO_WriteReverse(GPIOF, GPIO_PIN_4);
    };
    
  }else if(ERR==1)
  {
    GPIO_WriteReverse(GPIOB, GPIO_PIN_5);
    delay_ms(100);
  }else if(ERR==2)
  {
    GPIO_WriteReverse(GPIOB, GPIO_PIN_6);
    delay_ms(100);
  };
   /*
  GPIO_WriteLow(GPIOB, GPIO_PIN_6);
  delay_ms(50);
  GPIO_WriteHigh(GPIOB, GPIO_PIN_6);
  
  GPIO_WriteLow(GPIOB, GPIO_PIN_7);
  delay_ms(50);
  GPIO_WriteHigh(GPIOB, GPIO_PIN_7);
   
  GPIO_WriteLow(GPIOB, GPIO_PIN_5);
  delay_ms(50);
  GPIO_WriteHigh(GPIOB, GPIO_PIN_5);
  delay_ms(1000); 
*/

 }
 
 //return 0;
}
Пример #10
0
/**
  * @brief Validation firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    int ButtonIndex =0;
    u8 i =0;
    u8 LedState =1;
    u8 pos =0;
    u8 s[16];

    /* Initialize I/Os in Output Mode for LEDs */
    GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN,GPIO_MODE_OUT_PP_LOW_FAST);

    /* Initialization of I/O in Input Mode with Interrupt for Key button */
    GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT);

    /* Initialization of the Interrupt sensitivity */
    EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);

    /* Enable general interrupts for Key button reading */
    enableInterrupts();

    /* Initialize SPI */
    SPI_DeInit();
    SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER,
             SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX,
             SPI_NSS_SOFT, 0x07);
    SPI_Cmd(ENABLE);

    /* Initialize LCD */
    LCD_Init();

    /* Clear LCD lines */
    LCD_Clear();

    /* Display "moving" ST logo on first line */
    for (pos = 0x80; pos < 0x88; pos++)
    {
        LCD_Clear();
        LCD_DisplayLogo(pos);
        Delay(20000);
    }

    /* Display "moving" ST logo on second line */
    for (pos = 0x90; pos < 0x98; pos++)
    {
        LCD_Clear();
        LCD_DisplayLogo(pos);
        Delay(20000);
    }

    LCD_Clear();

    /* More than 15 characters: the message is displayed on 2 lines */
    /* LCD_PrintMsg("STM8S - SPI/LCD example"); */

    /* Max 15 characters per line */
    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " *** STM8S *** ");
    LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, "SPI-LCD example");

    for (i = 0; i < 10; i++)
    {
        Delay(0xFFFF);
    }

    LCD_Clear();

    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "Press KEY...");

    while (1)
    {
        /* Check button status */
        if (GetVar_ButtonPressed() == TRUE) /* Button is pressed */
        {
            ButtonPressed = FALSE;
            LCD_ClearLine(LCD_LINE2);
            LCD_PrintString(LCD_LINE2, DISABLE, DISABLE, "LED #");
						
           /*Use the  sprintf() and LCD_Print() function to print a digit on the LCD */
 					 if (LedState == 0)
            {
                sprintf(s,"%d ", ButtonIndex + 1);
                LCD_Print(s);
								LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */
                LCD_PrintChar('O');
                LCD_PrintChar('F');
                LCD_PrintChar('F');
            }
						/*Use the LCD_PrintDec1() function to print a digit on the LCD */
            else
            {
                LCD_PrintDec1((u8)(ButtonIndex + 1)); /* Display at current cursor position */
                LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */ 
								LCD_PrintChar('O');
                LCD_PrintChar('N');
                LCD_PrintChar(' ');
            }
             switch (ButtonIndex)
            {
            case 0:
                GPIO_WriteReverse(LEDS_PORT, LED1_PIN);
                ButtonIndex++;
                break;
            case 1:
                GPIO_WriteReverse(LEDS_PORT, LED2_PIN);
                ButtonIndex++;
                break;
            case 2:
                GPIO_WriteReverse(LEDS_PORT, LED3_PIN);
                ButtonIndex++;
                break;
            default:
            case 3:
                GPIO_WriteReverse(LEDS_PORT, LED4_PIN);
                ButtonIndex = 0;
                LedState ^= 0x01;
                break;
            }
        }
    }

}
Пример #11
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    /* Configures the Multiplexer on the evalboard to select the IrDA*/
    Multiplexer_EvalBoard_Config();

    /* Initialize I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);

    UART1_DeInit();
    /* UART1 configuration ----------------------------------------------------*/
    /* UART1 configured as follow:
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - BaudRate = 9600 baud
          - Tx and Rx enabled
          - UART1 Clock disabled
    */
    UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

		/* Set Prescaler*/
    UART1_SetPrescaler(0x1);

    UART1_IrDAConfig(UART1_IRDAMODE_NORMAL);

    UART1_IrDACmd(ENABLE);
    while (1)
    {
        /* Wait until a byte is received */
        while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
        {
        }
        /* Read the received byte */
        ReceivedData = UART1_ReceiveData8();

        switch (ReceivedData)
        {
            /* Led connected to PH.0 (LED4) toggle */
        case UP:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_0);
            break;
            /* Led connected to PH.1 (LED3) toggle */
        case DOWN:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_1);
            break;
            /* Led connected to PH.2 (LED2) toggle */
        case LEFT:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_2);
            break;
            /* Led connected to PH.3 (LED1) toggle */
        case RIGHT:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_3);
            break;

        case SEL:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_0|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1);
            break;
        default:
            break;
        }
    }

}
Пример #12
0
Файл: main.c Проект: msrLi/Robot
void main(void)
{
  uint8_t i;
  BitStatus bytes;
  CLK_HSICmd(ENABLE);//开始内部高频RC
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);//不分频  16MHz
  /* Initialize I/Os in Output Mode */
  init_usart1();   // 输入判断
  GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);// 输出 模式 用于Trag 
  GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);// 输出 模式 用于Trag 
  GPIO_WriteHigh(GPIOA, GPIO_PIN_2);
  GPIO_Init(GPIOA,GPIO_PIN_1,GPIO_MODE_IN_PU_NO_IT);       // 输入包含  上拉  中断 
//  GPIO_Init(GPIOA,GPIO_PIN_1,GPIO_MODE_IN_PU_IT); 
//  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOA,EXTI_SENSITIVITY_RISE_ONLY); 
  InitADC();
  enableInterrupts();
  flageExtiA=0;  
  sendBuff[0]=DEVICE_ID;
  sendBuff[3]=0xff;
  sendBuff[4]=0xff;
  sendBuff[5]=0xFF;
  sendBuff[6]=0xA0;
  sendBuff[7]=0xFA; 

  while (1)
  {
     
    bytes=GPIO_ReadInputPin(GPIOA,GPIO_PIN_1);
    if(bytes==RESET && flageExtiA==0)    
    {
        flageExtiA=1;  
        GPIO_WriteReverse(GPIOA,GPIO_PIN_3);  
        for(i=0;i<8;i++)
        {  
          Send(sendBuff[i]);
         }
    }else if(bytes!=RESET)
    {
      flageExtiA=0;
    }  
    datas=readADCs();
  sendBuff[5]=0;
  sendBuff[1]=(uint8_t)(datas&0xff);
  sendBuff[2]=(uint8_t)((datas>>8)&0xff);
  for(i=0;i<5;i++)
  {
    sendBuff[5]+=sendBuff[i];
  }      
//    datas=datas;
//    bytes=GPIO_ReadInputPin(GPIOA,GPIO_PIN_1);
//    if(flageExtiA!=1)
//    {
//      sendBuff[1]=(uint8_t)(datas&0xff);
//      sendBuff[2]=(uint8_t)((datas>>8)&0xff);
//      sendBuff[5]=0;
//      for(i=0;i<5;i++)
//      {
//        sendBuff[5]+=sendBuff[i];
//      }
//    }
  }
  
}
Пример #13
0
/**
  ******************************************************************************
  * @brief Toggle PD0 (Led LD1)
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void Toggle(void)
{
  GPIO_WriteReverse(GPIOD, GPIO_PIN_0);
}