User manual

mikroBasic PRO for PIC32
MikroElektronika
483
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
dim text as char[16]
dim counter as byte
‘ Port Expander module connections
dim SPExpanderRST as sbit at LATD8_bit
dim SPExpanderCS as sbit at LATD9_bit
dim SPExpanderRST_Direction as sbit at TRISD8_bit
dim SPExpanderCS_Direction as sbit at TRISD9_bit
‘ End Port Expander module connections
sub procedure Move_Delay() ‘ Function used for text moving
Delay_ms(500) ‘ You can change the moving speed here
end sub
main:
CHECON = 0x32
AD1PCFG = 0xFFFF ‘ Congure AN pins as digital
text = “mikroElektronika”
‘ If Port Expander Library uses SPI2 module
‘ Initialize SPI module used with PortExpander
SPI2_Init_Advanced(_SPI_MASTER,_SPI_8_BIT, 4, _SPI_SS_DISABLE,_SPI_DATA_SAMPLE_
MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_ACTIVE_2_IDLE)
Spi_Lcd8_Cong(0) ‘ Initialize LCD over SPI interface
Spi_Lcd8_Cmd(_LCD_CLEAR) ‘ Clear display
Spi_Lcd8_Cmd(_LCD_CURSOR_OFF) ‘ Turn cursor off
Spi_Lcd8_Out(1,6, “mikroE”) ‘ Print text to LCD, 1st row, 6th column
Spi_Lcd8_Chr_CP(“!”) ‘ Append ‘!’
Spi_Lcd8_Out(2,1, text) ‘ Print text to LCD, 2nd row, 1st column
‘ Spi_Lcd8_Out(3,1,’mikroE’) ‘ For LCD with more than two rows
‘ Spi_Lcd8_Out(4,15,’mikroE’) ‘ For LCD with more than two rows
Delay_ms(2000)
‘ Moving text
for counter = 0 to 3 ‘ Move text to the right 4 times
Spi_Lcd8_Cmd(_LCD_SHIFT_RIGHT)
Move_Delay()
next counter