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.

Matlab -> F28335 -> LCD display

Other Parts Discussed in Thread: TMS320F28335, CCSTUDIO

Hi, I want to make a program in Matlab (simulink) which will display a data on the lcd display HD444780 attached to F28335.

I'm using Matlab with CCstudio 3.3 with TMS320F28335 Experimenter Kit.

I make the program in CCStudio which I use to interface with LCD and it works fine. I used 4-bit interface and connected to the pins:

LCD F28335

D7

D6

D5

D4

E

RS

- GPIO34

- GPIO32

- GPIO30

- GPIO28

- GPIO87

- GPIO22

 

and for example here is the part of the code, the function for the init LCD display:

void Gpio_init_lcd(void)
{
    short j;
    Gpio_select();
// ----------------------------------------------------
    for(j=0; j<100; j++)
        DELAY_US(500);
// -------- Function set ---------------------------
    GpioDataRegs.GPASET.bit.DB5 = 0x1;//Set DB5
    f_send();
    f_send();
    GpioDataRegs.GPACLEAR.bit.DB5 = 0x1;//Clear DB5
    GpioDataRegs.GPBSET.bit.DB7 = 0x1;//Set DB7
    f_send();
// --------- Delay more than 39 uS-------
    DELAY_US(500);
// -------- Display on/off control --------
    GpioDataRegs.GPBCLEAR.bit.DB7 = 0x1;//Clear DB7
    GpioDataRegs.GPACLEAR.bit.DB5 = 0x1;//Clear DB5
    f_send();
    GpioDataRegs.GPBSET.bit.DB7 = 0x1;//Set DB7
    GpioDataRegs.GPBSET.bit.DB6 = 0x1;//Set DB6
    GpioDataRegs.GPASET.bit.DB5 = 0x1;//Set DB5
    GpioDataRegs.GPASET.bit.DB4 = 0x1;//Set DB4
    f_send();
// --------- Delay more than 39 uS-------
    DELAY_US(50);
// --------- Display clear -----------------
    GpioDataRegs.GPBCLEAR.bit.DB7 = 0x1;//Clear DB7
    GpioDataRegs.GPBCLEAR.bit.DB6 = 0x1;//Clear DB6
    GpioDataRegs.GPACLEAR.bit.DB5 = 0x1;//Clear DB5
    GpioDataRegs.GPACLEAR.bit.DB4 = 0x1;//Clear DB4
    f_send();
    GpioDataRegs.GPASET.bit.DB4 = 0x1;//Set DB4
    f_send();
// --------- Delay more than 1.53 mS-------
    for(j=0; j<20; j++)
        DELAY_US(100);
// --------- Entry mode set -----------------
    GpioDataRegs.GPACLEAR.bit.DB4 = 0x1;//Clear DB4
    f_send();
    GpioDataRegs.GPBSET.bit.DB6 = 0x1;//Set DB6
    GpioDataRegs.GPASET.bit.DB5 = 0x1;//Set DB5
    f_send();
    f_string("Testing LCD");
}

Now, I have no idea how to implement this with the simulink?

I want to make the block in the simulink which I will use when I need to interface with LCD, but have no idea how and where to start?

I was thinking to make interface via SPI interface and connection LCD with 74HC595 ,but first I would like to know how to implement the above code with the simulink.

Btw I know how to implement all blocks in the simulink library "Target support package" for C2000/F28335.

  • I've sent this over to The Mathworks, hopefully Greg will reply here in the next couple days.

    I don't get to use their tools, but I thought you could just create your own block with your function code.

     

  • Hi,

     

      There are a couple of ways to address this. Both methods mentioned below leverage the C-code you have already written above. In both of the cases below, the C source files and header files that contain the source code above must be available for compilation. If you have questions about this aspect, reply to this thread.

     

    1. Since you already have the C-code written, the simplest way is probably making a Simulink block using the Legacy Code Tool.

    The Legacy Code Tool ships with Simulink. It can be used to generate the necessary wrappers to create a Simulink block based on existing C-code functions.

    For more information regarding the Legacy Code Tool, enter

      >>doc legacy_code

    at the MATLAB Command Prompt, or visit the following web address:

    http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/legacy_code.html

     

    The "See Also" section of this documentation page includes some additional links that you should also find useful.

    The basic premise behind the Legacy Code Tool is you define the function interface, and the tool wraps the necessary interface with the appropriate code so it can be called by Simulink and Real-Time Workshop.

    2. The Embedded MATLAB Function block does allow calling C-functions directly using the eml.ceval function. For more information regarding this function, visit the following documentation page:

      http://www.mathworks.com/access/helpdesk/help/toolbox/eml/ref/eml.ceval.html

     

    The problem in this case is configuring the GPIO requires some sort of initialization routine, which the Embedded MATLAB Function block does not have directly.  There are two primary ways around this:

      a. Use the System Initialize or Model Initialize blocks from the Real-Time Workshop library in Simulink. These blocks allow you to have custom C-code included in the initialization function in the generate C-code. For more information, view the following documentation page:

      http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/ref/systeminitialize.html

      b. Create a initialization branch at the top of the Embedded MATLAB source code in the Embedded MATLAB Code function block. A common way to do this is to use a PERSISTENT variable. The top of the source code would look something like:

    %%BEGIN CODE

      persisent firstTime;

      if isempty(firstTime)

        firstTime = false;

        eml.ceval('gpio_initialization_routine')

      end

    %% END CODE

     

     

  • Hi, thanks for the replay and I will analyze it, by the way, I was thinking to crate some simulink model like this one on the picture, then make a subsystem and use it when I want to interface with LCD, but it seems to be complicated to get what I want.

     

     

     

    Ok, now I will try to realize one of your suggestions and go back here.

  • Dear all,

     

    I am interested on the LCD control via simulink, no by C code (it will be generated by matlab). Any news about a functional block?

     

    Best Regards,

  • Hello Jaime,

       you can use the sci block from embedded coder - Embedded targets - Processors - Texas Instruments C2000 - C28x38x.

    Add a constant block- change the value to - for e.g.

    abs('This is test') and connect it to SCI transmit block.

    abs function will convert string to ascii code.

  • Hi Powers,

    Did you try this simulink model? I need a keypad and LCD interface model for F28335. I appreciate your help if you can send some mdl files if you have.