Monday, February 08, 2010

Interface & Program LCD 2 x 16 to Microcontroller (dsPIC30F)

Interface & Program LCD 2 x 16 to Microcontroller

The 2 X16 Parallel LCD is an 8 bit or 4 bit parallel interfaced LCD. This unit allows the user to display text, numerical data and custom created characters. The LCD uses the HD44780 series LCD driver from Hitachi, or equivalent controller. The LCD is connected to a female 14-pin connector for easy interface with the BS2p24/40 Demo Board (#45187) and the Professional Development Board (#28138). Though the device has the ribbon cable and 14-pin connector it may also be hooked up manually using the diagram on the next page.

The 2 X16 Parallel LCD is an 8 bit or 4 bit parallel interfaced LCD. This unit allows the user to display text, numerical data and custom created characters. The LCD uses the HD44780 series LCD driver from Hitachi, or equivalent controller. The LCD is connected to a female 14-pin
connector for easy interface with the BS2p24/40 Demo Board (#45187) and the Professional Development Board (#28138). Though the device has the ribbon cable and 14-pin connector it may also be hooked up manually using the diagram on the next page.

The following example 2x16 LCD connection (16characters, 2 line) to a dsPIC30F microcontroller by using a 4-bit and 8-bit interface. The following code demonstrates the usage of the LCD Custom Library routines. The example covers the initialization of the LCD module and instructions for contolling and writing the module. The realization is carried out by using the mikroBasic compiler for dsPIC30F Microcontrollers. The interconnection of the LCD module and a dsPIC30F devices by using a 4-bit interface is shown in Fig. 13-1.

Interface LCD 2 x 16 to  MicrocontrollerInterface LCD 2 x 16 to Microcontroller (dsPIC30F) using 4-bit

Interface LCD 2 x 16 to  MicrocontrollerInterface LCD 2 x 16 to Microcontroller (dsPIC30F) using 4-bit


example program LCD 4bit

dim txt as string[15]

main:
ADPCFG = $FFFF
Lcd_Init(PORTB, 3,2,1,0, PORTD, 0,2,1)
Lcd_Cmd(LCD_CURSOR_OFF)
Lcd_Cmd(LCD_CLEAR)

Lcd_Out(1, 1, "mikroElektronika")
Lcd_Out(2, 1, "2x16 LCD Testing")
end.


example program LCD 8bit

dim txt as string[10]

main:
ADPCFG = $FFFF ' PORTB to be digital
Lcd8_Init(PORTB, 7, 6, 5, 4, 3, 2, 1, 0, PORTD, 0, 1, 2)
Lcd8_Cmd(LCD_CURSOR_OFF)
Lcd8_Cmd(LCD_CLEAR)

Lcd8_Out(1, 1, "mikroElektronika")
Lcd8_Out(2, 1, "2x16 LCD Testing")
end.

Source