Mikroelektronika MIKROE-724 データシート

ページ / 726
544
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Library Example
This example demonstrates how to communicate Lcd in 8-bit mode via the SPI module, using serial to parallel convertor 
MCP23S17.
Copy Code To Clipboard 
program Spi_Lcd8
dim text as char[16]
dim counter as byte
‘ Port Expander module connections
dim SPExpanderRST as sbit at LATF0_bit
dim SPExpanderCS  as sbit at LATF1_bit
dim SPExpanderRST_Direction as sbit at TRISF0_bit
dim SPExpanderCS_Direction  as sbit at TRISF1_bit
‘ End Port Expander module connections
sub procedure Move_Delay()            ‘ Function used for text moving
  Delay_ms(500)                       ‘ You can change the moving speed here
end sub
main:
  text = “mikroElektronika”
  ADPCFG = 0xFFFF                     ‘ initialize AN pins as digital
  SPI1_Init()                         ‘ Initialize SPI
  Spi_Lcd8_Config(0)                   ‘ Initialize LCD over SPI interface
  Spi_Lcd8_Cmd(_LCD_CLEAR)            ‘ Clear display
  Spi_Lcd8_Cmd(_LCD_CURSOR_OFF)       ‘ Turn cursor off
  Spi_Lcd8_Out(1,6, “mikroE”)         ‘ Print text to LCD, 1st row, 6th column
  Spi_Lcd8_Chr_CP(“!”)                ‘ Append ‘!’
  Spi_Lcd8_Out(2,1, text)             ‘ Print text to LCD, 2nd row, 1st column
  ‘  Spi_Lcd8_Out(3,1,’mikroE’) 
      ‘ For LCD with more than two rows
  ‘  Spi_Lcd8_Out(4,15,’mikroE’)      ‘ For LCD with more than two rows
  ‘ Moving text
  for counter = 0 to 3                ‘ Move text to the right 4 times
    Spi_Lcd8_Cmd(_LCD_SHIFT_RIGHT)
    Move_Delay()
  next counter
  while TRUE                          ‘ Endless loop
    for counter = 0 to 6              ‘ Move text to the left 7 times
      Spi_Lcd8_Cmd(_LCD_SHIFT_LEFT)
      Move_Delay()
    next counter
 for counter = 0 to 6                 ‘ Move text to the right 7 times
      Spi_Lcd8_Cmd(_LCD_SHIFT_RIGHT)
      Move_Delay()
    next counter
  wend
end.