Mikroelektronika MIKROE-350 Fiche De Données
Library Example
This example demonstrates how to communicate Lcd in 8-bit mode via the SPI mod-
ule, using serial to parallel convertor MCP23S17.
ule, using serial to parallel convertor MCP23S17.
program Spi_Lcd8_Test
dim text as char[16]
' Port Expander module connections
dim SPExpanderRST as sbit at PORTB.0
dim SPExpanderRST as sbit at PORTB.0
SPExpanderCS
as sbit at PORTB.1
SPExpanderRST_Direction
as sbit at DDRB.0
SPExpanderCS_Direction
as sbit at DDRB.1
' End Port Expander module connections
main:
text = "mikroE"
' If Port Expander Library uses SPI1 module
SPI1_Init() ' Initialize SPI mod-
ule used with PortExpander
Spi_Rd_Ptr = @SPI1_Read ' Pass pointer to SPI
Read sub function of used SPI module
' ' If Port Expander Library uses SPI2 module
' SPI2_Init() ' Initialize SPI mod-
ule used with PortExpander
' Spi_Rd_Ptr = &SPI2_Read ' Pass pointer to SPI
Read sub function of used SPI module
SPI_Lcd8_Config(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_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
end.
end.
418
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6