serg wrote:Hi Hugoneus,
We have prepared a simple example which demonstrates direct sub20.dll calls from Matlab
% ------------------------------------------------------------------------------
% The following example demonstrates direct sub20.dll calls
% The main disadvantages of this method (in contrast to the .NET interface) are:
% -incompatible data types
% -numeric constants from the libsub.h are not available
% ------------------------------------------------------------------------------
loadlibrary('C:\WINDOWS\system32\sub20.dll', 'C:\Program Files\SUB-20\inc\libsub.h')
% Open first available SUB-20 device
hSub20=calllib('sub20', 'sub_open', libpointer);
str='Hello world !';
% Write to the LCD
status=calllib('sub20', 'sub_lcd_write', hSub20, str);
% config spi, i.e SPI_ENABLE+SPI_CPOL_RISE+SPI_SMPL_SETUP+SPI_MSB_FIRST+SPI_CLK_4MHZ,
% see libsub.h for details
status=calllib('sub20', 'sub_spi_config', hSub20, hex2dec('40'), libpointer);
% send string str over SPI. Use SS2 SS_LO, see libsub.h for details
status=calllib('sub20', 'sub_spi_transfer', hSub20, str, libpointer, length(str), hex2dec('25'));
% close the device
status=calllib('sub20', 'sub_close', hSub20);
% ------------------------------------------------------------------------------
Regards
thanks you
your reply is very good.
str = str='Hello world !';
status=calllib('sub20', 'sub_lcd_write', hSub20, str);
status=calllib('sub20', 'sub_spi_config', hSub20, hex2dec('40'), libpointer)
This LCD have to demo display as GUI in the matlab, or We work LCD display connection with PC output signal out as COM or USB.
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.
Before writing to the LCD display, a set of commands must be issued to configure the LCD for the data write operation. These are:
1. Waiting: Wait for display to get ready after power-on.
Value: 0x00
Execution Time: 15 ms = 750000 cycles
2. Function Set: This is used to set the number of display lines, the character font and the data length (in bits)
Value used*: 0x3C
Execution Time: 8.4 ms = 420000 cycles
* Please note that some of the value used can be changed by setting the DB0 and DB1. Please refer to the user manual for details.
3. Set Display On: Turn the display on, cursor off and cursor position off.
Value used: 0x0C
Execution Time: 4.2 ms = 210000 cycles
4. Clear Display:
Value used: 0x01
Execution Time: 4.2 ms = 210000 cycles
5. Entry Mode Set: This is a powerful command! It can be used to set the direction in which the cursor moves and to specify whether to shift the display or not.
Value used: 0x06
Execution Time: 4.2 ms = 210000 cycles
Once the LCD is configured for writing, the characters to be displayed can be transferred:
1. Char_h:
Value: 0x48
Execution Time: 4.2 ms = 210000 cycles
2. Char_o:
Value: 0x4F
Execution Time: 4.2 ms = 210000 cycles
3. Char_l:
Value: 0x4C
Execution Time: 4.2 ms = 210000 cycles
4. Char_a:
Value: 0x41
Execution Time: 4.2 ms = 210000 cycles
After writing the characters, it is good to wait for additional 4.2 ms (210000 cycles) before exiting the program.