User manual

554
mikoC PRO for dsPIC
MikroElektronika
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
const code char truck_bmp[1024];
// Port Expander module connections
sbit SPExpanderRST at LATF0_bit;
sbit SPExpanderCS at LATF1_bit;
sbit SPExpanderRST_Direction at TRISF0_bit;
sbit SPExpanderCS_Direction at TRISF1_bit;
// End Port Expander module connections
void Delay2s(){ // 2 seconds delay function
Delay_ms(2000);
}
void main() {
char counter;
char *someText;
#dene COMPLETE_EXAMPLE
ADPCFG = 0xFFFF; // initialize AN pins as digital
// If Port Expander Library uses SPI1 module
SPI1_Init(); // Initialize SPI module used with
PortExpander
SPI_Glcd_Init(0); // Initialize Glcd via SPI
SPI_Glcd_Fill(0x00); // Clear Glcd
Delay2s();
while(1) {
#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,56,1); // Draw box
SPI_Glcd_Rectangle(5,5,84,35,1); // Draw rectangle
SPI_Glcd_Line(0, 63, 127, 0,1); // Draw line
Delay2s();
for(counter = 5; counter < 60; counter+=5 ) { // Draw horizontal and vertical line
Delay_ms(250);
SPI_Glcd_V_Line(2, 54, counter, 1);
SPI_Glcd_H_Line(2, 120, counter, 1);
}