34-LCD_2x16-Library (STM32F4)

Diese Library dient zum ansteuern eines Text LC-Display mit 2×16 Zeichen. Die LIB ist kompatibel mit den Chips :  ST7066U, HD44780, SED1278, KS0066U, S6A0069X

Das Display wird im 4Bit-Mode betrieben und benötigt dazu 6 GPIO-Pins zur Datenverbindung. Im C-File können diese beliebig auf die freien Pins eingestellt werden. (Ich habe PE5 bis PE10 benutzt)

Beispielbild :

lcd2x16

Benutzte Pins :

PE5  -> LCD_RS
PE6  -> LCD_E
PE7  -> LCD_DB4
PE8  -> LCD_DB5
PE9  -> LCD_DB6
PE10 -> LCD_DB7

Voraussetzungen :

1
2
Benutzte Module der CooCox-IDE : GPIO
Benutzte Librarys : keine

Enumerationen :

1
2
3
4
5
6
typedef enum {
  TLCD_OFF =0,    // Display=AUS, Cursor=Aus, Blinken=Aus
  TLCD_ON,        // Display=EIN, Cursor=Aus, Blinken=Aus
  TLCD_CURSOR,    // Display=EIN, Cursor=EIN, Blinken=Aus
  TLCD_BLINK      // Display=EIN, Cursor=EIN, Blinken=EIN
}TLCD_MODE_t;

Funktionen :

1
2
3
4
5
6
void UB_LCD_2x16_Init(void);                              // um das Display zu initialisieren
void UB_LCD_2x16_Clear(void);                             // um das Display zu löschen
void UB_LCD_2x16_SetMode(TLCD_MODE_t mode);               // um den Display Mode zu ändern
void UB_LCD_2x16_String(uint8_t x, uint8_t y, char *ptr); // zum ausgeben eines Strings an x,y Position
void UB_LCD_2x16_WriteCG(uint8_t nr, uint8_t *pixeldata); // zum speichern von Sonderzeichen
void UB_LCD_2x16_PrintCG(uint8_t x, uint8_t y, uint8_t nr); // zum anzeigen von Sonderzeichen

Beispiel :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//--------------------------------------------------------------
// File     : main.c
// Datum    : 17.04.2013
// Version  : 1.0
// Autor    : UB
// EMail    : mc-4u(@)t-online.de
// Web      : www.mikrocontroller-4u.de
// CPU      : STM32F4
// IDE      : CooCox CoIDE 1.7.0
// Module   : CMSIS_BOOT, M4_CMSIS_CORE
// Funktion : Demo der LCD-2x16-Library
// Hinweis  : Diese zwei Files muessen auf 8MHz stehen
//              "cmsis_boot/stm32f4xx.h"
//              "cmsis_boot/system_stm32f4xx.c"
//--------------------------------------------------------------
 
#include "main.h"
#include "stm32_ub_lcd_2x16.h"
 
int main(void)
{
  SystemInit(); // Quarz Einstellungen aktivieren
 
  // Init vom LC-Display
  UB_LCD_2x16_Init();
 
  // Text auf Zeile-1 ausgeben
  UB_LCD_2x16_String(0,0,"LCD 2x16 STM32F4");
 
  // Text auf Zeile-2 ausgeben
  UB_LCD_2x16_String(3,1,"Discovery");
 
  while(1)
  {
 
  }
}

Hier die Library zum Download :

ub_stm32f4_lcd_2x16_v101

Hier der komplette CooCox-Projektordner zum Download :

Demo_34_LCD_2x16

