⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd8bitdemodriver.pbas

📁 8 bit lcd interface in c++ for embedded microcotrollers
💻 PBAS
字号:
'*******************************************************************************
'  This is a driver for Hitachi based LCD wired via 8-bit interface. The driver
'  is provided "AS IS". The code should be a guide on how to use 8-bit interface protocol.
'  It is supposed that the LCD is connected to PIC via two ports.
'  The driver should work with any PIC (P16 family)  that has two 8-bit ports.
'  Tested on P16F877A.
'  2004-08-29
'
'  LCD Pin description
'
'    Pin#  Symbol  Level  Function
'     1     Vss     GND    Ground
'     2     Vcc     +5V    Module power
'     3     Vee    note1   Liquid crystal drive
'     4     RS      H/L    Register select, H=data, L=instruction
'                          connected to PIC portCTRL.2
'     5     R/W     H/L    Read/Write, H=read (module->CPU), L=write (CPU->module)
'                          connected to any PIC portCTRL pin that is on low (0) or to GND
'     6     E       H/L    Enable      connected to PIC portCTRL.3
'     7     DB0      "     Data bit 0  connected to PIC portDATA.0 (least significant bit)
'     8     DB1      "              1  connected to PIC portDATA.1
'     9     DB2      "              2  connected to PIC portDATA.2
'    10     DB3      "              3  connected to PIC portDATA.3
'    11     DB4      "              4  connected to PIC portDATA.4
'    12     DB5      "              5  connected to PIC portDATA.5
'    13     DB6      "              6  connected to PIC portDATA.6
'    14     DB7      "              7  connected to PIC portDATA.7
'*******************************************************************************}

module LCD8Bit

include "lcd8bit.pbas"

' If LCD8_Config function is called, values of these constants are changed
' internally by linker in order to reflect LCD8_Config parameters.
' If LCD8_Init is called, values of these constants remain unchanged

dim DataAddress as byte
dim CtrlAddress as byte
dim cmd as byte


sub procedure LCD8_Cmd_Demo(dim Out_Char as byte)
  FSR = DataAddress
  INDF = 0
  asm
    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,7
    BSF      INDF,__LCD8_DB7

    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,6
    BSF      INDF,__LCD8_DB6

    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,5
    BSF      INDF,__LCD8_DB5

    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,4
    BSF      INDF,__LCD8_DB4

    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,3
    BSF      INDF,__LCD8_DB3

    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,2
    BSF      INDF,__LCD8_DB2

    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,1
    BSF      INDF,__LCD8_DB1

    BTFSC    lcd8bitdemodriver_Lcd8_Cmd_Demo_param_out_char,0
    BSF      INDF,__LCD8_DB0
  end asm


  FSR = CtrlAddress
  asm
    BSF      INDF, __LCD8_RS
  end asm

  if cmd = 1 then
     asm
       BCF      INDF, __LCD8_RS
     end asm
  end if

  asm
    BSF      INDF, __LCD8_ENABLE
  end asm
    Delay_1us
  asm
    BCF      INDF, __LCD8_ENABLE
  end asm

 if cmd = 1 then
   Delay_5500us
 else
    delay_50us
 end if
end sub

sub procedure LCD8_Chr_Demo(dim Row as byte, dim Column as byte, dim Out_Char as byte)
  select case Row
    case 1
      Row = LCD_FIRST_ROW
    case 2
      Row = LCD_SECOND_ROW
    case 3
      Row = LCD_THIRD_ROW
    case 4
      Row = LCD_FOURTH_ROW
    case else
      Row = LCD_FIRST_ROW
  end select
  Row = Row + Column-1

  Lcd8_Cmd_Demo(Row)
  cmd = 0
  Lcd8_Cmd_Demo(Out_Char)
  cmd = 1
end sub

sub procedure LCD8_Chr_CP_Demo(dim Out_Char as byte)
  cmd = 0
  Lcd8_Cmd_Demo(Out_Char)
  cmd = 1
end sub

sub procedure LCD8_Init_Demo(dim byref portCTRL as byte,
                             dim byref portDATA as byte)
  Delay_5500us
  Delay_5500us
  Delay_5500us

  portDATA = byte(portDATA)
  asm
    MOVF    lcd8bitdemodriver_lcd8_init_demo_param_portdata,W
    MOVWF   lcd8bitdemodriver_main_global_dataaddress
  end asm
  SetBit(FSR,7)
  INDF = 0

  portCTRL = byte(portCTRL)
  asm
    MOVF    lcd8bitdemodriver_lcd8_init_demo_param_portctrl,W
    MOVWF   lcd8bitdemodriver_main_global_ctrladdress
  end asm
  SetBit(FSR,7)
  asm
    BCF   INDF,__LCD8_RS
    BCF   INDF,__LCD8_RW
    BCF   INDF,__LCD8_ENABLE
  end asm
  ClearBit(FSR,7)

  cmd = 1
  Lcd8_Cmd_Demo(48)

  Lcd8_Cmd_Demo(48)
  Lcd8_Cmd_Demo(48)

  Lcd8_Cmd_Demo(56)
  Lcd8_Cmd_Demo(8)
  Lcd8_Cmd_Demo(LCD_CLEAR)
  Lcd8_Cmd_Demo(6)
  Lcd8_Cmd_Demo(LCD_CURSOR_OFF)
end sub

sub procedure LCD8_Out_Demo(dim Row as byte,
                            dim Column as byte,
                            dim byref text as char[255])
  dim i as byte
  for i = 1 to Length(text)
     Lcd8_Chr_Demo(Row, Column+i-1, text[i])
  next i
end sub

sub procedure LCD8_Out_CP_Demo(dim byref text as char[255])
  dim i as byte
  for i = 1 to Length(text)
     Lcd8_Chr_CP_Demo(text[i])
  next i
end sub


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -