This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28027: INTERFACING LCD

Part Number: TMS320F28027

Tool/software: Code Composer Studio

Hello Everyone I am a Newbie to this ti controller , actually I am trying to interface a 1602A LCD with F28027 controller in 4 bit mode ,I have done the interfacing with avr and arduino before and while shifting the data bit we use to use PORT command which gave us access to all 4 pins at once but as far as I know in Ti GPIO are all accessed  individually ,Then how can we interface a LCD in 4 bit mode?

  • You mean writing new values to several pins at once? As long as the pins are in the same data register, you can do that. You just use .all instead of .bit. For example if you wanted to write to GPIOs 0-3 at the same time you could do something like

    temp = GpioDataRegs.GPADAT.all;
    GpioDataRegs.GPADAT.all = (temp & ~(0xF)) | newValue;

    Does that clear it up or did I misunderstand the question?

    Whitney
  • Thank You for replying!!!

    The suggestion you gave  is i think really good i tried it but can you please help me in how it declare temp variable as i tried a lot but everytime it shows a error :

    #28 expression must have a constant value 

    Also ,can you please help know how to select the 0x__ value anding with temp for a exact gpio that we want?

    Thanks in Advance

    Regards

  • You should just be able to declare temp as any 32-bit unsigned type like uint32_t.

    ~(0xF) is a mask used to clear the previous value written to the register so you can overwrite them. In my example, I was just writing to GPIOs 0-3, so I picked ~(0xF) to clear the bottom 4 bits. You'll just need to widen the mask and shift it around according to which GPIOs/bits you want to cover. To give another example, GPIO22-GPIO26 would be ~(0x07C00000) or ~(0x1FUL << 22).

    Whitney
  • Thank You!!!

    As a Newbie to TI i thought to interface LCD in * bit mode and then move to 4 bit mode ,walking on the same path i wrote the following code for 8 bit mode but the Lcd isn't working i.e 1st line comes all black .


    #include "F2802x_Device.h"
    #include "f2802x_examples.h"



    void SendByte(unsigned char Value)
    {
    unsigned char temp;

    if((Value & 0x01) == 0x01)
    GpioDataRegs.GPASET.bit.GPIO0 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO0 =1;

    if((Value & 0x02) == 0x02)
    GpioDataRegs.GPASET.bit.GPIO1 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO1 =1;

    if((Value & 0x04) == 0x04)
    GpioDataRegs.GPASET.bit.GPIO2 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO2 =1;

    if((Value & 0x08) == 0x08)
    GpioDataRegs.GPASET.bit.GPIO3 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO3 =1;

    if((Value & 0x10) == 0x10)
    GpioDataRegs.GPASET.bit.GPIO4 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO4 =1;

    if((Value & 0x20) == 0x20)
    GpioDataRegs.GPASET.bit.GPIO5 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO5 =1;

    if((Value & 0x40) == 0x40)
    GpioDataRegs.GPASET.bit.GPIO6 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO6 =1;

    if((Value & 0x80) == 0x80)
    GpioDataRegs.GPASET.bit.GPIO7 =1;
    else
    GpioDataRegs.GPACLEAR.bit.GPIO7 =1;

    GpioDataRegs.GPASET.bit.GPIO19 =1;
    for(temp=0;temp<5; temp++);
    GpioDataRegs.GPACLEAR.bit.GPIO19 =1;
    DELAY_US(500);
    }

    void WriteCommandLCD(unsigned char CommandByte)
    {
    SendByte(CommandByte);
    GpioDataRegs.GPACLEAR.bit.GPIO12=1;
    GpioDataRegs.GPASET.bit.GPIO19=1;
    DELAY_US(1);
    GpioDataRegs.GPACLEAR.bit.GPIO19=1;
    DELAY_US(3000);
    }

    void DisplayLCD(char LineNumber,char *Mes)
    {


    int a=0;
    if(LineNumber == 1)
    { //First Line
    WriteCommandLCD(0x80); //Select the first line
    }
    else
    { //Second line
    WriteCommandLCD(0xC0); //Select the second line
    }

    // SendByte(Mes);

    for(a=0;a<16;a++)
    {
    SendByte(*Mes); //Display a character
    GpioDataRegs.GPASET.bit.GPIO12=1;
    GpioDataRegs.GPASET.bit.GPIO19=1;
    DELAY_US(80);
    GpioDataRegs.GPACLEAR.bit.GPIO19=1;
    DELAY_US(80);
    Mes++; //Increment pointer
    }

    }

    void InitializeLCD(void)
    {

    DELAY_US(100000);

    WriteCommandLCD(0x38);
    DELAY_US(5000);

    WriteCommandLCD(0x38);
    DELAY_US(500);

    WriteCommandLCD(0x38);
    DELAY_US(500);

    WriteCommandLCD(0x38);
    DELAY_US(10);

    WriteCommandLCD(0x08);
    DELAY_US(10);

    WriteCommandLCD(0x01);
    DELAY_US(10);


    WriteCommandLCD(0x06);
    DELAY_US(10);

    WriteCommandLCD(0x80);
    DELAY_US(10);

    }

    void main(void)
    {

    EALLOW;
    GpioCtrlRegs.GPAMUX1.all = 0x00000000;
    GpioCtrlRegs.GPAMUX2.all = 0x00000000;
    GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO4 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO5 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO6 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO7 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;
    GpioCtrlRegs.GPADIR.bit.GPIO19 = 1;
    EDIS;

    InitializeLCD();
    DELAY_US(1000000);
    DisplayLCD(1,"AAAAAAAAAA");
    DisplayLCD(2,"AAAAAAAAAA");

    for(;;) {
    GpioDataRegs.GPATOGGLE.bit.GPIO0=1;
    DELAY_US(1000000);
    }

    //return 0;
    }



    Can You help help know if there is any problem in Code?

    Thanks in Advance.
  • Having no familiarity with your LCD, it's hard for me to judge the correctness of your GPIO configuration, but there's nothing obviously wrong with it at least. I do recommend adding some device initialization to the start of main() though. You should at least call our InitSysCtrl() function to disable the watchdog and configure the system clock so those delays will behave as expected.

    Whitney
  • Also, for future reference, when sharing code please use the code formatting tool marked by the </> button. This tool can be located by clicking the "Insert Code, Attach Files, and more" link on the bottom right hand side of the Reply menu. It makes code much easier to follow. Thanks!