cant get my Lcd to work using Pic18f452


Results 1 to 14 of 14

Threaded View

  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

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