NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, B.tech projects, M.tech projects, online Embedded C training

Interfacing Graphical LCD JHD 128x64E with TI Stellaris Launch pad LM4F120XL

Interfacing diagram:
Hello! Every one, in this tutorial I am going to show how to interface the GLCD with stellaris launch pad LM4F120XL processor. I have searched a lot around the internet but I didn’t get any proper details to interface GLCD with TI stellaris launch pad. Well! Here I am using JHD 128x64E GLCD. This GLCD contains 20 pins, out of these 8 data lines (D0-D7), 5 control lines (EN, RW, RS, CS1, CS2). The interfacing diagram is shown below.

Interfacing diagram for GLCD (JHD 128x64E) with Stellaris launch pad LM4F120XL




The data lines (D0-D7) of the GLCD are connected to GPIO PORTB (PB0-PB7) of the Stellaris LM4F120XL processor. The GLCD contains two segments, to enable these segments there are two control lines (CS1 and CS2) are available on the GLCD. According to the JHD 128x64E data sheet, these signals are active low signals. To enable any one of these segments, an active low signal is provided on these control lines. The other control lines like Enable, Read/Write, and RS are connected to GPIO PORTE (PE3, PE2, and PE1) respectively. Vcc should be 5v, Vee is -5v and a 10k preset is connected to V0 pin of the GLCD to adjust the contrast. Stellaris operated with 3.3v, but the GLCD is operated with 4-6v. Join both stellaris launch pad and GLCD ground pins, otherwise you won’t get proper animation or characters on the display.

Program code:
/*******************************************************************************************/
Graphical LCD working perfectly - printing dots on the GLCD.
Author: kiranvarma
/*******************************************************************************************/
#include "inc/lm4f120h5qr.h"
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "font5x8.h"


unsigned int delay_value = 10 ;

volatile unsigned long ulLoop;

//*****************************************************************************
// PORTB is defined as data lines for graphical LCD
//*****************************************************************************

#define LCD_DATA_PERIPH        SYSCTL_PERIPH_GPIOB  // LCD data port
#define LCD_DATA_BASE          GPIO_PORTB_BASE
#define LCD_DATA            0xFF

//*****************************************************************************
// define control pins of GLCD 128x64
//*****************************************************************************
#define LCD_CS1_PERIPH           SYSCTL_PERIPH_GPIOA  // column 1 select
#define LCD_CS1_BASE             GPIO_PORTA_BASE
#define LCD_CS1_PIN              GPIO_PIN_2
#define LCD_CS2_PERIPH           SYSCTL_PERIPH_GPIOA  // column 1 select
#define LCD_CS2_BASE             GPIO_PORTA_BASE
#define LCD_CS2_PIN              GPIO_PIN_3
#define LCD_RST_PERIPH           SYSCTL_PERIPH_GPIOA   //Reset pin
#define LCD_RST_BASE             GPIO_PORTA_BASE
#define LCD_RST_PIN              GPIO_PIN_4
#define LCD_DI_PERIPH            SYSCTL_PERIPH_GPIOE  // DATA or INSTRUCTION (RS)
#define LCD_DI_BASE              GPIO_PORTE_BASE
#define LCD_DI_PIN               GPIO_PIN_3
#define LCD_RW_PERIPH            SYSCTL_PERIPH_GPIOE  // Read or Write pin
#define LCD_RW_BASE              GPIO_PORTE_BASE
#define LCD_RW_PIN               GPIO_PIN_2
#define LCD_EN_PERIPH            SYSCTL_PERIPH_GPIOE  // Enable Pin
#define LCD_EN_BASE              GPIO_PORTE_BASE
#define LCD_EN_PIN               GPIO_PIN_1




