Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Programacion de Pantallas Led

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

LCD Library Page 1 of 4

LCD Library
mikroBasic provides a library for communicating with commonly used LCD (4-bit interface). Figures
showing HW connection of PIC and LCD are given at the end of the chapter.

Library Routines

n Lcd_Config
n Lcd_Init
n Lcd_Out
n Lcd_Out_Cp
n Lcd_Chr
n Lcd_Chr_Cp
n Lcd_Cmd

Lcd_Config

Prototype sub procedure Lcd_Config(dim byref data_port as byte,dim D7, D6, D5,
D4 as byte,dim byref ctrl_port as byte,dim RS, WR, EN as byte)

Returns Nothing.

Description Initializes LCD data port and control port with pin settings you specify.

Requires Nothing.

Example Lcd_Config(PORTD,3,2,1,0,PORTB,2,3,4)

Lcd_Init

Prototype sub procedure Lcd_Init(dim byref port as byte)

Returns Nothing.

Description Initializes LCD at port with default pin settings (see the connection scheme at the
end of the chapter):

D7 → port.7
D6 → port.6
D5 → port.5
D4 → port.4
E → port.3
RS → port.2
RW → port.0

Requires Nothing.

mk:@MSITStore:C:\Program%20Files%20(x86)\Mikroelektronika\mikroBasic\mikro... 30/03/2021
LCD Library Page 2 of 4

Example Lcd_Init(PORTB)

Lcd_Out

Prototype sub procedure Lcd_Out(dim row, col as byte, dim byref text as char
[255])

Returns Nothing.

Description Prints text on LCD at specified row and column (parameters row and col). Both
string variables and literals can be passed as text.

Requires Port with LCD must be initialized. See Lcd_Config or Lcd_Init.

Example Print “Hello!” on LCD at line 1, char 3:

Lcd_Out(1, 3, "Hello!")

Lcd_Out_Cp

Prototype sub procedure Lcd_Out_Cp(dim byref text as char[255])

Returns Nothing.

Description Prints text on LCD at current cursor position. Both string variables and literals can
be passed as text.

Requires Port with LCD must be initialized. See Lcd_Config or Lcd_Init.

Example Print “Here!” at current cursor position:

Lcd_Out_Cp("Here!")

Lcd_Chr

Prototype sub procedure Lcd_Chr(dim row, col, character as byte)

Returns Nothing.

Description Prints character on LCD at specified row and column (parameters row and col).
Both variables and literals can be passed as character.

Requires Port with LCD must be initialized. See Lcd_Config or Lcd_Init.

Example Print “i” on LCD at line 2, char 3:

Lcd_Chr(2, 3, "i")

mk:@MSITStore:C:\Program%20Files%20(x86)\Mikroelektronika\mikroBasic\mikro... 30/03/2021
LCD Library Page 3 of 4

Lcd_Chr_Cp

Prototype sub procedure Lcd_Chr_Cp(dim character as byte)

Returns Nothing.

Description Prints character on LCD at current cursor position. Both variables and literals can
be passed as character.

Requires Port with LCD must be initialized. See Lcd_Config or Lcd_Init.

Example Print “e” at current cursor position:

Lcd_Chr_Cp("e")

Lcd_Cmd

Prototype sub procedure Lcd_Cmd(dim command as byte)

Returns Nothing.

Description Sends command to LCD. You can pass one of the predefined constants to the
function. The complete list of available commands is below.

Requires Port with LCD must be initialized. See Lcd_Config or Lcd_Init.

Example Clear LCD display:

Lcd_Cmd(Lcd_Clear)

Available LCD Commands

LCD Command Purpose

Lcd_First_Row Move cursor to 1st row

Lcd_Second_Row Move cursor to 2nd row

Lcd_Third_Row Move cursor to 3rd row

Lcd_Fourth_Row Move cursor to 4th row

Lcd_Clear Clear display

Lcd_Return_Home Return cursor to home position, returns a shifted display to original position. Display data
RAM is unaffected.

Lcd_Cursor_Off Turn off cursor

Lcd_Underline_On Underline cursor on

Lcd_Blink_Cursor_On Blink cursor on

Lcd_Move_Cursor_Left Move cursor left without changing display data RAM

Lcd_Move_Cursor_Right Move cursor right without changing display data RAM

mk:@MSITStore:C:\Program%20Files%20(x86)\Mikroelektronika\mikroBasic\mikro... 30/03/2021
LCD Library Page 4 of 4

Lcd_Turn_On Turn LCD display on

Lcd_Turn_Off Turn LCD display off

Lcd_Shift_Left Shift display left without changing display data RAM

Lcd_Shift_Right Shift display right without changing display data RAM

Library Examples
Default Pin Configuration

Use Lcd_Init for default pin settings (see the first figure below).

program Lcd_default_test
dim text as char[20]

main:
TRISB = 0 ' PORTB is output
Lcd_Init(PORTB) ' Initialize LCD on PORTB
Lcd_Cmd(Lcd_CURSOR_OFF) ' Turn off cursor
text = "mikroElektronika"
Lcd_Out(1, 1, text) ' Print text at LCD
end.

LCD HW connection by default initialization (using Lcd_Init)

mk:@MSITStore:C:\Program%20Files%20(x86)\Mikroelektronika\mikroBasic\mikro... 30/03/2021

You might also like