Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
531
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
dim SPExpanderRST as sbit at LATF0_bit
    SPExpanderCS  as sbit at LATF1_bit
    SPExpanderRST_Direction as sbit at TRISF0_bit
    SPExpanderCS_Direction  as sbit at TRISF1_bit
‘ End Port Expander module connections
dim someText as char[20]
    counter as byte
sub procedure Delay2S
  Delay_ms(2000)
end sub
main:
  #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)
    #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)                        ‘ Draw horizontal and vertical line
      Delay_ms(250)
      SPI_Glcd_V_Line(2, 54, counter, 1)
      SPI_Glcd_H_Line(2, 120, counter, 1)
      counter = counter + 5
    wend