User manual
543
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Library Example
This example demonstrates how to communicate Lcd in 8-bit mode via the SPI module, using serial to parallel convertor
MCP23S17.
Copy Code To Clipboard
program Spi_Lcd8;
var text : array[16] of char;
var counter : byte;
// Port Expander module connections
var SPExpanderRST : sbit at LATF0_bit;
var SPExpanderCS : sbit at LATF1_bit;
var SPExpanderRST_Direction : sbit at TRISF0_bit;
var SPExpanderCS_Direction : sbit at TRISF1_bit;
// End Port Expander module connections
procedure Move_Delay(); // Function used for text moving
begin
Delay_ms(500); // You can change the moving speed here
end;
begin
text := ‘mikroE’;
SPI1_Init(); // Initialize SPI interface
// If Port Expander Library uses SPI2 module
// SPI2_Init(); // Initialize SPI module used with PortExpander
Spi_Lcd8_Cong(0); // Intialize LCD in 8bit mode via SPI
Spi_Lcd8_Cmd(_LCD_CLEAR); // Clear display
Spi_Lcd8_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Spi_Lcd8_Out(1,6, text); // Print text to LCD, 1st row, 6th column...
Spi_Lcd8_Chr_CP(‘!’); // Append ‘!’
Spi_Lcd8_Out(2,1, ‘mikroelektronika’); // Print text to LCD, 2nd row, 1st
column...
// Spi_Lcd8_Out(3,1, text); // For LCD modules with more than two rows
// Spi_Lcd8_Out(4,15, text); // For LCD modules with more than two rows
Delay_ms(2000);
// Moving text
for counter := 0 to 3 do // Move text to the right 4 times
begin
Spi_Lcd8_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
end;