Help with 2004a LCD and SPLC780D ~ DB0-DB7

Thread Starter

Samuel3589

Joined Apr 25, 2019
4
Hi,
I'm trying to write on the 2nd and 4th line of my 2004a LCD.
Im using it in parallel (DB0-DB7) and not in I2C. Therefore I have to manually write.
For now, in both 1- and 2-row configuration when I write something it gets displayed on the 1st row and then it goes to the 3rd row as expected.
I would like to be able to address the 2nd and 4th row too but in the SPLC780D Datasheet as well as online I couldn't find any help.
Whit SetDDRAMLCD() it doesn't seem like it's working right even if i use the same commands as in the datasheet example.
Attached is the LCD.c I'm using


Code:
//###########################################################################
//
// FILE:    LCD.c
//
// TITLE:    Driver for LCD 
//
//###########################################################################

//  V E R S I O N I
//
//
//   V1.0:  23.8.2020      versione iniziale
// Included Files
//
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include "LCD.h"

void InitLCDGpio()
{ 
    EALLOW;

    //
    // Enable internal pull-up for the selected pins
    // Pull-ups can be enabled or disabled by the user.
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0;   // Enable pull-up for GPIO0 (E)
    GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;   // Enable pull-up for GPIO19 (RS)
    GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0;   // Enable pull-up for GPIO1 (D0)
    GpioCtrlRegs.GPBPUD.bit.GPIO44 = 0;   // Enable pull-up for GPIO44 (D1)
    GpioCtrlRegs.GPAPUD.bit.GPIO2 = 0;   // Enable pull-up for GPIO2 (D2)
    GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0;   // Enable pull-up for GPIO3 (D3)
    GpioCtrlRegs.GPAPUD.bit.GPIO4 = 0;   // Enable pull-up for GPIO4 (D4)
    GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;   // Enable pull-up for GPIO16 (D5)
    GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;   // Enable pull-up for GPIO17 (D6)
    GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;   // Enable pull-up for GPIO13 (D7)

    //
    // Set qualification for selected pins to asynch only
    // This will select asynch (no qualification) for the selected pins.
    // Comment out other unwanted lines.
    //
    /*GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3;  // Asynch input GPIO32 (SDAA)
    GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3;  // Asynch input GPIO33 (SCLA)*/

    //
    // Configure LCD pins using GPIO regs
    // This specifies which of the possible GPIO pins will be LCD
    // functional pins. Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;   // Configure GPIO0 for GPIO0                        v
    GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 0;   // Configure GPIO19 for GPIO19 WARNING: USING GPAMUX2
    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;   // Configure GPIO1 for GPIO1
    GpioCtrlRegs.GPBMUX1.bit.GPIO44 = 0;
    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;   // Configure GPIO2 for GPIO2
    GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;   // Configure GPIO3 for GPIO3
    GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0;   // Configure GPIO4 for GPIO4                          v
    GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 0;   // Configure GPIO16 for GPIO16 WARNING: USING GPAMUX2  v
    GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 0;   // Configure GPIO17 for GPIO17    WARNING: USING GPAMUX2
    GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;   // Configure GPIO13 for GPIO13

    GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;   // Configure GPIO0 as output
    GpioCtrlRegs.GPADIR.bit.GPIO19 = 1;   // Configure GPIO19 as output
    GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;   // Configure GPIO1 as output
    GpioCtrlRegs.GPBDIR.bit.GPIO44 = 1; // Configure GPIO44 as output
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;   // Configure GPIO2 as output
    GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;   // Configure GPIO3as output
    GpioCtrlRegs.GPADIR.bit.GPIO4 = 1;   // Configure GPIO4 as output
    GpioCtrlRegs.GPADIR.bit.GPIO16 = 1;   // Configure GPIO16 as output
    GpioCtrlRegs.GPADIR.bit.GPIO17 = 1;   // Configure GPIO17 as output
    GpioCtrlRegs.GPADIR.bit.GPIO13 = 1;   // Configure GPIO13 as output
    
    EDIS;
}

///
///     Function that write a string to the LCD
///     Input:  Data: String o characters (max 40)
///     RS: 0 = Instruction Register
///               1 = Data Register
///   Max Data length = 40 (20 on the first line and 20 on the 3rd line)
///   To be implemented yet: Write up to 80 characters and dived on the four lines
///
 
