Author Topic: Interfacing Character LCD 2X16 using GPIO  (Read 6458 times)

0 Members and 1 Guest are viewing this topic.

Offline marouene_joeTopic starter

  • Newbie
  • Posts: 1
Interfacing Character LCD 2X16 using GPIO
« on: February 13, 2012, 07:34:42 am »
Hello ,
I'm using STM32 F100 RB microcontroller and 2x16 character LCD.
I want to  display strings on it.(HD 44780 driver) using GPIO protocole ( GPIOB )
Who can help me about it ?
Is there any demo project  in this site ?
Can you give me a link or code , adress to help me ?
Thank's
 

Offline electrode

  • Regular Contributor
  • *
  • Posts: 141
  • Country: au
Re: Interfacing Character LCD 2X16 using GPIO
« Reply #1 on: February 13, 2012, 12:09:07 pm »
Welcome. I see you have already asked this on edaboard.

We have no way of knowing your level of experience with electronics and programming, but what you need to do is either:

a) Find a driver that's already done the hard work for you. (Does this help? I know very little about STM as a platform...)

OR

b) Write your own library. Someone on edaboard already gave you a link to get started with the HD44780 instruction set. First, work out the low-level steps to send data to the LCD - work on abstracting that to write letters and words. At the top level, you want a function like lcd_print(char *string), where you can feed it letters and away you go.
 

Offline MarkS

  • Supporter
  • ****
  • Posts: 825
  • Country: us
Re: Interfacing Character LCD 2X16 using GPIO
« Reply #2 on: February 13, 2012, 04:36:33 pm »
I did this a few years ago with a 4x40 LCD and a Parallax Propeller microcontroller. All I did was look at the HD 44780 driver datasheet and connected the necessary pins from the LCD to the MCU. Wasn't terribly difficult. I even wrote my own driver software. What are you having trouble with?
 

Offline electronicsbasecom

  • Newbie
  • Posts: 3
Re: Interfacing Character LCD 2X16 using GPIO
« Reply #3 on: February 20, 2012, 07:34:58 pm »
do you have code that can drive high and low individual pins?
if you have you are allmost done :)
here is example of LCD code that is written for AVR but by using only functions for lcd and changing only part for driving pins high and low your project will be working in no time.

Code: [Select]
//this example was taken from
//http://www.electronics-base.com/index.php/projects/complete-projects/110-avr-2x16-character-lcd-diplay-universal-code-library
//there you have detailed explanation of all lines in code if you need it..

#include <mega8.h>
#include <delay.h>
#include <stdlib.h>

#define LCD_RS    PORTD.2    // Register select
#define LCD_EN    PORTD.3    // Enable
#define LCD_D4 PORTD.4    // Data bits
#define LCD_D5 PORTD.5    // Data bits
#define LCD_D6 PORTD.6    // Data bits
#define LCD_D7 PORTD.7    // Data bits

#define    LCD_STROBE    ((LCD_EN = 1),(LCD_EN=0))
char buf[4];
char b1,b2,b3;


/*
 *    LCD interface example
 *    Uses routines from delay.c
 *    This code will interface to a standard LCD controller
 *    like the Hitachi HD44780. It uses LCD display in 4 bit mode, with
 *    the hardware connected as follows (the standard 14 pin
 *    LCD connector is used):
 *   
 *    PORTB bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
 *    PORTA bit 2 is connected to the LCD RS input (register select)
 *    PORTA bit 3 is connected to the LCD EN bit (enable)
 *   
 *    To use these routines, set up the port I/O (TRISA, TRISB) then
 *    call lcd_init(), then other routines as required.
 *
 * Copywrite Craig Lee 1998
 *   
 */

/* write a byte to the LCD in 4 bit mode */

void
lcd_write(unsigned char c)
{
    if(c & 0x80) LCD_D7=1; else LCD_D7=0;
    if(c & 0x40) LCD_D6=1; else LCD_D6=0;
    if(c & 0x20) LCD_D5=1; else LCD_D5=0;
    if(c & 0x10) LCD_D4=1; else LCD_D4=0;
    LCD_STROBE;
    if(c & 0x08) LCD_D7=1; else LCD_D7=0;
    if(c & 0x04) LCD_D6=1; else LCD_D6=0;
    if(c & 0x02) LCD_D5=1; else LCD_D5=0;
    if(c & 0x01) LCD_D4=1; else LCD_D4=0;
    LCD_STROBE;   
    delay_us(40);
}

/*
 *     Clear and home the LCD
 */

void
lcd_clear(void)
{
    LCD_RS = 0;

    lcd_write(0x1);
    delay_ms(2);
}

/* write a string of chars to the LCD */

void
lcd_puts(const char * s)
{
    LCD_RS = 1;    // write characters

    while(*s) lcd_write(*s++);
}

/* write one character to the LCD */

void
lcd_putch(unsigned char c)
{
    LCD_RS = 1;    // write characters

    lcd_write(c);
}


/*
 * Go to the specified position
 */

void
lcd_goto(unsigned char pos,unsigned char line)
{
    LCD_RS = 0;
    if (line==0)
    lcd_write(0x80 + pos);
    else
    lcd_write(0x80 + pos+ 0x40);
}
   
/* initialise the LCD - put into 4 bit mode */

void
lcd_init(void)
{
    LCD_RS = 0;    // write control bytes

    delay_ms(15);// power on delay

    LCD_D4 = 1;    // init!   
    LCD_D5 = 1; //
    LCD_STROBE;   
    delay_ms(5);

    LCD_STROBE;    // init!   
    delay_us(100);

    LCD_STROBE;    // init!   
    delay_ms(5);

    LCD_D4 = 0;    // set 4 bit mode
    LCD_STROBE;   
    delay_us(40);
   
    lcd_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
    lcd_write(0x0C);// display on
    lcd_write(0x06);// entry mode advance cursor
    lcd_write(0x01);// clear display and reset cursor
}
// Standard Input/Output functions
// Declare your global variables here
void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
//PORTA=0x00;
//DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=T State0=T
PORTD=0x00;
DDRD=0xFC;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
//OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
       
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

lcd_init();
     
while (1)
      { 
      lcd_clear();
      lcd_goto(0,0);
      lcd_puts("Vh:") ;
      itoa( b1  , buf);
      lcd_puts(buf) ;     
      lcd_putch('V'); 
      lcd_goto(8,0);
      lcd_puts("Vl:") ;
      itoa(b2  , buf);
      lcd_puts(buf) ; 
      lcd_putch('V');     
      lcd_goto(0,1);
      lcd_puts("Freq.:") ;
      itoa(b3, buf);
      lcd_puts(buf) ; 
      lcd_puts("Hz") ;     
      b1++;
      b2--;
      b3+=2;
      delay_ms(50);
      };
}

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf