News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

LCD 1602 Character

Started by Abdullah, Today at 06:10 PM

Previous topic - Next topic

Abdullah

Hello everyone
How can a down arrow be printed in a single custom character box on a 16x2 LCD
Abdullah

RGV250

Hi,
You need to study the display datasheet, it will have an area for user defined symbols. Once you have loaded the data you just print like any other character but I believe you need to use a number.

Regards,
Bob

Abdullah

Quote from: RGV250 on Today at 06:36 PMHi,
You need to study the display datasheet, it will have an area for user defined symbols. Once you have loaded the data you just print like any other character but I believe you need to use a number.

Regards,
Bob
Hi sir
I tried to read it,but i couldn't understand how to convert it into proton basic code
Abdullah

top204

#3
Creating UDGs (User Defined Graphics) on an alphanumeric LCD is very straightforward with the compilers, because the values sent to the LCD via the Print command, also represent the control values as written in the LCD's datasheet.

So to send a command, send the value $FE (%11111110) to the LCD, with Print $FE.

An alphanumeric LCD allows 8 UDGs as characters 0 to 7. So to create a UDG at character 0, use:

Print $FE, 64, %00000100, %00001110, %00010101, %00000100, %00000100, %00000100, %00000100, %00000000  ' Up facing arrow UDG, is character 0

Address 64 is the start of the CGRAM in the LCD.

And to display the Up Arrow character, use a command such as: Print 0

Below is a code demonstration that creates 4 arrow UDGs and displays them on an LCD:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate creating UDGs (User Defined Graphics) on an Hitachi alphanumeric LCD, and display them.
' Written by Les Johnson for the Positron8 BASIC Compiler.
'
    Device = 16F684                                     ' Tell the compiler what device to compile for
    Declare Xtal = 4                                    ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Setup the Alphanumeric LCD
'
    Declare LCD_DTPin = PORTC.0                         ' Pins PORTC.0 to PORTC.3 connect to the LCD's D4 to D7 pins
    Declare LCD_RSPin = PORTC.4                         ' Connects to the LCD's RS pin
    Declare LCD_ENPin = PORTC.5                         ' Connects to the LCD's EN pin
    Declare LCD_Interface = 4                           ' Tell the compiler to use a 4-bit interface with the LCD
    Declare LCD_Lines = 2                               ' Tell the compiler that the LCD has 2 lines
    Declare LCD_Type = Alpha                            ' Tell the compiler that the LCD is an alphanumeric type
'
' Create any global variables here
'
    Dim bXposition As Byte

'------------------------------------------------------------------------------------
' The main program starts here
' Display the UDG arrows on the alphanumeric LCD
'
Main:
    Setup()                                                 ' Setup the program and any peripherals
'
' Draw a line of right facing arrows from top left to top mid
'
    For bXposition = 1 To 8                                 ' Create a loop for the X positions
        Print At 1, bXposition, 0                           ' Draw character 0, which is defined as the right facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next                                                    ' Close the loop
'
' Draw a line of left facing arrows from bottom mid to bottom left
'
    For bXposition = 8 DownTo 1                             ' Create a loop for the X positions
        Print At 2, bXposition, 1                           ' Draw character 1, which is defined as the right facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next                                                    ' Close the loop
'
' Draw a line of Up facing arrows from top mid to top right
'
    For bXposition = 9 To 16                                ' Create a loop for the X positions
        Print At 1, bXposition, 2                           ' Draw character 2, which is defined as the up facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next
'
' Draw a line of Down facing arrows from bottom right to bottom mid
'
    For bXposition = 16 DownTo 9                            ' Create a loop for the X positions
        Print At 2, bXposition, 3                           ' Draw character 3, which is defined as the down facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next

'-------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : Writes UDG data to the LCD's CGRAM address, which starts at 64
'
Proc Setup()
    Cls                                                                                             ' Clear the LCD
'
' Create 4 custom arrow characters for the LCD
'
    Print $FE, 64,_                                                                                 ' Point the LCD to the beginning of CGRAM
          %00001000, %00000100, %00000010, %00011111, %00000010, %00000100, %00001000, %00000000,_  ' Right facing arrow UDG, is character 0
          %00000010, %00000100, %00001000, %00011111, %00001000, %00000100, %00000010, %00000000,_  ' Left facing arrow UDG, is character 1
          %00000100, %00001110, %00010101, %00000100, %00000100, %00000100, %00000100, %00000000,_  ' Up facing arrow UDG, is character 2
          %00000100, %00000100, %00000100, %00000100, %00010101, %00001110, %00000100, %00000000    ' Down facing arrow UDG, is character 3
