cant get my Lcd to work using Pic18f452


Closed Thread
Results 1 to 14 of 14
  1. #1

    Default cant get my Lcd to work using Pic18f452

    i am new to this so please help me out in anyway. I trying to get my code to work and so far i am getting just black boxes on the lcd display..

    i also get this error when compileing "config has been deprecated for 18f devices


    define LCD_DREG PORTB ' set LCD Data port
    '
    define LCD_DBIT 4 ' set starting data bit
    '
    define LCD_RSREG PORTB ' set LCD registers
    '
    define LCD_RSBIT 2 ' set LCD register select bit
    '
    define LCD_EREG PORTB ' set LCD enable port
    '
    define LCD_EBIT 3 ' set LCD enable bit
    '
    DEFINE LCD_BITS 4 ' set LCD bus size
    '
    define LCD_LINES 4 ' set number of lines on LCD
    '
    define LCD_COMMANDUS 2000 ' set command delay time in us
    '
    define LCD_DATAUS 50 ' set data delay time in us
    '''''''''''''''''

    '''Variables'''
    v1 var word 'Variable where digital value will be stored
    '''''''''''''''

    '''TRIS registers'''

    trisb = %00000000 'Set PORTB pins as outputs
    ''''''''''''''''''''

    ' This 'INCLUDE' routine is use to read a matrix keypad.
    ' Allow to use various keypad format
    ' Allow to place the keypad ROW and COL on different PORT.
    ' The routine set TRIS register for you

    ' How to use it
    ' =============
    ' 1. Include the file
    ' write
    ' INCLUDE "KeyPad.bas"
    ' somewhere in your code.. after TRIS setting and before MAIN loop
    '
    ' 2. Call the Keypad routine by one or the other method bellow
    ' 1. By calling the macro
    ' @ READKEYPAD _YourVar
    ' result store in 'YourVar' wich must be defined as a BYTE sized variable
    '
    ' 2. By using GOSUB
    ' GOSUB KeypadScan
    ' result is store in 'Key' Variable

    ' Specific DEFINE
    ' ===============
    ' The defaults setings are
    ' 1. Keypad ROW are connected to PORTB<3:0>
    ' 2. Keypad COL are connected to PORTB<7:4>
    ' 3. Debounce delay = 200 mSec
    ' 4. No auto-repeat
    ' 5. Keypad type 4X4
    '
    ' If you decide to change default settings, here's the DEFINEs list
    ' DEFINE KEYPAD_ROW 4 ' 4 ROW keypad
    ' DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB
    ' DEFINE KEYPAD_ROW_BIT 4 ' ROW0 = PORTB.4
    ' DEFINE KEYPAD_COL 4 ' 4 COL keypad
    ' DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
    ' DEFINE KEYPAD_COL_BIT 0 ' COL0 = PORTB.0
    ' DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
    ' DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature
    '
    ' When using the auto-repeat feature, the delay is the debounce delay (DEBOUNCEMS)

    ' Hardware Connection
    ' ===================
    ' 1. Column bits must have Pull-up resistor attach to VCC
    ' 2. ROW bits must be connected in serie with resistor.

    ' Results
    ' =======
    ' Results are always set the same way, even with different keypad type
    '
    ' 3X4
    ' ---
    ' Col0 Col1 Col2 Col3
    ' ---- ---- ---- ----
    ' 1 2 3 4 Row0
    ' 5 6 7 8 Row1
    ' 9 10 11 12 Row2
    '
    ' 6X5
    ' ---
    ' Col0 Col1 Col2 Col3 Col4
    ' ---- ---- ---- ---- ----
    ' 1 2 3 4 5 Row0
    ' 6 7 8 9 10 Row1
    ' 11 12 13 14 15 Row2
    ' 16 17 18 19 20 Row3
    ' 21 22 23 24 25 Row4
    ' 26 27 28 29 30 Row5
    '

    asm
    errorlevel 0,-207 ; Disable 'found opcode after...' warning

    ;
    ; Macro Definition
    ; ================
    READKEYPAD macro KeyVar
    L?CALL _KeypadScan
    MOVE?BB _Key,KeyVar
    endm

    ;
    ; Default settings
    ; ================
    KB_ROW = 4 ; 4 ROW keypad
    KB_ROW_PORT = PORTC ; Keypad ROW on PORTC
    KB_ROW_BIT = 0 ; ROW0 = PORTB.0
    KB_COL = 4 ; 4 COL keypad
    KB_COL_PORT = PORTC ; Keypad Col on PORTC
    KB_COL_BIT = 4 ; COL0 = PORTB.4
    DebounceDelay = d'200' ; debounce delay 200mSec

    ;
    ; Software Definition
    ; ===================
    ;
    ; Keypad type definition
    ; ----------------------
    ifdef KEYPAD_ROW
    KB_ROW = KEYPAD_ROW ; Assign amount of ROW
    endif

    ifdef KEYPAD_COL
    KB_COL = KEYPAD_COL ; Assign amount of COL
    endif

    ;
    ; ROW pins assignement
    ; --------------------
    ifdef KEYPAD_ROW_PORT
    KB_ROW_PORT = KEYPAD_ROW_PORT ; Assign ROW to user selected PORT
    endif

    ifdef KEYPAD_ROW_BIT
    KB_ROW_BIT = KEYPAD_ROW_BIT ; Assign ROW0 to user selected BIT
    endif

    ;
    ; COLUMN pins assignement
    ; -----------------------
    ifdef KEYPAD_COL_PORT
    KB_COL_PORT = KEYPAD_COL_PORT ; Assign COL to user selected PORT
    endif

    ifdef KEYPAD_COL_BIT
    KB_COL_BIT = KEYPAD_COL_BIT ; Assign COL0 to user selected BIT
    endif

    ;
    ; Keypad debounce delay
    ; ---------------------
    ifdef KEYPAD_DEBOUNCEMS
    DebounceDelay=KEYPAD_DEBOUNCEMS
    endif

    endasm

    '
    ' Variable definition
    ' ===================
    KB_ROW_PORT VAR BYTE EXT ' ROW port
    KB_COL_PORT VAR BYTE EXT ' COL port
    Col var byte '
    Row var byte '
    RowBit var byte '
    Key var byte ' result of scanned key
    KeyTemp var byte '

    '
    ' Constant definition
    ' ===================
    KeyMask con EXT ' Key mask when reading PORT
    InitialState con EXT ' initial ROW PORT value
    KB_ROW CON EXT ' # row
    KB_COL CON EXT ' # column
    KB_ROW_BIT CON EXT ' ROW0 bit
    KB_COL_BIT CON EXT ' COL0 bit
    DebounceDelay CON EXT ' Debounce delay, also Auto-Repeat delay if defined
    asm
    KeyMask = b'11111111' >> (8-KB_COL) ; use to keep only COL bits
    InitialState=b'00001111' << KB_ROW_BIT ; Initial state of ROW column bits
    endasm




    start:
    Pause 1500
    lcdout $fe, 1 ' clear display
    lcdout $fe, $80 ' move cursor to begining of line
    lcdout " Welcome to JDA Tech "
    lcdout $fe, $C0
    Lcdout " Wireless Sleep Apnea " ' output the following
    lcdout $fe, $94
    LCDout " Monitor"
    pause 3000
    '
    Main: ' Operations todo
    '
    Lcdout $fe, 1
    lcdout $fe, $80
    lcdout " Choose an Option"
    pause 3000
    lcdout $fe,1
    '
    lcdout $fe, $80
    lcdout "1 :Start to Record"
    lcdout $fe, $C0
    lcdout "2 :Stop " ' display on LCD
    pause 10000
    '
    lcdout $fe, 1
    lcdout $fe, $80
    lcdout "3: Send Data to RS-232"
    lcdout $fe, $C0
    Lcdout "4: Last Reading Percentage"
    gosub Keypadscan

    If (key = 1) then
    pause 100
    lcdout $fe, $D4, #key
    Goto Record
    endif
    IF (key = 2) then
    Pause 100
    lcdout $fe, $D4, #key
    Stop
    Endif
    IF ( key = 3 ) Then
    Pause 100
    lcdout $fe, $D4, #key
    GOTO Send
    endif
    If ( key = 5 ) then
    Pause 100
    lcdout $fe, $D4, #key
    Goto Percentage
    endif

    IF ( key > 5 ) then
    pause 100
    lcdout $fe, $C0
    Lcdout "Invalid Choice"
    GOTO main
    ENDIF
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    As far as the black boxes go, do you have a POT wired as a voltage divider with the wiper going to the contrast pin of the LCD?

    Look here for the new config.
    http://www.picbasic.co.uk/forum/show...ost13087#post6
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Black square could also mean that the LCD initialization haven't been done properly. Now why... maybe because the LVP mode is still enable, hence RB5 can't be used as a standard I/O. Make sure you disable it in your config fuses.

    The deprecated stuff is just a warning. you can disable it

    @ ERRORLEVEL -230

    in your code or modify the 18F452.inc file in your PBP folder.
    Code:
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F452, r = dec, w = -311, w = -230, f = inhx32
            INCLUDE "P18F452.INC"   ; MPASM  Header
            __CONFIG    _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H
            __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
            __CONFIG    _CONFIG4L, _LVP_OFF_4L
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	8
    This have been corrected in V2.47.
    Steve

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

  4. #4


    Did you find this post helpful? Yes | No

    Default disableing RB5

    thanks for the info.. one question on that though would it be that i would have to disable it from the trisb ?

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


    Did you find this post helpful? Yes | No

    Default

    Trisb be will set the I/O as an input or output. LCDOUT will automatically do it for you as well, but even with it, if you didn't disable the LVP mode, it will not work.

    Same rules apply with ADC, Comparator etc etc.
    Steve

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

  6. #6


    Did you find this post helpful? Yes | No

    Default follow up

    i could not access the inc file due to access is denied due to school computer. So i tried config 4l by the use of config4l= 0x81

    ; Default settings
    ; ================
    KB_ROW = 4 ; 4 ROW keypad
    KB_ROW_PORT = PORTC ; Keypad ROW on PORTC
    KB_ROW_BIT = 0 ; ROW0 = PORTB.0
    KB_COL = 4 ; 4 COL keypad
    KB_COL_PORT = PORTC ; Keypad Col on PORTC
    KB_COL_BIT = 4 ; COL0 = PORTB.4
    DebounceDelay = d'200' ; debounce delay 200mSec
    CONFIG4L =0x81

  7. #7
    Join Date
    Apr 2007
    Location
    Southern Ontario
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    I had the same problem and it drove me crazy untill I turned the lcd off an noticed for a spit second my message appear. Really look at that contrast pin and make sure you can fade the boxes on and off. This might not be the solution but it was in my case.
    Snap
    Beer is proof that God loves us and wants us to be happy.

  8. #8


    Did you find this post helpful? Yes | No

    Unhappy still having the same issues

    im still trying to get the lcd to work.. i dont know how to configure the lpv to disable and i looked at the contrast and it was fine since i used someones else program using the same pic that im using which is the pic18f452 and it came out working just fine. Im up for anymore ideas or anwsers to solve the problem at hand

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Read this, http://www.picbasic.co.uk/forum/showthread.php?t=543 it tells how to set the config fuses from inside the program. As mister_e points out in post #5 of that thread, you could still have problems. If you do it will be time to talk to your instructor.

    Now about the contrast pin. You said that you are using the same PIC as someone else. Do you mean PIC or project board?

    What happens when you adjust the pot tied to the LCD's contrast pin?

    It could be either one, LVP or contrast. If it is the same program as your friend , was your friend using the school's system.

    Let us know.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Could be interesting to have your whole schematic.
    Steve

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

  11. #11


    Did you find this post helpful? Yes | No

    Red face updated

    there is no pot on the board that i got. The lcd and keypad was preassembled by my instructor. trying to get a picture and or the schematic but dont have that at the momentThe pic he used was his daughters and it was the same as mine Pic18f452 and was demostrated that it work on the board that i have trouble with.

    I would like to take the time and say thank you for helping. Its some of the most help i got so far with this.

    so thank you
    Attached Images Attached Images  

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I have ran across LCD that does not need an adjusting pot, the contrast pin could be connected directly to 0 volt (ground) and would work. So it is possible your instructor was using one. But not very possible! I would say this happens maybe 1 out of 100 times. You need the adjusting POT.

    Questions that I am still not clear on:

    1- Are you using the exact same board and LCD as your instructor?

    2- Is the board and LCD a copy of the one your instructor has?

    3- Did you instructor compile his/her program on the same computer you are using? ( this is to test the LVP config)

    4- What does you instructor say about the problem?

    Please provide a drawing showing how the LCD is connected (draw it on paper and scan it if you have to)

    Go here http://www.microengineeringlabs.com/support/index.htm and you and the instructor look at the manual under LCDOUT, it shows the correct way to wire a LCD using PORTA as a default. I am not saying to use PORTA, but look at how the contrast is set up.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Civic

    I have an application with a 452 and LCD on port D ... works fine.

    Now, what I see is external interrupts are all on PortB ...

    So a special care to the corresponding registers has to be done.

    I also use PBP 2.47, but had explicitly ( correct ? ) written all registers ....

    Alain
    Attached Files Attached Files
    ************************************************** ***********************
    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 " !!!
    *****************************************

  14. #14
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default My 2 cents worth . . .

    Here is what I see:
    I see no config fuse settings in his code.
    I see a circuit board set up to use an oscillator module, not a crystal or resonator, so it would seem necessary to set fuses for External oscillator. Keypad code looks VERY FAMILIAR, like something mr_e once tossed together so I am pretty sure it is tested and working. In conclusion, I believe you need to work on your config settings, which should contain statements about _CONFIG1 EC_OSC and WDT_OFF etc . . .
    look at this data sheet.
    http://ww1.microchip.com/downloads/e...doc/39564b.pdf
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Pic18f452 with 20x4 LCD Help
    By djmachine in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th November 2008, 22:43
  2. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  3. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  4. Why doesn't my code for 18f452 work on 18f252?
    By senojlr in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2005, 02:42
  5. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22

Members who have read this thread : 0

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