Need help with LCD number display.


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2007
    Posts
    10

    Question Need help with LCD number display.

    I am trying to find a way to display the number times a button is pushed on an LCD display. I can display strings such as 'Hello world', or 'Number = ' just fine but have trouble when I have a number stored in B10 (for example) and need to get it to the LCD.
    I am using the Lab-X1 with a 16F877A chip, and I am basing my code on the sample program 'PICBASIC program to demonstrate operation of an LCD in 4-bit mode'. I program in PICbasic. Any help would be appreciated.
    Thanks
    Steve

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Steve Matson View Post
    I can display strings such as 'Hello world', or 'Number = ' just fine but have trouble when I have a number stored in B10 (for example) and need to get it to the LCD.
    Thanks
    Steve
    Let's see the code you DO have and tell us what's wrong with it, so we can help you fix it.
    Last edited by skimask; - 29th May 2007 at 14:55.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    should be this one
    http://www.melabs.com/resources/samples/x1/pbc/lcdx.bas

    will check this latter today if someone didn't beat me to the punch... PBC is so WAY different of PBP. Too bad they don't have LCDOUT built-in
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    My guess is that you are sending a simple byte out to the LCD, and it is then displaying the ASCII equivalent. For example, take the following:
    Code:
    Number1 VAR BYTE
    
    Number1 = 123
    When Number1 is sent directly to the LCD, it will cause the “{“ to display.

    What you will need to do is enumerate each decimal place of the number and send that to the LCD. For example:
    Code:
    Number1	VAR BYTE
    Temp 	VAR BYTE
    
    Number1 = 123
    
    ‘Get Value of digit in 100’s place
    Temp = Number1/100 ‘With Number1 = 123 then Temp = 1
    Temp = Temp + 48 ‘Convert value to ASCII equivalent
    ‘Send temp to LCD
    
    ‘Get Value of digit in 10’s place
    Temp = Number/10 ‘With Number1 = 123 then Temp = 12
    Temp = Temp//10 ‘Get Remainder so with Number1 = 123 then Temp = 2
    Temp = Temp + 48 ‘Convert value to ASCII equivalent
     ‘Send temp to LCD
    
    ‘Get Value of digit in 1’s place
    Temp = Number1//10 ‘Get Remainder so…with Number1 = 123 then Temp = 3
    Temp = Temp + 48 ‘Convert value to ASCII equivalent
     ‘Send temp to LCD
    This will print out the leading "0"s, and will only enumerate a BYTE. It's just a simple code example, but it should help explain the concept and get you started on a more specific solution to met you needs.

    Hope this helps, good luck.

    SteveB
    Last edited by SteveB; - 29th May 2007 at 18:43.

  5. #5
    Join Date
    May 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Here is the code Im basing it on. Thank you for the help.

    ' PICBASIC program to demonstrate operation of an LCD in 4-bit mode

    Symbol PORTD = 8 ' PORTD is register 8
    Symbol PORTE = 9 ' PORTD is register 9
    Symbol TRISD = $88 ' PORTD data direction is register hexadecimal 88
    Symbol TRISE = $89 ' PORTD data direction is register hexadecimal 89
    Symbol ADCON1 = $9f ' ADCON1 is register hexadecimal 9f

    Poke ADCON1, 7 ' Set analog pins to digital
    Poke TRISD, 0 ' Set all PORTD lines to output
    Poke TRISE, 0 ' Set all PORTE lines to output
    Poke PORTE, 0 ' Start with enable low

    Pause 100 ' Wait for LCD to power up

    Gosub lcdinit ' Initialize the lcd

    loop: Gosub lcdclr ' Clear lcd screen
    For B4 = 0 To 4 ' Send string to lcd one letter at a time
    Lookup B4, ("Hello"), B2 ' Get letter from string
    Gosub lcddata ' Send letter in B2 to lcd
    Next B4
    Pause 500 ' Wait .5 second

    Gosub lcdclr ' Clear lcd screen
    For B4 = 0 To 4 ' Send string to lcd one letter at a time
    Lookup B4, ("world"), B2 ' Get letter from string
    Gosub lcddata ' Send letter in B2 to lcd
    Next B4
    Pause 500 ' Wait .5 second

    Goto loop ' Do it forever


    ' Subroutine to initialize the lcd - uses B2 and B3
    lcdinit: Pause 15 ' Wait at least 15ms

    Poke PORTD, $33 ' Initialize the lcd
    Gosub lcdtog ' Toggle the lcd enable line

    Pause 5 ' Wait at least 4.1ms

    Poke PORTD, $33 ' Initialize the lcd
    Gosub lcdtog ' Toggle the lcd enable line

    Pause 1 ' Wait at least 100us

    Poke PORTD, $33 ' Initialize the lcd
    Gosub lcdtog ' Toggle the lcd enable line

    Pause 1 ' Wait once more for good luck

    Poke PORTD, $22 ' Put lcd into 4 bit mode
    Gosub lcdtog ' Toggle the lcd enable line

    B2 = $28 ' 4 bit mode, 2 lines, 5x7 font
    Gosub lcdcom ' Send B2 to lcd

    B2 = $0c ' Lcd display on, no cursor, no blink
    Gosub lcdcom ' Send B2 to lcd

    B2 = $06 ' Lcd entry mode set, increment, no shift
    Goto lcdcom ' Exit through send lcd command

    ' Subroutine to clear the lcd screen - uses B2 and B3
    lcdclr: B2 = 1 ' Set B2 to clear command and fall through to lcdcom

    ' Subroutine to send a command to the lcd - uses B2 and B3
    lcdcom: Poke PORTE, 0 ' Set RS to command
    lcdcd: B3 = B2 & $f0 ' Isolate top 4 bits
    Poke PORTD, B3 ' Send upper 4 bits to lcd
    Gosub lcdtog ' Toggle the lcd enable line

    B3 = B2 * 16 ' Shift botton 4 bits up to top 4 bits
    Poke PORTD, B3 ' Send lower 4 bits to lcd
    Gosub lcdtog ' Toggle the lcd enable line

    Pause 2 ' Wait 2ms for write to complete
    Return

    ' Subroutine to send data to the lcd - uses B2 and B3
    lcddata: Poke PORTE, 1 ' Set RS to data
    Goto lcdcd

    ' Subroutine to toggle the lcd enable line
    lcdtog: Peek PORTE, B0 ' Get current PORTE value
    B0 = B0 | %00000010 ' Set lcd enable line high
    Poke PORTE, B0
    B0 = B0 & %11111101 ' Set lcd enable line low
    Poke PORTE, B0
    Return

  6. #6
    Join Date
    May 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default It's me again.

    I am begning to think that I should get PBP. I seems alot more powerful.
    Also I am tempted to look into the 'Lookup' and 'Lookdown' functions.
    Thanks for the tips.
    STeve

    P.S. Thanks to Steve B.
    That looks like something I can work with.
    Last edited by Steve Matson; - 30th May 2007 at 09:48.

  7. #7
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    Yeah - like with the standard version of most things in this World, PIC Basic is only half of what you get in the PRO version. I throughly read between the lines before I made the decision to buy PBP, which at the time, almost twice the amount of the standard.

  8. #8
    Join Date
    May 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Complete success!

    adding 48 to my number in the register worked great. I am still going to get the pro version. I hope there isnt too much of a learning curve from Picbasic.
    Steve

  9. #9
    Join Date
    May 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default I jsut purchased Pic Basic Pro.

    I just purchased Pic Basic Pro because I heard alot of great things about it.
    Again, Thanks for all the help.
    Steve.
    P.S. Just to let you know, Pics are often used in industry and it's good to mention on a resume if your going for any kind of technical job.

Similar Threads

  1. LCD Display
    By lambert in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th January 2010, 23:18
  2. LCD display not working properly
    By dilpkan in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd February 2008, 08:43
  3. Replies: 14
    Last Post: - 26th September 2007, 06:41
  4. LCD Display not working - PIC heating...
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 24th September 2006, 08:35
  5. A/D display result on LCD
    By winsthon in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 10th January 2004, 11:09

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts