Docs

Micro-controllers, wireless transmission and database

Head

LCD 1602 I2C with STM8S103F3P6 using ST Visual develop IDE

Prerequisites

This project assumes you have already installed ST Visual develop IDE and Cosmic Compiler. You need to have previously done a basic blink sketch with STM8S103F3P6 using STVD. I have made a complete video from installing to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=iFiBfx9vCqo

Wiring Diagram

Diagram

Libraries

FROM STM8S/A Standard peripheral library

from https://www.st.com/en/embedded-software/stsw-stm8069.html

stm8s.h

stm8s_clk.h

stm8s_gpio.h

stm8s_i2c.h

stm8s_clk.c

stm8s_gpio.c

stm8s_i2c.c

stm8s_conf.h

lcd_i2c.h

lcd_i2c.c

main.c code

#include "stm8s.h"
#include "lcd_i2c.h"

main()
{
  // setup()
  int testValue = 0; // Max value of int is 32767 
             // use long for higher values
  LCD_Begin();
  LCD_Clear();
  LCD_BL_On();  // Back light on
  LCD_Set_Cursor(1,1);
  LCD_Print_String("STM8 LCD 1602");
  LCD_Set_Cursor(2,1);
  LCD_Print_String("by MICROPETA");
  delay_ms(2000);
  LCD_Clear();
  LCD_BL_Off();  // Back light off
  LCD_Set_Cursor(1,1);
  LCD_Print_String("Nizar Mohideen");
  delay_ms(2000);
  LCD_BL_On();  // Back light on
  LCD_Set_Cursor(2,1);
  LCD_Print_String("Score: ");
  // loop()
  while (1)
  {
    LCD_Set_Cursor(2,8);
    LCD_Print_Integer(testValue);
    delay_ms(100); 
    testValue++;
  }
}