Esempio n. 1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  uint8_t i = 0;
  
  /* Select fCPU = 16MHz */
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
  
  /* Init the Eval board LCD */
  STM8S_EVAL_LCD_Init();

  /* Clear LCD */
  LCD_Clear();

  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print("SPI-LCD example");		
  
  /* Display "moving" ST logo */
  for (i = 1; i < 8; i++)
  {
    PrintLogo();
    Delay(0xFFFF);
  }
  
  LCD_SetCursorPos(LCD_LINE2, 0);
  LCD_Print("               ");

  LCD_DisplayLogo(0x93);
  Delay(600);
  while(1)
  {}

}
Esempio n. 2
0
/**
  * @brief  Print ST logo on the LCD
  * @param  None
  * @retval None
  */
void PrintLogo(void)
{
  static uint8_t logo_pos = 0x90;
  static int8_t logo_pos_index = 1;

  LCD_SetCursorPos(LCD_LINE2, 0);
  LCD_Print("               ");

  LCD_DisplayLogo(logo_pos);
  logo_pos += logo_pos_index;
  if (logo_pos > 0x95)
  {
    logo_pos -= 2;
    logo_pos_index = -1;
  }
  if (logo_pos < 0x90)
  {
    logo_pos += 2;
    logo_pos_index = 1;
  }
}
Esempio n. 3
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;
            }
        }
    }

}
Esempio n. 4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    STM_EVAL_LEDInit(LED2);
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED4);

    /* Initialize KEY button */
    STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

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

    /* Initialize LCD */
    STM8L_EVAL_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(5000);
    }

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

    /* Clear LCD lines */
    LCD_Clear();

    /* Max 15 characters per line */
    LCD_SetCursorPos(LCD_LINE1, 0);
    LCD_Print(" *** STM8L *** ");
    LCD_SetCursorPos(LCD_LINE2, 0);
    LCD_Print("SPI-LCD example");

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

    /* Clear LCD lines */
    LCD_Clear();

    LCD_Print("Press KEY...");

    while (1)
    {
      /* Check button status */
      if (GetVar_ButtonPressed() == TRUE) /* Button is pressed */
      {
        ButtonPressed = FALSE;
        LCD_SetCursorPos(LCD_LINE2, 0);
        LCD_Clear();
        LCD_Print("LED #");
        sprintf((char*)StrName, "%d", (int)(ButtonIndex + 2));

        LCD_Print(StrName);
        LCD_SetCursorPos(LCD_LINE2, 2); /* 8th position */
        if (LedState == 0)
        {
          LCD_Print("OFF");
        }
        else
        {
          LCD_Print("ON");
        }
        switch (ButtonIndex)
        {
          case 0:
            STM_EVAL_LEDToggle(LED2);
            ButtonIndex++;
          break;
          
          case 1:
            STM_EVAL_LEDToggle(LED3);
            ButtonIndex++;
          break;

          case 2:
            STM_EVAL_LEDToggle(LED4);
            ButtonIndex = 0;
            LedState ^= 0x01;
          break;
        }
    }
  }
}