Hello
I have to connect 40x4 lcd to my project .
The lcd have 2 Enable pins ,
EN1 for rows 1&2
EN2 for rows 3&4
How can I connect it to my Board?
The Lcd is JHD404a-4
Thanks
Yoram
40x4 LCD
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: 40x4 LCD
Hello,
Please take a look at following topic:
http://www.mikroe.com/forum/viewtopic.p ... 48#p190657
Best regards.
Please take a look at following topic:
http://www.mikroe.com/forum/viewtopic.p ... 48#p190657
Best regards.
Re: 40x4 LCD
TRY SOMETHING LIKE THIS
I used a 16F876A but you and some others,
ENJOY IN PROGRAMMING
I used a 16F876A but you and some others,
ENJOY IN PROGRAMMING
Code: Select all
program LCD_4X40_MBPRO
INCLUDE LCD_4x40_HS_PLL
' Declarations section
'-------------------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////////////////
'-------------------------------------------------------------------------------
main:
TRISA = 0 PORTA = 0
TRISB = 0 PORTB = 0
TRISC = 0 PORTC = 0 ' ALL PORTS as Output
Delay_ms(100)
LCD_PLL_INIT ' INICIJALIZACIJA LCD DISPLEJA
LCD_PLL_CMD(_LCD_CLEAR) ' Lcd_Clear
Delay_ms(100)
'-------------------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////////////////
'-------------------------------------------------------------------------------
While 1 = 1
Lcd_PLL_Out(1,1,"I have to connect 40x4 lcd to my project")
Lcd_PLL_Out(2,1,"The lcd have 2 Enable pins ,")
Lcd_PLL_Out(3,1,"EN1 for rows 1&2 and EN2 for rows 3&4")
Lcd_PLL_Out(4,1,"How can I connect it to my Board? ")
Wend
'-------------------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////////////////
'-------------------------------------------------------------------------------
end.
'-------------------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////////////////
'-------------------------------------------------------------------------------
Code: Select all
'*******************************************************************************
'' EXAMPLE INCLUDING USE IN PLL
'' Oscillator: HS-PLL 10.0000 MHz UP TO 40.000 MHz
MODULE LCD_4x40_HS_PLL
'' *
'' * Modul name:
'' Lcd_PLL_Test (Simple demonstration of the LCD_PLL Module sub functions)
'' * Copyright:
'' S59KB Thank microelectronics, 2012
'' * Revision History:
'' 20121212:
'' - initial release.
'' * Description:
'' EXAMPLE INCLUDING USE IN HS-PLL Oscillator
'' This is a simple demonstration of LCD_PLL library Module.
''
'' * Test configuration:
'' MCU: TEST to P18F4520 or any other
'' Dev.Board: EasyPIC5
'' Oscillator: HS-PLL 10.0000 MHz
'' Ext. Modules: me LCD 4x40
'' SW: mikroBasicPro v 3.2
'' *
'' INCLUDE LCD_PLL_MODULE
'' Library Routines LCD_4x40_HS_PLL
'' Lcd_Config_____________________LCD_PLL_CONFIG
'' Lcd_Init_______________________LCD_PLL_INIT
'' Lcd_Cmd________________________LCD_PLL_CMD
'' Lcd_Chr________________________LCD_PLL_CHR
'' Lcd_Chr_Cp_____________________LCD_PLL_CHR_CP
'' Lcd_Out________________________LCD_PLL_OUT
'' Lcd_Out_Cp_____________________LCD_PLL_OUT_CP
''
'' LCD_PLL_CONFIG(Port_x, d3, d2, d1, d0, Port_x, rs, ctrl_rw, enable) Not necessary to make the procedure.
''
'' LCD_PLL_INIT Initializes LCD at port with default pin settings (see the connection scheme at the end of the chapter)
''
'' LCD_PLL_CMD(Lcd_Clear) Sends command to LCD. You can pass one of the predefined constants to the function. The complete list of available commands is below.
'' 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
'' 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
''
'' LCD_PLL_CHR(1,5,51) Prints character on LCD at specified row and column (parameters row and col). Both variables and literals can be passed as character.
''
'' LCD_PLL_CHR_CP(51) Prints character on LCD at current cursor position. Both variables and literals can be passed as character.
''
'' LCD_PLL_OUT(1,1,"mikroBasic") Prints text on LCD at specified row and column (parameters row and col). Both string variables and literals can be passed as text.
''
'' LCD_PLL_OUT_CP("mikroBasic") Prints text on LCD at current cursor position. Both string variables and literals can be passed as text.
''
''------------------------------------------------------------------------------
''Example for the generation of new characters
'' const character1 as byte[8] = (21,14,21,4,21,14,21,0) 'KARAKTER 1 ... O O O
'' SUB PROCEDURE CustomChar1 dim i1 as byte O O O
'' DIM i1 AS BYTE O O O
'' LCD_PLL_INIT Delay_ms(250) O
'' LCD_PLL_CMD(64)for i1=0 to 7 LCD_PLL_CHR_CP(character1[i1])next i1 O O O
'' END SUB O O O
''------------------------- O O O
'' LCD_PLL_Cmd(64)for i1 = 0 to 7 LCD_PLL_Chr_Cp(character1[i1])next i1 'KARAKTER 1 ...
''------------------------------------------------------------------------------
'*******************************************************************************
'' Initializes LCD at port with default pin settings.
'' LCD_PLL_CONFIG(Port_x, d3, d2, d1, d0, Port_x, rs, ctrl_rw, enable) Not necessary to make the procedure.
''
'' WRITE YOUR OWN HERE TO CONTACT USE
''
' symbol LCD_RW = PORTB.0 'Not used in Module. USE FOR ANYTHING
symbol LCD_RS = PORTB.1
symbol LCD_E_1 = PORTB.2
symbol LCD_E_2 = PORTB.3
'------------------------
symbol LCD_D0 = PORTB.4
symbol LCD_D1 = PORTB.5
symbol LCD_D2 = PORTB.6
symbol LCD_D3 = PORTB.7
'------------------------
SUB PROCEDURE LCD_poslji_nib_1(DIM RS, NIB AS BYTE)
SUB PROCEDURE LCD_poslji_nib_2(DIM RS, NIB AS BYTE)
SUB PROCEDURE LCD_poslji_1(DIM RS, NIB AS BYTE)
SUB PROCEDURE LCD_poslji_2(DIM RS, NIB AS BYTE)
SUB PROCEDURE LCD_PLL_INIT()
SUB PROCEDURE LCD_RED_POZ_OUT_1(DIM KO,VR AS BYTE)
SUB PROCEDURE LCD_RED_POZ_OUT_2(DIM KO,VR AS BYTE)
SUB PROCEDURE LCD_PLL_CMD(DIM TEKST AS BYTE)
SUB PROCEDURE LCD_PLL_CHR(DIM KO,VR AS BYTE,DIM ZNAK AS BYTE)
SUB PROCEDURE LCD_PLL_CHR_CP(DIM ZNAK AS BYTE)
SUB PROCEDURE LCD_PLL_OUT(DIM KO,VR AS BYTE, DIM BYREF TEKST as STRING[40])
SUB PROCEDURE LCD_PLL_OUT_CP(DIM BYREF ZNAK AS BYTE)
'------------------------
implements
''
'' The initialization of the following adjusted
'' TRISB = 0
'' PORTB = 0
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_poslji_nib_1(DIM RS, NIB AS BYTE)
LCD_RS = RS '// namesti RS
LCD_D0 = NIB.0 '// namesti nibbla na izlaz
LCD_D1 = NIB.1
LCD_D2 = NIB.2
LCD_D3 = NIB.3
LCD_E_1 = 1 '// slanje enable LCD modulu
delay_us(200)
LCD_E_1 = 0
delay_us(200)
LCD_E_1 = 1
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_poslji_nib_2(DIM RS, NIB AS BYTE)
LCD_RS = RS '// namesti RS
LCD_D0 = NIB.0 '// namesti nibbla na izlaz
LCD_D1 = NIB.1
LCD_D2 = NIB.2
LCD_D3 = NIB.3
LCD_E_2 = 1
delay_us(200)
LCD_E_2 = 0
delay_us(200)
LCD_E_2 = 1
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_poslji_1(DIM RS, NIB AS BYTE)
LCD_RS = RS '// slanje gornjeg nibbla
LCD_D0 = NIB.4
LCD_D1 = NIB.5
LCD_D2 = NIB.6
LCD_D3 = NIB.7
delay_us(80)
LCD_E_1 = 0
delay_us(20)
LCD_E_1 = 1
LCD_RS = RS '// slanje doljneg nibbla
LCD_D0 = NIB.0
LCD_D1 = NIB.1
LCD_D2 = NIB.2
LCD_D3 = NIB.3
delay_us(80)
LCD_E_1 = 0
delay_us(80)
LCD_E_1 = 1
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_poslji_2(DIM RS, NIB AS BYTE)
LCD_RS = RS '// slanje gornjeg nibbla
LCD_D0 = NIB.4
LCD_D1 = NIB.5
LCD_D2 = NIB.6
LCD_D3 = NIB.7
delay_us(80)
LCD_E_2 = 0
delay_us(20)
LCD_E_2 = 1
LCD_RS = RS '// slanje doljneg nibbla
LCD_D0 = NIB.0
LCD_D1 = NIB.1
LCD_D2 = NIB.2
LCD_D3 = NIB.3
delay_us(80)
LCD_E_2 = 0
delay_us(80)
LCD_E_2 = 1
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_INIT() '// Initializes LCD at port with default pin settings.
LCD_E_1 = 0
LCD_poslji_nib_1(0,0x03) delay_ms(200)'// 3 puta init
LCD_poslji_nib_1(0,0x03) delay_ms(80)
LCD_poslji_nib_1(0,0x03) delay_ms(80)
LCD_poslji_nib_1(0,0x02) delay_ms(12) '// namesti 4 bita prenos podataka
LCD_poslji_1(0,0x01) delay_ms(12) '// obrisi displaj
LCD_poslji_1(0,0x28) delay_ms(4) '// nastavi znakove sa 5x7 font
LCD_poslji_1(0,0x0C) delay_ms(4) '// ukljuci displj, izkljuci kursor i blinkanje
LCD_poslji_1(0,0X06) delay_ms(4) '// namesti smer pomeranja kursora i shift displaj
'-------------------------------------------
LCD_E_2 = 0
LCD_poslji_nib_2(0,0x03) delay_ms(200)'// 3 puta init
LCD_poslji_nib_2(0,0x03) delay_ms(80)
LCD_poslji_nib_2(0,0x03) delay_ms(80)
LCD_poslji_nib_2(0,0x02) delay_ms(12) '// namesti 4 bita prenos podataka
LCD_poslji_2(0,0x01) delay_ms(12) '// obrisi displaj
LCD_poslji_2(0,0x28) delay_ms(4) '// nastavi znakove sa 5x7 font
LCD_poslji_2(0,0x0C) delay_ms(4) '// ukljuci displj, izkljuci kursor i blinkanje
LCD_poslji_2(0,0X06) delay_ms(4) '// namesti smer pomeranja kursora i shift displaj
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_RED_POZ_OUT_1(DIM KO,VR AS BYTE)
if (KO = 1) THEN LCD_poslji_1(0,128 + VR) END IF
if (KO = 2) THEN LCD_poslji_1(0,192 + VR) END IF
if (KO = 3) THEN LCD_poslji_1(0,148 + VR) END IF
if (KO = 4) THEN LCD_poslji_1(0,212 + VR) END IF
delay_us(50)
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_RED_POZ_OUT_2(DIM KO,VR AS BYTE)
if (KO = 1) THEN LCD_poslji_2(0,128 + VR) END IF
if (KO = 2) THEN LCD_poslji_2(0,192 + VR) END IF
if (KO = 3) THEN LCD_poslji_2(0,148 + VR) END IF
if (KO = 4) THEN LCD_poslji_2(0,212 + VR) END IF
delay_us(50)
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_CMD(DIM TEKST AS BYTE)
LCD_poslji_1(0,TEKST)
LCD_poslji_2(0,TEKST)
delay_us(40)
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_CHR(DIM KO,VR AS BYTE,DIM ZNAK AS BYTE)
IF KO<3 THEN
IF (KO=1)AND(VR>20) THEN KO=3 VR=VR-20 END IF
IF (KO=2)AND(VR>20) THEN KO=4 VR=VR-20 END IF
LCD_RED_POZ_OUT_1(KO,VR-1)
LCD_poslji_1(1,ZNAK)
delay_us(40)
ELSE
IF KO=3 THEN KO=1 END IF
IF KO=4 THEN KO=2 END IF
IF (KO=1)AND(VR>20) THEN KO=3 VR=VR-20 END IF
IF (KO=2)AND(VR>20) THEN KO=4 VR=VR-20 END IF
LCD_RED_POZ_OUT_2(KO,VR-1)
LCD_poslji_2(1,ZNAK)
delay_us(40)
END IF
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_CHR_CP(DIM ZNAK AS BYTE)
LCD_poslji_1(1,ZNAK)
LCD_poslji_2(1,ZNAK)
delay_us(40)
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_OUT(DIM KO,VR AS BYTE, DIM BYREF TEKST as STRING[40])
DIM LOOP_INDEX AS BYTE
DIM INDEX AS BYTE
INDEX = Strlen(TEKST)- 1
FOR LOOP_INDEX = 0 TO INDEX
LCD_PLL_CHR(KO,VR+LOOP_INDEX, TEKST[LOOP_INDEX])
NEXT LOOP_INDEX
END SUB
'-------------------------------------------------------------------------------
'/////////////////////////////////////////////////////////////////////////////// ' OK
'-------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_OUT_CP(DIM BYREF ZNAK AS BYTE)
LCD_PLL_CHR_CP(ZNAK)
END SUB
'-------------------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////////////////
'-------------------------------------------------------------------------------
end.' and ENJOY :)
'-------------------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////////////////
'-------------------------------------------------------------------------------
Re: 40x4 LCD
Download Project [325.49KB]
http://www.libstock.com/projects/view/1 ... t-40x4-lcd
Best regards radio amateurs, 73
S59KB