10 Antworten auf 34-LCD_2x16-Library (STM32F4)

  1. Marc Rupprath sagt:

    Danke für diese hilfreiche Bibliothek ;-)

    • admin_ub sagt:

      gerne

  2. efyzz sagt:

    Funktioniert super, vielen Dank!
    Wenn man

    #define TLCD_MAXX 40

    setzt, funktioniert es auch mit einem 2×40 bzw. 4×20 LCD :)

    Eine Frage:
    Verstehe ich das richtig, dass die CPU nur auf 8 MHz laufen darf?
    Was muss ich ändern, damit ich Vollgas geben kann?

    • admin_ub sagt:

      du musst nichts ändern. 8MHz hat der externe Quarz, aber intern läuft die CPU per PLL mit 168MHz.

  3. Andreas sagt:

    Hallo,
    erst einmal vielen Dank für die tollen Libraries.

    Hier hätte ich nur kurz die Frage, ob die Lib auch für ein DOT Matrix Display mit 4×20 Zeichen (HD44780 ) geeignet ist.

    Vielen Dank.

    Gruß
    Andreas

    • admin_ub sagt:

      ja, das steht oben im Text in der zweiten Zeile.

      • Andreas sagt:

        Ou man, habe ich glatt übersehen.
        Trotzdem vielen Dank für die Antwort.

  4. Jochen sagt:

    Hi,

    bei mir hat es bei einem 4×20 Dot Display leider nicht geklappt. Ich konnte die Zeile 3 bzw. 4 nicht erreichen, auch nachdem die defines auf

    #define TLCD_MAXX 20
    #define TLCD_MAXY 4

    eingestellt habe.
    Bei y=2 springt es auf Zeile 1, bei y=3 springt es auf Zeile 2.

    Habe das Problem durch umschreiben der Cursor Funktion in den Griff bekommen. Vielleicht hilft es ja jemanden weiter.

    void P_LCD_2x16_Cursor(uint8_t x, uint8_t y)
    {
    //uint8_t wert;
    
    if(x>=TLCD_MAXX) x=0;
    if(y>=TLCD_MAXY) y=0;
    
    /*
    wert=(y<<6);
    wert|=x;
    wert|=0×80;
    P_LCD_2x16_Cmd(wert);
    */
    
    if(y==0)
    P_LCD_2x16_Cmd( (1<<7) + x);
    else if(y==1)
    P_LCD_2x16_Cmd( (1<<7) + 0×40 + x);
    else if(y==2)
    P_LCD_2x16_Cmd( (1<<7) + 0×14 + x);
    else if(y==3)
    P_LCD_2x16_Cmd( (1<<7) + 0×54 + x);
    }

    Gruß
    Jochen

  5. Roy sagt:

    Hi, I’m trying to use custom caracters, but i’m failing. I get the caracter, but no matter what, the first 4 pixels (from left to right) of the first row are always on. Any clue?I did it with another library but I’d like to add the function to this library

    Could be something like this?

    #define CGRAM 0×40
    #define DDRAM 0×80
    void CreateCaracter(uint16_t RegPos, uint16_t X, uint16_t Y, uint16_t bytes[])
    {
    int i;
    P_LCD_2x16_Cmd(CGRAM+RegPos);//Select register of CGRAM to save byte
    for(i=0; i<8;i++)//Copy bite for bite to register
    {
    P_LCD_2x16_Data(bytes[i]);
    }
    P_LCD_2x16_Cmd(DDRAM+X+Y);//Select place of DDRAM and position in the LCD
    P_LCD_2x16_Data(RegPos);//Shows data alocated in the register
    
    }

    • admin_ub sagt:

      please download new version 1.1
      1. define an array for 8 bytes and set pixeldata
      2. store user char as char (0…7)
      3. print char on display

      uint8_t buf[8];
      buf[0]=0x01;
      buf[1]=0x02;
      buf[2]=0x03;
      buf[3]=0x04;
      buf[4]=0x05;
      buf[5]=0x06;
      buf[6]=0x07;
      buf[7]=0x08;
      UB_LCD_2x16_WriteCG(0,buf); // store data as char 0
      UB_LCD_2x16_PrintCG(0,0,0); // show char at pos 0,0
      


Wie hat Dir dieser Artikel gefallen?

1 Stern2 Sterne3 Sterne4 Sterne5 Sterne (Noch keine Bewertungen)
Loading...