void writeByte2LCD(char Data, char RS)
{
    // set bit to parallel port
    // ATTENTION! DO NOT USE GPxDAT because use read modify write and 
    // you must wait some time before changing the next bit if not
    // the valure is not correct 
    //see SPRUH18H–January2011–RevisedNovember2019 chapter 1.5.3
    
    
    
    if (RS & D0_MASK) GpioDataRegs.GPASET.bit.GPIO19 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO19 = 1; 
    
    // set E to 1
    GpioDataRegs.GPASET.bit.GPIO0 = 1;
    
    // SET or CLEAR the DataBus BIT
    //D0
    if (Data & D0_MASK) GpioDataRegs.GPASET.bit.GPIO1 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO1 = 1; 
    
    //D1
    if (Data & D1_MASK) GpioDataRegs.GPBSET.bit.GPIO44 = 1;
        else GpioDataRegs.GPBCLEAR.bit.GPIO44 = 1; 
     
    //D2
    if (Data & D2_MASK) GpioDataRegs.GPASET.bit.GPIO2 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO2 = 1;
        
    //D3
    if (Data & D3_MASK) GpioDataRegs.GPASET.bit.GPIO3 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO3 = 1;
        
    //D4
    if (Data & D4_MASK) GpioDataRegs.GPASET.bit.GPIO4 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO4 = 1;
        
     //D5
    if (Data & D5_MASK) GpioDataRegs.GPASET.bit.GPIO16 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO16 = 1;
    
     //D6
    if (Data & D6_MASK) GpioDataRegs.GPASET.bit.GPIO17 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO17 = 1;
        
    //D7
    if (Data & D7_MASK) GpioDataRegs.GPASET.bit.GPIO13 = 1;
        else GpioDataRegs.GPACLEAR.bit.GPIO13 = 1;
    //wait 2us
    DELAY_US(2);
    //set E to 0
    GpioDataRegs.GPACLEAR.bit.GPIO0 = 1;
    // wait 100us
     DELAY_US(100);
}

void SetDDRAMLCD(int address){
    writeByte2LCD(0x80|address,0);
        DELAY_US(3000);
}

void ClearLCD()
{
     writeByte2LCD(0x01, 0);
     // wait at least 1.16ms
     DELAY_US(3000); 
}

void ReturnCursorHomeLCD()
{
     writeByte2LCD(0x02, 0);
     // wait at least 1.16ms
     DELAY_US(3000); 
}

void InitLCD()
{
    // Function SET: select 8 bit interface and 2 lines and 5 x 8 dots
     writeByte2LCD(0x30, 0);
     // wait 100us
     DELAY_US(100);
     // DISPLAY ON/OFF CONTROL:
     // Display ON
     // CURSOR ON
     // BLINK OFF
     writeByte2LCD(0x0E, 0);
     DELAY_US(100);
     //ENTRY SET MODE
     // Mouving direction right
     // no shift
     writeByte2LCD(0x06, 0);
     DELAY_US(100);
     ClearLCD();
}

void InitLCD1()
{
    // Function SET: select 8 bit interface and 2 lines and 5 x 8 dots
     writeByte2LCD(0x30, 0);
     // wait 100us
     DELAY_US(100);
     // DISPLAY ON/OFF CONTROL:
     // Display ON
     // CURSOR OFF
     // BLINK OFF
     writeByte2LCD(0x0C, 0);
     DELAY_US(100);
     //ENTRY SET MODE
     // Mouving direction right
     // no shift
     writeByte2LCD(0x06, 0);
     DELAY_US(100);
     ClearLCD();
}

void WriteStringLCD(char *str) 
{
    while (*str)
    {
        writeByte2LCD(*str, 1);
        str++;
        DELAY_US(100);
    }
}
 

jpanhalt

Joined Jan 18, 2008
11,088
I don't do C and cannot find where you are setting the cursor to the desired line. Are you doing something like this (numbers are hex):

1604316300825.png
 

Thread Starter

Samuel3589

Joined Apr 25, 2019
4
I don't do C and cannot find where you are setting the cursor to the desired line. Are you doing something like this (numbers are hex):

View attachment 221244
Thank you for your answer.
I'm figuring out that the problem is not the code (for now) but it's something with the voltages. Only 2 lines were active/responsive to the contrast (line 0 and line 2). So I guess this is why I didn't saw line 1 and line 3. I was using +3.3 V and when I switched to +5V Vcc for the display now all the lines are displayed. The contrast is off between line 0-2 and 1-3 tho. I thought they would behave all the same way with the voltages but apparently not
 
Top