User manual
mikroPascal PRO for PIC32
MikroElektronika
459
Library Example
The example demonstrates how to communicate to KS0108 Glcd via the SPI module, using serial to parallel convertor
MCP23S17.
Copy Code To Clipboard
program SPI_Glcd;
// Port Expander module connections
var SPExpanderRST : sbit at LATD8_bit;
SPExpanderCS : sbit at LATD9_bit;
SPExpanderRST_Direction : sbit at TRISD8_bit;
SPExpanderCS_Direction : sbit at TRISD9_bit;
// End Port Expander module connections
var someText : array[20] of char;
counter : byte;
procedure Delay2S;
begin
Delay_ms(2000);
end;
begin
CHECON := 0x32;
AD1PCFG := 0xFFFF; // Congure AN pins as digital
// 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_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_ll(0x00); // Clear GLCD
SPI_Glcd_PartialImage(0,0,68,30,128,64,@truck_bmp); // Partial image
Delay_ms(500);
SPI_Glcd_PartialImage(24,16,68,30,128,64,@truck_bmp);
Delay_ms(500);
SPI_Glcd_PartialImage(56,34,68,30,128,64,@truck_bmp);
Delay2s(); Delay2s();
SPI_Glcd_Fill(0x00); // Clear GLCD
SPI_Glcd_Box(62,40,124,56,1); // Draw box
SPI_Glcd_Rectangle(5,5,84,35,1); // Draw rectangle
Delay_ms(1000);
SPI_Glcd_Rectangle_Round_Edges(2,2,87,38,7,1);
Delay_ms(1000);
SPI_Glcd_Rectangle_Round_Edges_Fill(8,8,81,32,12,1);
Delay_ms(1000);
SPI_Glcd_Line(0, 0, 127, 63, 1); // Draw line
Delay2s();