Programacion de Pantallas Led
Programacion de Pantallas Led
Programacion de Pantallas Led
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
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.
Lcd_Out(1, 3, "Hello!")
Lcd_Out_Cp
Returns Nothing.
Description Prints text on LCD at current cursor position. Both string variables and literals can
be passed as text.
Lcd_Out_Cp("Here!")
Lcd_Chr
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.
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
Returns Nothing.
Description Prints character on LCD at current cursor position. Both variables and literals can
be passed as character.
Lcd_Chr_Cp("e")
Lcd_Cmd
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.
Lcd_Cmd(Lcd_Clear)
Lcd_Return_Home Return cursor to home position, returns a shifted display to original position. Display data
RAM is unaffected.
mk:@MSITStore:C:\Program%20Files%20(x86)\Mikroelektronika\mikroBasic\mikro... 30/03/2021
LCD Library Page 4 of 4
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.
mk:@MSITStore:C:\Program%20Files%20(x86)\Mikroelektronika\mikroBasic\mikro... 30/03/2021