Newbie? Problem with LCD


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2008
    Posts
    33

    Default Newbie? Problem with LCD

    Hi All,
    I put myself down as a newbie even though I played with Pic's over a year ago.
    The problem I have stems from I had a severe brain injury and had to undergo surgery, and since then I have had problems remembering things.

    I've had to start leaning about Pic's and PBP from scratch really.

    To help myself I bought an easypic 6 but decided to stick with PBP instead of Mikrobasic (had a quick look and it seemed really hard compared to PBP)

    I cant figure out what I'm doing wrong,
    I'm trying to get the simle "hello world" lcd test working but it just wont

    My code is as follows
    Code:
    '****************************************************************
    '*  Name    : Test.BAS                                          *
    '*  Author  : Lewis                                             *
    '*  Notice  :                                                   *
    '*          : All Rights Reserved                               *
    '*  Date    : 07/12/2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
      @   DEVICE pic16F887,HS_OSC
       'LCD DEFINATION
            DEFINE OSC 8
            DEFINE LCD_DREG PORTB       ' Set LCD Data port
            DEFINE LCD_DBIT 0           ' Set starting Data bit (0) 
            DEFINE LCD_RSREG PORTB      ' Set LCD Register Select port
            DEFINE LCD_RSBIT 4          ' Set LCD Register Select bit, Port B.4
            DEFINE LCD_EREG PORTB       ' Set LCD Enable port
            DEFINE LCD_EBIT 5           ' Set LCD Enable bit, PORTB.5
            DEFINE LCD_BITS 4           ' Set LCD bus size 4 bits
            DEFINE LCD_LINES 2         ' Set number of lines on LCD to 4 Lines
            DEFINE LCD_COMMANDUS 2000   ' Set command delay time in us
            DEFINE LCD_DATAUS 50        ' Set data delay time in us
    
    '*******************************************************************************
       pause 500       ' Wait for LCD to startup
    
    loop:   Lcdout $fe, 1   ' Clear LCD screen
            Lcdout "Hello"  ' Display Hello
            Pause 500       ' Wait .5 second
    
            Lcdout $fe, 1   ' Clear LCD screen
            Lcdout "World"
            Pause 500       ' Wait .5 second
    
            Goto loop       ' Do it forever
    I set it like that after studying the easypic manual and lcd that came with it

    I use MicroCode Studio

    The programmer is the picflash program that came with the easypic board, the xtal is 8Mhz

    When I write the program in Microcode Studio I get a wierd effect when choosing a 16F887 PIC
    the ICD Compile row of buttons goes greyed out, yet they dont when choosing a 16F877
    Does this matter?


    I get the following error when I compile I have no idea what it is.
    Warning [207]C:P\pbp\tests\lcdtes~1.asm 108 : found label after colum 1. (DEVICE)
    Error [122] c:\pbp\tests\cdtes~1.asm 108 : Illegal opcode (pic16f877)

    IF I take the @ DEVICE pic16F877,HS_OSC out and put it as the first line of the program it does the same thing

    If I take it out altogether it compiles ok but just won't do anything with the LCD.

    I don't want anyone to write any code for me, I want and need to learn, however I'd really like someone to help please and explain what I'm doing wrong please.

    I also tried changing the osc to xt but it makes no difference.

    Has anyone any ideas? and sorry for asking for help for what must be to most of you a very simple problem, but I've spent 3 days trying to figure out what is wrong, as well as trying various combinations of code.

    Oh Picflash v7.13
    Microcode Studio ver 3.0.0.5
    PBP ver I THINK it's 2.50C but not sure how to check.
    Windows 7 X64

  2. #2
    Join Date
    May 2008
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    after much more reading I came up with the following, but it still doesn't do anything.
    I tested the board and pic by using the blinking led program and it works, and then modified that to alternativly turn on then off each led on port B (cycle through them) and that works, so the board works fine

    I just cant figure out how to get the lcd working.

    Code:
    define device pic16F887,HS_osc
    Define OSC 8
    adcon1 = 7
    trisb=%00000000
    
    '****************************************************************
    '*  Name    : Test.BAS                                          *
    '*  Author  : Lewis                                             *
    '*  Notice  :                                                   *
    '*          : All Rights Reserved                               *
    '*  Date    : 07/12/2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
       'LCD DEFINATION
            DEFINE LCD_DREG PORTB       ' Set LCD Data port
            DEFINE LCD_DBIT 0           ' Set starting Data bit (0) 
            DEFINE LCD_RSREG PORTB      ' Set LCD Register Select port
            DEFINE LCD_RSBIT 4          ' Set LCD Register Select bit, Port B.4
            DEFINE LCD_EREG PORTB       ' Set LCD Enable port
            DEFINE LCD_EBIT 5           ' Set LCD Enable bit, PORTB.5
            DEFINE LCD_BITS 4           ' Set LCD bus size 4 bits
            DEFINE LCD_LINES 2         ' Set number of lines on LCD to 4 Lines
            DEFINE LCD_COMMANDUS 2000   ' Set command delay time in us
            DEFINE LCD_DATAUS 50        ' Set data delay time in us
    
    '*******************************************************************************
       pause 500       ' Wait for LCD to startup
    
    loop:   Lcdout $fe, 1   ' Clear LCD screen
            Lcdout "Hello" ' Display Hello
            Pause 500       ' Wait .5 second
    
            Lcdout $fe, 1   ' Clear LCD screen
            Lcdout "World"
            Pause 500       ' Wait .5 second
    
            Goto loop       ' Do it forever
    Anyone?

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Ok, lew

    Seems you use MPASM as an assembler ...

    so don't use PM commands !

    Code:
    @ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    should Work somewhat better ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    You think this MikroBASIC code is more difficult than what you came up with?

    Code:
    program Lcd_demo
    
    main:
    
      Lcd_Init(PORTB)                    ' Initialize LCD connected to PORTB
      Delay_ms(500)
    
      While true
    
        Lcd_Cmd(LCD_CLEAR)               ' Send command to LCD "clear display"
        Lcd_Out(1,1,"Hello")               ' Print txt to LCD, 1st row, 1st column
        Delay_ms(500)
    
        Lcd_Cmd(LCD_CLEAR)               ' Send command to LCD "clear display"
        Lcd_Out(2,1,"World")              ' Print txt to LCD, 2nd row, 1st column
        Delay_ms(500)
    
      Wend
    
    end.
    Last edited by rmteo; - 7th December 2009 at 16:32.

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    lew247,

    Your problem is at PORTB config;

    For 16F887, there are some registers controlling PORTB.
    You have non of them configured.

    If you use the LCD with PORTD, you need no setting for the port. I am sure it will work.
    But I am not sure if you can switch to PORTD with your existing pcb.

    ------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Talking Backfire ...

    Quote Originally Posted by rmteo View Post
    You think this MikroBASIC code...
    Hi, Rmteo

    PBP also has the While - Wend loops ... LOL

    Seriously ... Having tested both ... on " real " programs.

    No comparison possible ... MkBasic FAR Behind ...


    BTW ... If you'd want a C Pro license ... I GIVE you mine.

    Not Joking at all !

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    May 2008
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Ok, lew

    Seems you use MPASM as an assembler ...

    so don't use PM commands !

    Code:
    @ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    should Work somewhat better ...

    Alain

    Sorry I forgot totally about that, PM would not work at all,because I have an X64 system

    For some reason @ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF will not work

    If I add it at the beginning I get Error [118] c:\pbp\tests\cdtes~1.asm 108 : Overwriting previous address contents (2007)

    If I put this at the beginning of the program it compiles with no errors but won't work.
    Code:
    Define Device 16f887
    Define OSC 8
    adcon1 = 7
    PORTB  = %00000000
    TRISB  = %00000000 
    IOCB = 0
    CM1CON0 = 0
    CM2CON0 = 0
    CCP1CON = 0
    CM2CON1 = 0
    INTCON = 0
    I checked the datasheet of the 16f887 (using this because it came supplied with it) and I THINK I've configured all registers on PortB


    It would be good if I could change LCD pins as suggested but unfortunately not possible on this board.
    And I need to learn what is wrong so next time I won't (hopefully) need to ask for help.

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    If I add it at the beginning I get Error [118] c:\pbp\tests\cdtes~1.asm 108 : Overwriting previous address contents (2007)
    Yes ...

    With MPLAB you also must comment the PBP default config in the relevant .inc file ...

    see details here:

    http://www.picbasic.co.uk/forum/showthread.php?t=543

    ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Rmteo

    PBP also has the While - Wend loops ... LOL

    Seriously ... Having tested both ... on " real " programs.

    No comparison possible ... MkBasic FAR Behind ...


    BTW ... If you'd want a C Pro license ... I GIVE you mine.

    Not Joking at all !

    Alain
    Although I am not a C user, I'll take it.

  10. #10
    Join Date
    May 2008
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Got it working at last
    Thanks for all the help everyone.

    I think the problem I had was I was trying to overwrite the inc files without realising.

    I now have @ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    as the config

    However the programmer always tried to program in low voltage mode, I have to manually set it to off.

    I'd like to sort that out, but I can live with it if needed.

    Edit: Works with 16F877A but not 16F887 for some weird reason!

    found it!

    This works for the 16f887
    Code:
    @ __config _CONFIG1, _HS_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    Define device 16F887
    Define OSC 8
    ANSEL=0  ' A/D disabled for ANS0 to ANS7
    ANSELH=0 ' A/D disabled for ANS8 to ANS13
    CM1CON0 = 0 ' Disable comparators
    CM2CON0 = 0 ' These default to disabled at POR, but just in case
    CM2CON1 = 0
    adcon1 = 7
    IOCB = 0
    INTCON = 0
    ansel = 0 
    anselh = 0
    PORTB  = %00000000
    TRISB  = %00000000
    However still got the programming issued I've got to set the low power programming to off manually and the oscillator to HS
    Last edited by lew247; - 7th December 2009 at 18:51.

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    May be you should have a look to the upper part of the MPLAB Configuration bits window ...

    an option to choose ...


    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. LCD problem with 16F628
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 19th September 2016, 08:28
  2. LCD problem
    By Andre_Pretorius in forum General
    Replies: 8
    Last Post: - 27th January 2009, 15:47
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. LCD Problem
    By karenhornby in forum General
    Replies: 3
    Last Post: - 19th June 2008, 11:43
  5. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07

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