EndProc

And below is a screenshot of the program operating in the proteus simulator:

LCD_UDGs.jpg

Regards
Les



Abdullah

Quote from: top204 on Today at 08:48 PMCreating UDGs (User Defined Graphics) on an alphanumeric LCD is very straightforward with the compilers, because the values sent to the LCD via the Print command, also represent the control values as written in the LCD's datasheet.

So to send a command, send the value $FE (%11111110) to the LCD, with Print $FE.

An alphanumeric LCD allows 8 UDGs as characters 0 to 7. So to create a UDG at character 0, use:

Print $FE, 64, %00000100, %00001110, %00010101, %00000100, %00000100, %00000100, %00000100, %00000000  ' Up facing arrow UDG, is character 0

Address 64 is the start of the CGRAM in the LCD.

And to display the Up Arrow character, use a command such as: Print 0

Below is a code demonstration that creates 4 arrow UDGs and displays them on an LCD:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate creating UDGs (User Defined Graphics) on an Hitachi alphanumeric LCD, and display them.
' Written by Les Johnson for the Positron8 BASIC Compiler.
'
    Device = 16F684                                     ' Tell the compiler what device to compile for
    Declare Xtal = 4                                    ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Setup the Alphanumeric LCD
'
    Declare LCD_DTPin PORTC.0
    Declare LCD_RSPin PORTC.4
    Declare LCD_ENPin PORTC.5
    Declare LCD_Interface 4
    Declare LCD_Lines 2
    Declare LCD_Type = Alpha
'
' Create any global variables here
'
    Dim bXposition As Byte

'------------------------------------------------------------------------------------
' The main program starts here
' Display the UDG arrows on the alphanumeric LCD
'
Main:
    Setup()                                                 ' Setup the program and any peripherals
'
' Draw a line of right facing arrows from top left to top mid
'
    For bXposition = 1 To 8                                 ' Create a loop for the X positions
        Print At 1, bXposition, 0                           ' Draw character 0, which is defined as the right facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next                                                    ' Close the loop
'
' Draw a line of left facing arrows from bottom mid to bottom left
'
    For bXposition = 8 DownTo 1                             ' Create a loop for the X positions
        Print At 2, bXposition, 1                           ' Draw character 1, which is defined as the right facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next                                                    ' Close the loop
'
' Draw a line of Up facing arrows from top mid to top right
'
    For bXposition = 9 To 16                                ' Create a loop for the X positions
        Print At 1, bXposition, 2                           ' Draw character 2, which is defined as the up facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next
'
' Draw a line of Down facing arrows from bottom right to bottom mid
'
    For bXposition = 16 DownTo 9                            ' Create a loop for the X positions
        Print At 2, bXposition, 3                           ' Draw character 3, which is defined as the down facing array UDG
        DelayMS 50                                          ' A delay so the arrows can be seen moving
    Next

'-------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : Writes UDG data to the LCD's CGRAM address, which starts at 64
'
Proc Setup()
    Cls                                                                                             ' Clear the LCD
'
' Create 4 custom arrow characters for the LCD
'
    Print $FE, 64,_                                                                                 ' Point the LCD to the beginning of CGRAM
          %00001000, %00000100, %00000010, %00011111, %00000010, %00000100, %00001000, %00000000,_  ' Right facing arrow UDG, is character 0
          %00000010, %00000100, %00001000, %00011111, %00001000, %00000100, %00000010, %00000000,_  ' Left facing arrow UDG, is character 1
          %00000100, %00001110, %00010101, %00000100, %00000100, %00000100, %00000100, %00000000,_  ' Up facing arrow UDG, is character 2
          %00000100, %00000100, %00000100, %00000100, %00010101, %00001110, %00000100, %00000000    ' Down facing arrow UDG, is character 3
EndProc

And below is a screenshot of the program operating in the proteus simulator:

LCD_UDGs.jpg

Regards
Les



Hello sir
thank you very much for your quick response
Best regards to My respectful teacher Les
Abdullah