void delayms(unsigned int value)
{
 unsigned int i;
 for(i=0;i PORTE.1
 delayms(delay_value);
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_1; // EN = 0
 delayms(delay_value);

}

void GLCD_ON()
{

 //enable both chips on Graphical LCD
 GPIO_PORTA_DATA_R |= GPIO_PIN_2;   // CS1 = 0 --> PA2, both are active low signals -- '0' must be provide to enable
 GPIO_PORTA_DATA_R |= GPIO_PIN_3;   // CS2 = 0 --> PA3

 // for command transfer
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_3;  // DI or RS = 0 --> PE3 (command)
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_2;  // RW = 0 --> PE2 (write)

 // command to ON 0x3F
 GPIO_PORTB_DATA_R = 0x3F;
 glcd_enable_pulse();
}


void Set_Start_Line(unsigned char linenum)
{
 //enable both chips on Graphical LCD
 GPIO_PORTA_DATA_R &= ~GPIO_PIN_2;   // CS1 = 0 --> PA2, both are active low signals -- '0' must be provide to enable
 GPIO_PORTA_DATA_R &= ~GPIO_PIN_3;   // CS2 = 0 --> PA3

 // for command transfer
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_3;  // DI = 0 --> PE3 (command)
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_2;  // RW = 0 --> PE2 (write)

 // command on PORTB
 GPIO_PORTB_DATA_R = (0xC0 | linenum);
 glcd_enable_pulse();
}




void GLCD_Write(unsigned short b)
{
 // for DATA write operation DI = 1, for command write operation DI = 0
 // for data transfer
 GPIO_PORTE_DATA_R |= GPIO_PIN_3;  // DI = 1 --> PE3 (data)
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_2;  // RW = 0 --> PE2 (write)

 GPIO_PORTB_DATA_R = b;            //put data on data port
 delayms(10);
 glcd_enable_pulse();
}


unsigned short GLCD_Read(unsigned short column)
{
 unsigned short read_data = 0; //Read data here

 GPIO_PORTB_DIR_R = 0x00;//Make PORTB as Input

 // for data read
 GPIO_PORTE_DATA_R |= GPIO_PIN_3; //DI = 1 --> PE3 (data)
 GPIO_PORTE_DATA_R |= GPIO_PIN_2; //RW = 1 --> PE2 (read)

 // if column is greater than 63 then de-activate CS1 (CS1 = 1) and activate CS2 (CS2 = 0)

 if(column>63)
 {
  GPIO_PORTA_DATA_R &= ~GPIO_PIN_2;   // CS1 = 0 --> PA2 -- CS1 controller(left side) -- De-activated
  GPIO_PORTA_DATA_R |= GPIO_PIN_3;   // CS2 = 1 --> PA3 -- CS2 controller(right side) -- activated
 }
 else
 {
  GPIO_PORTA_DATA_R |= GPIO_PIN_2;   // CS1 = 1 --> PA2 -- CS1 controller(left side) -- activated
  GPIO_PORTA_DATA_R &= ~GPIO_PIN_3;   // CS2 = 0 --> PA3 -- CS2 controller(right side) -- De-Activated
 }

 GPIO_PORTE_DATA_R |= GPIO_PIN_1; // EN = 1 -> PORTE.1
 delayms(delay_value);
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_1; // EN = 0
 delayms(delay_value);
 GPIO_PORTE_DATA_R |= GPIO_PIN_1; // EN = 1 -> PORTE.1
 delayms(delay_value);

 read_data = GPIO_PORTB_DATA_R;    //Input data

 GPIO_PORTE_DATA_R &= ~GPIO_PIN_1; // EN = 0
 delayms(delay_value);
 GPIO_PORTB_DIR_R = 0xFF;     //Output again
 return read_data;
}

void GOTO_COL(unsigned int x)
{
 unsigned short Col_Data;
 // for command transfer
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_3;  // RS/DI = 0 --> PE3 (command)
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_2;  // RW = 0 --> PE2 (write)

 if(x<64)             //left chip section
 {
  GPIO_PORTA_DATA_R |= GPIO_PIN_2;   // CS1 = 1 --> PA2 -- CS1 controller(left side) -- activated
  GPIO_PORTA_DATA_R &= ~GPIO_PIN_3;   // CS2 = 0 --> PA3 -- CS2 controller(right side) -- De-Activated
  Col_Data = x;              //put column address on data port
 }
 else                 //right chip section
 {

  GPIO_PORTA_DATA_R &= ~GPIO_PIN_2;   // CS1 = 0 --> PA2 -- CS1 controller(left side) -- De-activated
  GPIO_PORTA_DATA_R |= GPIO_PIN_3;   // CS2 = 1--> PA3 -- CS2 controller(right side) -- activated
  Col_Data = x-64;   //put column address on data port
 }

 Col_Data = (Col_Data | 0x40 ) & 0x7F;  //Command format
 GPIO_PORTB_DATA_R = Col_Data;
 glcd_enable_pulse();
}

void GOTO_ROW(unsigned int y)  // page selection
{
 unsigned short Col_Data;
 // for command transfer
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_3;  // DI = 0 --> PE3 (command)
 GPIO_PORTE_DATA_R &= ~GPIO_PIN_2;  // RW = 0 --> PE2 (write)
 Col_Data = (y | 0xB8 ) & 0xBF; //put row address on data port set command
 GPIO_PORTB_DATA_R = Col_Data;
 glcd_enable_pulse();
}

void GOTO_XY(unsigned int x,unsigned int y)
{
 GOTO_COL(x);
 GOTO_ROW(y);
}

void GLCD_Clrln(unsigned short ln)
{
 int i;

 GOTO_XY(0,ln);      //At start of line of left side
 GPIO_PORTA_DATA_R |= GPIO_PIN_2;    // LEFT HALF OF THE SCREEN IS SELECTED,CS1 = 1 and CS2 = 0
 GPIO_PORTA_DATA_R &= ~GPIO_PIN_3;
 for(i=0;i<64;i++)
  GLCD_Write(0);

 GOTO_XY(64,ln);      //At start of line of right side
 GPIO_PORTA_DATA_R &= ~GPIO_PIN_2;    // Right HALF OF THE SCREEN IS SELECTED,CS1 = 0 and CS2 = 1
 GPIO_PORTA_DATA_R |= GPIO_PIN_3;
 for(i=64;i<128;i++)
  GLCD_Write(0);
}


void GLCD_CLR()
{
 unsigned short m;
 for(m=0;m<8;m++){
  GLCD_Clrln(m);
 }
}

void Draw_Point(unsigned short x,unsigned short y, unsigned short color)
{
 unsigned short Col_Data;;
 GOTO_XY(x,(y/8));
 switch (color)
 {
 case 0:         //Light spot
  Col_Data = ~(1<<(y%8)) & GLCD_Read(x);
  break;
 case 1:         //Dark spot
  Col_Data = (1<<(y%8)) | GLCD_Read(x);
  break;
 }
 GOTO_XY(x,(y/8));
 GLCD_Write(Col_Data);
}




void main(void)
{
 unsigned short u, v;
 setup();
 delayms(delay_value);

 GPIO_PORTA_DATA_R &= ~GPIO_PIN_2; // de-activate the chips
 GPIO_PORTA_DATA_R &= ~GPIO_PIN_3;
 GPIO_PORTA_DATA_R &= ~GPIO_PIN_4; // RST active low - reset applied
 delayms(1000);
 GPIO_PORTA_DATA_R |= GPIO_PIN_4; // RST
 GLCD_ON();
 GLCD_CLR();
 Set_Start_Line(0);

 do {

  for(u=0; u<64; u+=6)
   for (v=0; v<128; v+=2)
    //GLCD_Write(1);
    Draw_Point(v, u, 1);
  delayms(100);
  GLCD_CLR();
  delayms(100);

 } while(1);

}




Video:

0 comments :

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

0 comments :

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger