Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Library Example
This example demonstrates how to communicate Lcd via the SPI module, using
serial to parallel convertor MCP23S17.
program SPI_Lcd;
var text : array[16] of char;
// Port Expander module connections
var SPExpanderRST : sbit at PORTB.B0;
SPExpanderCS  : 
sbit at PORTB.B1;
SPExpanderRST_Direction : 
sbit at DDRB.B0;
SPExpanderCS_Direction  : 
sbit at DDRB.B1;
// End Port Expander module connections
begin
text := 'mikroElektronika';
// If Port Expander Library uses SPI1 module
SPI1_Init();                           // Initialize SPI module
used with PortExpander
Spi_Rd_Ptr := @SPI1_Read;              // Pass pointer to SPI Read
function of used SPI module
// If Port Expander Library uses SPI2 module
// SPI2_Init();                        // Initialize SPI module
used with PortExpander
// Spi_Rd_Ptr = @SPI2_Read;            // Pass pointer to SPI Read
function of used SPI module
SPI_Lcd_Config(0);           // Initialize Lcd over SPI interface
SPI_Lcd_Cmd(LCD_CLEAR);                // Clear display
SPI_Lcd_Cmd(LCD_CURSOR_OFF);           // Turn cursor off
SPI_Lcd_Out(1,6, 'mikroE');            // Print text to Lcd, 1st
row, 6th column
SPI_Lcd_Chr_CP('!');                   // Append '!'
SPI_Lcd_Out(2,1, text); // Print text to Lcd, 2nd row, 1st column
end.
420
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6