Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Library Example
The example demonstrates how to communicate to KS0108 Glcd via the SPI mod-
ule, using serial to parallel convertor MCP23S17.
program SPI_Glcd;
uses bitmap;
// Port Expander module connections
var SPExpanderRST : sbit at PORTB.0;
SPExpanderCS  : 
sbit at PORTB.1;
SPExpanderRST_Direction : 
sbit at DDRB.0;
SPExpanderCS_Direction  : 
sbit at DDRB.1;
// End Port Expander module connections
var someText : array[20] of char;
counter : byte;
procedure Delay2S;
begin
delay_ms(2000);
end;
begin
// If Port Expander Library uses SPI1 module
SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV2, _SPI_CLK_HI_TRAIL-
ING);  // 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_Advanced(_SPI_MASTER, _SPI_FCY_DIV2,
_SPI_CLK_HI_TRAILING);  // Initialize SPI module used with
PortExpander
// Spi_Rd_Ptr = @SPI2_Read;                    // Pass pointer to
SPI Read function of used SPI module
SPI_Glcd_Init(0);                      // Initialize Glcd via SPI
SPI_Glcd_Fill(0x00);                  // Clear Glcd
while (TRUE) do
begin
SPI_Glcd_Image(@truck_bmp);              // Draw image
Delay2s(); Delay2s();
SPI_Glcd_Fill(0x00);                    // Clear Glcd
Delay2s;
412
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6