AnsweredAssumed Answered

I did LCD attempt with stm32 have a problem.

Question asked by yildiz.nazim.001 on Apr 17, 2011
Latest reply on Apr 17, 2011 by yildiz.nazim.001
Hi
I have lm016L 2x16 LCD.
I'm suppyling LCD with +5V and i'm using 4bit communication.
I checked the D4,D5,D6,D7 pin's voltaj and entire are 2.7Volt
My codes are ;

Main.c
------------------------------------------------------------------
#include <stm32f10x.h>
#include "LCD.h"

void rcc_init(void);
void delay(unsigned long gecikme);

int main(void)
{
     rcc_init();

     GPIOC->CRL &= 0x00000000;
     GPIOC->CRL = 0x00000003;                              //For external led.
     GPIOC->CRH &= 0x00000000;                    //PORTC 8,9 bits are Output mode 
     GPIOC->CRH = 0x00000033;
     GPIOA->CRL &= 0x00000000;               
     GPIOA->CRL = 0x33333333;                              //PORTA 0-7 pins are using for LCD
     GPIOC->ODR = 0x00000001;                              //External led at portc pin0
     lcd_init();
     cursor(1,2);
     lcd_karakter('A');                                                  //Character function
     cursor(2,1); 
     lcd_write("ASDASDASD");
     delay(0x00FFFFFF);
     for(;;)
     {
          GPIOC->ODR |= 0x00000300;                         //On board leds are high(LD4 and LD3)
          delay(0x0005ffff);
          GPIOC->BRR = 0x00000300;                         //Leds are low
          delay(0x0005ffff);
     }
}
void rcc_init(void)
{
     RCC->CR |= 0x00030000;                         //HSEON=1
     while(!(RCC->CR & 0x00020000));                 //Wait to HSE be stabilized
     RCC->CIR |= 0x00080000;                         //HSERDYC: HSE ready interrupt cleared
     RCC->CR |= 0x00080000;                          //Clock security system Enabled.
     RCC->CIR |= 0x00800000;                         //CSSC: Clock security system interrupt cleared.
     RCC->CR |= 0x00040000;                         //HSE bypassed.

//     RCC->APB2RSTR |= 0x000000FC;                  //PORT A,B,C,D,E Resetlendi.
     RCC->CFGR |= 0x00000005;                     //SW[1:0]=01: HSE selected as system clock  
                                                       //SWS[3:2]=01: HSE oscillator used as system clock
     RCC->CFGR |= 0x00000080;                    //AHB configuration -> 1000: SYSCLK divided by 2
     RCC->CFGR |= 0x00002000;                     //APB2 configuration -> 100: HCLK divided by 2
     RCC->APB2ENR |= 0x00000014;                    // PORT C,A Clock Enabled.
     

}

void delay(unsigned long gecikme)
{
     while(gecikme--);
}     
-------------------------------------------------------------------------------------------

LCD.c
------------------------------------------------------------------------------------
#include <stm32f10x.h>
#include "LCD.h"

void lcd_init(void)
{
     lcd_komut(0x00000002);                    
     lcd_komut(0x00000028);
     lcd_komut(0x00000006);
     lcd_komut(0x00000008);
     lcd_komut(0x0000000C);
     lcd_komut(0x00000001);
     gecikme(0x0000ffff);                         //more than 3ms delay.     
}
void lcd_write(const unsigned char string[])
{
     unsigned char x=0;
     while(string[x]!='\0')
     {
          gecikme(0x0000ffff);
          lcd_karakter(string[x]);
          x++;
     
}
void cursor(unsigned char satir,unsigned char sutun)
{
     if(satir==1)
     {
          lcd_komut(0x00000080 +(sutun-1));
     }
     else
     {
          lcd_komut(0x000000C0 + (sutun-1));
     }
}
void lcd_karakter(unsigned char veri)                                        //Character function
{
     GPIOA->ODR=0x00000003;                              //RS,E = High
     GPIOA->ODR |= (veri & 0x000000F0);                         //Yuksek degerlikli 4 bit gonderiliyor.
     GPIOA->BRR=0x00000002;                              //E = Low
     gecikme(0x0000ffff);
     GPIOA->BRR=0x000000F0;

     GPIOA->ODR |= 0x00000002;                              //E = High
     GPIOA->ODR |= ((veri & 0x0000000F)<<4);                     //Dusuk degerlikli 4 bit gönderiliyor.
     GPIOA->BRR=0x00000002;                              //E = Low
     gecikme(0x0000ffff);
     GPIOA->BRR=0x000000F0;
}
void lcd_komut(unsigned char komut)                              //Command function
{
     GPIOA->BRR = 0x00000001;
     GPIOA->ODR = 0x00000002;                              //RS = 0, E=1     Yani komut gönderilecek lcdye.
     GPIOA->ODR |= (komut & 0x000000F0);
     GPIOA->BRR=0x00000002;                              //E=0
     gecikme(0x0000ffff);
     GPIOA->BRR=0x000000F0;
     
     GPIOA->ODR=0x00000002;                              //E=1
     GPIOA->ODR |= ((komut & 0x0000000F)<<4);
     GPIOA->BRR=0x00000002;                              //E=0
     gecikme(0x0000ffff);
     GPIOA->BRR=0x000000F0;                              
}
void lcd_temizle(void)                                                  //LCD clear function
{
     lcd_komut(0x00000001);
     gecikme(0x0000ffff);
}

void gecikme(unsigned long x)                                   //Delay function for lcd library
{                    

     while(x--);
}
------------------------------------------------------------------------------------------

LCD.h
--------------------------------------------------------------------------------
/*------ACIKLAMA-------
--RS=GPIOA.bit0
--RW=At the stm32's ground.
--E=GPIOA.bit1
--D4,D5,D6,D7 = GPIOA.bit4,5,6,7
*/

extern void lcd_init(void);
extern void lcd_write(const unsigned char string[]);
extern void cursor(unsigned char satir,unsigned char sutun);
extern void lcd_karakter(unsigned char veri);
extern void lcd_komut(unsigned char komut);
extern void lcd_temizle(void);
extern void gecikme(unsigned long gecikme);
------------------------------------------------------------------------------------------
Not:I use this my lcd library with my PIC projects and they were worked

******* TROUBLESHOOTING GUIDE for LCD(LM016L 2x16) ********
Sympton:
A) No display after initialization and data sent.
Probable cause:
1. VO voltage not properly set. Check specification. Some displays require a negative voltage at this
pin. Set up VO with potentiometer that will adjust over full range from VDD to VSS, or VDD to VEE
(-5VDC). (See Power Supply Section).
2. Timing violated. Check that all set up times are followed. check that Enable pulse must be 450nS
minimum.
3. Execution times violated. Do not send signals for 15mS after power up. Allow 1.6mS after Clear
and Return Home Instructions are sent; 40mS after other instructions and the data are sent.
4. Improper initialization. It's always a good idea to send an initialization routine after power up. The
internal routine leaves the display in the OFF condition.
5. Do not store in direct sunlight.
6. If leakage of the liquid crystal material should occur, all contact with this material, particularly
ingestion, must be avoided. If skin or clothing becomes contaminated, wash thoroughly with soap
and water.
7. Display misconnected. Check all connections. Ensure no I/O pads are bridged.
8. Signal levels incorrect. Insure data bus components have CMOS or TTL level outputs. Measure
2.4VDC min. for logic high and I/O connections on display.
9. Power supply out of tolerance or "dirty". Check +5VDC and ground.

Outcomes