22 Antworten zu 34-LCD_2x16-Library (STM32F4)

  1. naztra sagt:

    I tried to print some string in the loop block side, but the character and cursor just didn’t go the right way. can you give an example how to use the library in the loop block? Thank you

    • admin_mb sagt:

      Hi Naztra,
      sorry, but I do not understand what you mean by the „loop block“.
      Du you you mean the while(1){} block? Please give me your sample code. So I’m able to analyze it.
      Please use <pre> your sample code </pre> tags to post your sample.

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      
      #include "main.h"
      #include "stm32_ub_lcd_2x16.h"
       
      int main(void)
      {
        SystemInit(); // Quarz Einstellungen aktivieren
       
        // Init vom LC-Display
        UB_LCD_2x16_Init();
       
        // Text auf Zeile-1 ausgeben
        UB_LCD_2x16_String(0,0,"LCD 2x16 STM32F4");
       
        // Text auf Zeile-2 ausgeben
        UB_LCD_2x16_String(3,1,"Discovery");
       
        while(1)
        {
       
        }
      }
      • naztra sagt:

        iam sorry, this is my code

        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        
        #include "main.h" 
        #include "stm32_ub_lcd_2x16.h"
         
        int main ( void ) 
        { 
          System Init ( ) ;  Activate settings // Quartz
         
          // Init the LCD 
          UB_LCD_2x16_Init ( ) ;
         
          // Text on line-1 output 
          //UB_LCD_2x16_String ( 0 , 0 , "LCD 2x16 STM32F4" ) ;
         
          // print text on line 2 
         // UB_LCD_2x16_String ( 3 , 1 , "Discovery" ) ;
         
          while ( 1 ) 
          {
                UB_LCD_2x16_String ( 0, 0 , "Testing" ) ;
          } 
        }

        and the lcd print the chars around the place

        #Testing#Testing
        #Testing#Testing
        

        # = means some unknown char

        • naztra sagt:

          if i print the chars outside the while(1) it works well

          • admin_mb sagt:

            Hi
            be sure the LCD Controller is not in the busy state (BF = 0) before sending an instruction from the MPU to the LCD. You send several times each microsecond the command to display the string on the LCD. But the controller of the LCD need much more time to do the job. For example it needs 1.52 milliseconds to clear the display (have a look into the datasheet).
            The easiest way to avoid this is to add a delay after your command:

            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            
            #include "main.h" 
            #include "stm32_ub_lcd_2x16.h"
             
            void Delay(volatile uint32_t nCount)
            {
              while(nCount--)
              {
              }
            }
             
            int main ( void ) 
            { 
              System Init ( ) ;  Activate settings // Quartz
             
              // Init the LCD 
              UB_LCD_2x16_Init ( ) ;
             
              // Text on line-1 output 
              //UB_LCD_2x16_String ( 0 , 0 , "LCD 2x16 STM32F4" ) ;
             
              // print text on line 2 
             // UB_LCD_2x16_String ( 3 , 1 , "Discovery" ) ;
             
              while ( 1 ) 
              {
                    UB_LCD_2x16_String ( 0, 0 , "Testing" ) ;
                    Delay(50000);
              } 
            }
          • naztra sagt:

            great, thanks a lot sir

  2. DD4MS sagt:

    Hallo Zusammen,

    ich suche für ein Projekt ein I²C Library zum Ansteuern eines 4 mal 20 Zeichen LCD Displays. Die Displays gibt es mittlerweile für wenig Geld bei der Bucht oder Ama… .
    als Einzelmodul oder schon huckepack mit den Display.
    Der verwendete I²C Chip ist ein Philips PCF8574T ein einfacher 8 Bit Portexpander.
    Am liebsten wäre mir eine Lib von Uwe die sind immer erstklassig.

    mfg Michael DD4MS

  3. Michael DD4MS sagt:

    Hallo Manfred,

    ja genau so etwas ist es.

    So ich habe hier diesen, den ich gekauft habe:
    http://amzn.to/2DeMelr
    oder diesen nur mit einen 2*16 Zeichen Display:
    http://amzn.to/2mUt91V
    die Platinen gibt es auch einzeln:
    http://amzn.to/2mRT0aF

    Der IC ist immer der gleiche!

    Gruß aus der nähe von Worms mit extremen Windbedingungen!

    Michael

  4. maxi sagt:

    Hola, primero que nada gracias por la libreria!, queria hacer una consulta sobre el Back Light es posible controlarlo mediante firmware?.

    • admin_mb sagt:

      The backlight can be turned on and off.
      void UB_LCD_TEXT_I2C_Backlight_On (LCD_TEXT_DISPLAY_t *lcd);
      void UB_LCD_TEXT_I2C_Backlight_Off (LCD_TEXT_DISPLAY_t *lcd);

  5. Putraa sagt:

    Hallo Ich bin aus Indonesien, ich möchte fragen , Ich habe alle Möglichkeiten oben gefolgt, warum kann nicht auch Caracter wie oben anzeigen, Ich benutze lcd 20 x 4 , aber es gibt keinen Exit-Text, bitte akzeptieren Sie die Antwort

    • admin_mb sagt:

      Without any source code, it is difficult to determine where the problem is.
      Please post your MAIN function. Then I can check that.

      Change in header file stm32_ub_lcd_2x16.h these two lines

      #define  TLCD_MAXX            20 // 16  // max x-Position (0...15)
      #define  TLCD_MAXY             4 //  2  // max y-Position (0...1)
      

      Then try this:

      #include "main.h"
      #include "stm32_ub_lcd_2x16.h"
       
      int main(void)
      {
        SystemInit(); // Quarz Einstellungen aktivieren
       
        // Init vom LC-Display
        UB_LCD_2x16_Init();
       
        // Text auf Zeile-1 ausgeben
        UB_LCD_2x16_String(0,0,"LCD 2x16 STM32F4");
       
        // Text auf Zeile-2 ausgeben
        UB_LCD_2x16_String(3,1,"Discovery");
       
        // Text auf Zeile-3 ausgeben
        UB_LCD_2x16_String(6,2,"Hello");
      
        // Text auf Zeile-4 ausgeben
        UB_LCD_2x16_String(12,3,"world!");
      
        while(1)
        {
       
        }
      }
      
      • Putraa sagt:

        I have tried the code program that you have given but the results still can not bring up any letter characters, can you give me wiring diagrams and code programs that you have created and the results can bring up characters that match the code of the program? I hope you want to give it, because I need to project my school, thank you, greetings from Indonesia

        • admin_mb sagt:

          The display is operated in 4-bit mode and requires 6 GPIO pins for data connection. These can be set to any of the free pins in the C-file. I have used PE5 to PE10.
          You have to connect them to the pins of your LCD Display:
          PE5 -> LCD_RS
          PE6 -> LCD_E
          PE7 -> LCD_DB4
          PE8 -> LCD_DB5
          PE9 -> LCD_DB6
          PE10 -> LCD_DB7

      • Putraa sagt:

        If you want to give it to me, I really hope it’s a good person.

      • Putraa sagt:

        my email : i got it

Schreibe einen Kommentar zu Putraa Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert