--- This is a test - only visible to admins ---
--- advertisement may go here ---
  • PicŪ Basic


  • Inexpensive alphanumeric LCD Arduino boards usage in Proton and the Amicus18 board

    The Alphanumeric LCDs available from Ebay are incredibly inexpensive and are usually less money than buying the LCD module itself. They are designed for an Arduino board, which has the same pinout dimensions as our Amicus18 board. However, the pinouts on an Arduino board are reversed. Plugging one of these boards into an Amicus18 board makes designing the final circuit simplicity itself, and may well be less expensive than getting a custom PCB designed and built.

    The code presented here allows these shields (the Arduino name for an add on board) to be used with the Proton compiler, which is free to use when programming the chip used on the Amicus18 board. i.e. the PIC18F25K20. It replaces the compiler's Print command code with code that works flawlessly with these LCD boards.

    The LCD shields come in various colours but seem to follow exactly the same pinouts and operation except that the Buttons that are connected to the microcontroller's ADC have different resistance so give a different value when pressed.

    A standard LCD shield is shown below:

    The demo program is listed below:
    Code:
    '
    ' Demonstrate the replacement Print command with reversed bits
    ' For use with some Arduino alphanumeric LCD shields on the Amicus18 board, or a user's own design
    ' These use a 4-bit interface to the LCD
    ' The buttons on the LCD shield are attached to AN0 and give a different ADC value for each button press
    '
        Include "Amicus18.inc"                  ' Use an 18F25K20 operating at 64MHz. i.e. An Amicus18 board
        Include "Amicus18_ADC.inc"              ' Load the Amicus18 ADC macros into the program
    '
    ' Setup the LCD for the pins used on the LCD shield
    '
        Declare LCD_DTPin = PORTC.0             ' The shield uses RC4, RC5, RC6, RC7 for the data pins
        Declare LCD_RSPin = PORTB.7             ' The shield uses RB7 for the RS pin
        Declare LCD_ENPin = PORTB.6             ' The shield uses RB6 for the EN pin
        Declare LCD_Interface = 4               ' The shield uses a 4-bit LCD interface
        Declare LCD_Lines = 2                   ' 2 lines by 16 characters
        Declare LCD_Type = Alphanumeric         ' It is an alphanumeric LCD
        Declare LCD_CommandUs = 2000            ' 2000us time for commands to be sent to the LCD
        Declare LCD_DataUs = 50                 ' 50us time for data to be sent to the LCD
    
        Include "Hitachi_4.inc"                 ' Load the replacement "reversed" Print command for a 4-bit interface
    '
    ' Create variables
    '
        Dim LCD_wButton As Word                 ' Holds a value for a button pressed
    
    $define _GHI_LCD                            ' We're using an Arduino GHI LCD shield for this demo
    
    $ifdef _DF_Robot_LCD                        ' Are we using the DF Robot LCD Shield?
    '
    ' Yes. So set ADC button values for the DF Robot LCD Shield
    '
        Symbol cButton_Left = 792
        Symbol cButton_Right = 0
        Symbol cButton_Up = 235
        Symbol cButton_Down = 521
        Symbol cButton_None = 1023
    $endif
    
    $ifdef _GHI_LCD                             ' Are we using the GHI LCD Shield?
    '
    ' Yes. So set ADC button values for the GHI Electronics LCD Shield
    '
        Symbol cButton_Left = 481
        Symbol cButton_Right = 0
        Symbol cButton_Up = 132
        Symbol cButton_Down = 308
        Symbol cButton_Select = 721
        Symbol cButton_None = 1023
    $endif
    
    '------------------------------------------------------------------------------------------------
        GoTo Main                                           ' Jump over the subroutines
    
    '------------------------------------------------------------------------------------------------
    ' Get a Button press from the LCD shield's buttons
    ' Input     : None
    ' Output    : LCD_wButton holds the Button press value
    ' Notes     : Because the ADC value may vary, detect the Buttons with some flexability
    '
    $define Get_Button(pResult) '
        GoSub _Get_ButtonPress       '
        pResult = LCD_wButton
    
    _Get_ButtonPress:
        LCD_wButton = ADIn 0                                ' Read the ADC for a Button pressed value
        Select LCD_wButton                                  ' Check the value from the ADC
            Case cButton_Left - 5 To cButton_Left + 5       ' Is it the Left button?
                LCD_wButton = cButton_Left                  ' Yes. So make the Button pressed value fixed
            Case cButton_Right To cButton_Right + 5         ' Is it the Right button?
                LCD_wButton = cButton_Right                 ' Yes. So make the Button pressed value fixed
            Case cButton_Up - 5 To cButton_Up + 5           ' Is it the Up button?
                LCD_wButton = cButton_Up                    ' Yes. So make the Button pressed value fixed
            Case cButton_Down - 5 To cButton_Down + 5       ' Is it the Down button?
                LCD_wButton = cButton_Down                  ' Yes. So make the Button pressed value fixed
            Case cButton_Select - 5 To cButton_Select + 5   ' Is it the Select button?
                LCD_wButton = cButton_Select                ' Make the Button pressed value fixed
            Case Else                                       ' Otherwise no Button is pressed. So...
                LCD_wButton = cButton_None                  ' Make the Button pressed value fixed
        EndSelect
        Return
    
    '------------------------------------------------------------------------------------------------
    ' Setup the program
    ' Input     : None
    ' Output    : None
    ' Notes     : None
    '
    $define Program_Setup() GoSub _Program_Setup
    
    _Program_Setup:
    '
    ' Open the Analogue to Digital Converter for an input on AN0, where the buttons are connected
    '
        OpenADC(ADC_FOSC_RC & ADC_RIGHT_JUST & ADC_2_TAD, ADC_REF_VDD_VSS, ADC_1ANA)
        Cls
        Return
    
    '------------------------------------------------------------------------------------------------
    Main:
        Program_Setup()                                     ' Setup the program
    
        Print At 1,1, "Press a Button"
        While                                               ' Create a loop
            Get_Button(LCD_wButton)                         ' Get a button press
            Select LCD_wButton                              ' Test the button press value
                Case cButton_Left                           ' Is it the Left button?
                    Print At 2,1,"Left Pressed  "           ' Yes. So print it
                Case cButton_Right                          ' Is it the Right button?
                    Print At 2,1,"Right Pressed "           ' Yes. So print it
                Case cButton_Up                             ' Is it the Up button?
                    Print At 2,1,"Up Pressed    "           ' Yes. So print it
                Case cButton_Down                           ' Is it the Down button?
                    Print At 2,1,"Down Pressed  "           ' Yes. So print it
                Case cButton_Select                         ' Is it the Select button?
                    Print At 2,1,"Select Pressed"           ' Yes. So print it
                Case Else                                   ' Otherwise no Button is pressed. So...
                    Print At 2,1,"              "           ' Empty the line on the LCD
            EndSelect
        Wend                                                ' Do it forever
    The code is available from here:
    Alphanumeric LCD Shield Usage

    Note that the code is for 18F devices only.
  • Recent Activity

    normnet-324

    PIC iPod wav player

    Thread Starter: normnet

    Coming in the next month or two a PIC iPod wav player. Plays 44k, 8 bit, stereo wav files from an SD card. Displays BMP pictures on a NOKIA 6100...

    normnet Today, 13:59 Go to last post
    teo-16018

    Frequency counter

    Thread Starter: teo

    Hello everybody Can someone help me with a piece of code to measure a frequency (1Hz to 160 Hz) precision two decimals. The result is transmitted...

    teo Yesterday, 17:43 Go to last post
    joesaliba-353

    Multiple functions by a single switch

    Thread Starter: amod

    Hi, How can I use multiple function by a single switch.I want to use 4 functions by a single switch.

    joesaliba Today, 09:19 Go to last post
    steyn-15336

    PickitPlus for Pickit2 and Pickit3 works well

    Thread Starter: leonj

    Hi Everyone, I have always had issues with Pickit2/Pickit3 and I'm glad to say they seem to all be solved now. I obtained PickitPlus from Even at...

    steyn Today, 09:34 Go to last post
    RGV250-614

    SD routines for 18F series

    Thread Starter: charliecoultas

    I've used the SD routines very successfully for the P24 chips, but now I need to attach an SD card to a 18F26K22. Do such routines exist and if...

    RGV250 Yesterday, 19:40 Go to last post