LCD Display

ruairihev

Member
I am using a 28x1 to display voltage and current readings on an LCD. I have connected the circuit using the schematic on hippys page
http://www.hippy.freeserve.co.uk/picaxelc.htm#Output_Pin_Definition
I also just cut and pasted his code for the hello world program and got it to work (I had to change 'get' to 'get1' and 'byte' to byte1' as a syntax error kept occuring). So basically I want to display voltage=### and current=### in place of hello and world. I want the real time data to be displayed where ### is to one decimal place (e.g. Voltage = 26.5, Current = 18.3). I am reading the voltage and current on pins 2 and 3 using the readadc10 command. Basically, how do I display on the LCD what the readadc10 command is detecting? It's probably an easy modification to the attached code but I don't know how to do it.

Code:
        SYMBOL  RS        = 2         ; 0 = Command   1 = Data
        SYMBOL  E         = 3         ; 0 = Idle      1 = Active
        SYMBOL  DB4       = 4         ; LCD Data Line 4
        SYMBOL  DB5       = 5         ; LCD Data Line 5
        SYMBOL  DB6       = 6         ; LCD Data Line 6
        SYMBOL  DB7       = 7         ; LCD Data Line 7

        SYMBOL  RSCMDmask = %00000000 ; Select Command register
        SYMBOL  RSDATmask = %00000100 ; Select Data register

        SYMBOL  get1     = b11;
        SYMBOL  byte1      = b12;
        SYMBOL  rsbit      = b13;

        
    PowerOnReset:

        GOSUB InitialiseLcd

    DisplayTopLine:

        EEPROM 6,("Voltage=")

        FOR get1 = 6 TO 13
          READ get1,byte1
          GOSUB SendDataByte
        NEXT

    MoveCursorToStartOfSecondLine:

        byte1 = $C0
        GOSUB SendCmdByte

    DisplayBottomLine:

        EEPROM 14,("Current=")

        FOR get1 = 14 TO 21
          READ get1,byte1
          GOSUB SendDataByte
        NEXT

        END

    InitialiseLcd:

        FOR get1 = 0 TO 5
          READ get1,byte1
          GOSUB SendInitCmdByte
        NEXT

        ' Nibble commands - To initialise 4-bit mode

        EEPROM 0,( $33 )    ; %0011---- %0011----   8-bit / 8-bit
        EEPROM 1,( $32 )    ; %0011---- %0010----   8-bit / 4-bit

        ' Byte commands - To configure the LCD

        EEPROM 2,( $28 )    ; %00101000 %001LNF00   Display Format
        EEPROM 3,( $0C )    ; %00001100 %00001DCB   Display On
        EEPROM 4,( $06 )    ; %00000110 %000001IS   Cursor Move

                            ; L : 0 = 4-bit Mode    1 = 8-bit Mode
                            ; N : 0 = 1 Line        1 = 2 Lines
                            ; F : 0 = 5x7 Pixels    1 = N/A
                            ; D : 0 = Display Off   1 = Display On
                            ; C : 0 = Cursor Off    1 = Cursor On
                            ; B : 0 = Cursor Steady 1 = Cursor Flash
                            ; I : 0 = Dec Cursor    1 = Inc Cursor
                            ; S : 0 = Cursor Move   1 = Display Shift

        EEPROM 5,( $01 )    ; Clear Screen

        RETURN

    SendInitCmdByte:

        PAUSE 15                        ; Delay 15mS

    SendCmdByte:

        rsbit = RSCMDmask               ; Send to Command register

    SendDataByte:

        pins = byte1 & %11110000 | rsbit ; Put MSB out first
        PULSOUT E,1                     ; Give a 10uS pulse on E
        pins = byte1 * %00010000 | rsbit ; Put LSB out second
        PULSOUT E,1                     ; Give a 10uS pulse on E

        rsbit = RSDATmask               ; Send to Data register next

        RETURN
 

George Sephton

Senior Member
To start with you gonna want to know how the stuff is sent, for starter you're gonna run into a lot of trouble if you want to write things to the eeprom then write to the LCD Screen.

Remember you can write to each line with this code:
Code:
byte1 = $80 ;Top Line
gosub SendCmdByte

(Everything you want on the top line here)

byte1 = $C0 ;Bottom Line
gosub SendCmdByte

(Everything you want on the bottom line here
Next to write without eeprom:
Code:
for counter = 0 to 4
lookup counter, ("Hello"), byte1
gosub SendDataByte
next counter
Note that the counter is 0 to 4, ie 5 letters to be displayed 0-4 (inclusive)
Also watch out that if you put counter = 0 to 10 you will get Hellooooooo

Final Point is bringing it together.
All that's needed is a sub-procedure to run it:

Code:
byte1 = $80 ;Top Line
gosub SendCmdByte

for counter = 0 to 4
lookup counter, ("Hello"), byte1
gosub SendDataByte
next counter
Now to implement it into your code:

Keep your: PowerOnReset sub and the InitialiseLcd sub, but everything in between can be replaced with something like this:

Code:
......
PowerOnReset:
GOSUB InitialiseLcd

ShowLCD:
byte1 = $80 ;Top Line
 gosub SendCmdByte

 for counter = 0 to 4
 lookup counter, ("Hello"), byte1
 gosub SendDataByte
 next counter
goto Main

Main:
(Here is your normal code, you could also use the above to rewrite to the 2nd line for example, or loop back to it: goto ShowLCD)
goto Main

InitialiseLcd:
.....
Hope that helps cos I had trouble when I first started.
 
Top