User manual
mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
530
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 LATF0_bit;
SPExpanderCS : sbit at LATF1_bit;
SPExpanderRST_Direction : sbit at TRISF0_bit;
SPExpanderCS_Direction : sbit at TRISF1_bit;
// End Port Expander module connections
var someText : array[20] of char;
counter : byte;
procedure Delay2S;
begin
Delay_ms(2000);
end;
begin
{$DEFINE COMPLETE_EXAMPLE}// comment this line to make simpler/smaller example
ADPCFG := 0xFFFF; // initialize AN pins as digital
// If Port Expander Library uses SPI1 module
SPI1_Init(); // Initialize SPI module used with PortExpander
// If Port Expander Library uses SPI2 module
// SPI2_Init(); // Initialize SPI module used with PortExpander
SPI_Glcd_Init(0); // Initialize Glcd via SPI
SPI_Glcd_Fill(0x00); // Clear Glcd
while (TRUE) do
begin
{$IFDEF COMPLETE_EXAMPLE}
SPI_Glcd_Image(@truck_bmp); // Draw image
Delay2s(); Delay2s();
{$ENDIF}
SPI_Glcd_Fill(0x00); // Clear Glcd
Delay2s;
SPI_Glcd_Box(62,40,124,63,1); // Draw box
SPI_Glcd_Rectangle(5,5,84,35,1); // Draw rectangle
SPI_Glcd_Line(0, 0, 127, 63, 1); // Draw line
Delay2s();
counter := 5;
while (counter < 60) do // Draw horizontal and vertical line
begin
Delay_ms(250);