newbie LCD to 18F4520


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1

    Default newbie LCD to 18F4520

    Hi all
    I am trying to get my LCD working on a pic 18F4520. (have tested the LCD on a 16f628 and it definitely works but only have the .hex file from years ago)

    SO right now I attaching the code I have so far ...
    I'm just not sure I have the code all correct.
    Do I need to add things like DEFINES to change the default ports.
    I would also like to use the built in clock.This is in my code, please could someone just double check it is correct.

    Here is my code so far, I know it's probably very wrong but it's what I have so far.

    Code:
                OSCCON = $70            'Int CLK 8MHz
    OSCTUNE.6 = 1           'PLL 4x
    ADCON1= %00001111       '$0F = disable A/D converter
    
    TRISA = %00000000       'All pins are outputs
    TRISB = %00000000           
    TRISC = %00000000           
    TRISD = %00000000
    TRISE.0 = 0
    TRISE.1 = 0
    TRISE.2 = 0
    
    DEFINE OSC 32            '4x 8MHz
       Pause 500       ' Wait for LCD to startup
    
    loop1:   
       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 loop1       ' Do it forever
    My pinout are as follows and please see the attached diagram too
    1 VDD VSS
    2 VSS VDD
    3 VEE VEE (10k)
    4 RS 21(PortD.2)
    5 RW VSS
    6 E 22(PortD.3)
    7
    8
    9
    10
    11 D4 27(PortD.4)
    12 D5 28(PortD.5)
    13 D6 29(PortD.6)
    14 D7 30(PortD.7)
    15
    16

    I really would appreciate any help and suggestions.

    Kind regards
    Dennis
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Yes, you need to set the DEFINEs if you are not using the default port/pins.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks Mackrackit

    Ok I have altered my code to.. would appreciate if someone could check it's right

    Code:
    '*************************************
    'LCD code for 16 X 2  HD4x lcd
    '*************************************
    
    'Ocsillator selections here
    OSCCON = $70            'Int CLK 8MHz
    OSCTUNE.6 = 1           'PLL 4x
    ADCON1= %00001111       '$0F = disable A/D converter
    'END of oscillator selections
    
    
    'Port IO directions and presets for port pins begin here
    TRISA = %00000000       'All pins are outputs
    TRISB = %00000000           
    TRISC = %00000000           
    TRISD = %00000000
    TRISE.0 = 0
    TRISE.1 = 0
    TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
    'timer/oscillator defines 
    DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    
    'LCD defines begin here   
    DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
    DEFINE LCD_DREG PORTD 	'defines the port where data lines are connected to
    DEFINE LCD_DBIT 4 	'defines the position of data lines for 4-bit interface (0 or 4)
    DEFINE LCD_RSREG PORTD 	'defines the port where RS line is connected to
    DEFINE LCD_RSBIT 2 	'defines the pin where RS line is connected to 
    DEFINE LCD_EREG PORTD 	'defines the port where E line is connected to 
    DEFINE LCD_EBIT 3 	'defines the pin where E line is connected 
    DEFINE LCD_RWREG 0 	'defines the port where R/W line is connected to (set to 0 if not used)
    DEFINE LCD_RWBIT 0 	'defines the pin where R/W line is connected to (set to 0 if not used)
    DEFINE LCD_COMMANDUS 2000 	'defines the delay after LCDOUT statement 
    DEFINE LCD_DATAUS 200 		'delay in micro seconds
    'END of LCD DEFINES
    
    LCDINIT LcdCurBlink
       Pause 500       ' Wait for LCD to startup
    
    loop1:   
       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 loop1       ' Do it forever

  4. #4


    Did you find this post helpful? Yes | No

    Default Ok all fixed now...almost

    OK all fixed now and working ....well almost :-)
    This line was causing my problem
    LCDINIT LcdCurBlink

    so just took it out ! See the working code below ;-)
    Now there just one problem to sort out ... the "hello world' message writes itself on one long string and then repeats without anyspaces on the first and second lines ....
    something like this
    Hello||World||Hello||World||Hello||World||Hello||W orld||Hello||World||Hello||World||
    How do I format it to something like
    Hello
    World
    ?


    Code:
    '*************************************
    'LCD code for 16 X 2  HD4x lcd
    '*************************************
    
    'Ocsillator selections here
    OSCCON = $70            'Int CLK 8MHz
    OSCTUNE.6 = 1           'PLL 4x
    ADCON1= %00001111       '$0F = disable A/D converter
    'END of oscillator selections
    
    
    'Port IO directions and presets for port pins begin here
    TRISA = %00000000       'All pins are outputs
    TRISB = %00000000           
    TRISC = %00000000           
    TRISD = %00000000
    TRISE.0 = 0
    TRISE.1 = 0
    TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
    'timer/oscillator defines 
    DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    
    'LCD defines begin here   
    DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
    DEFINE LCD_DREG PORTD 	'defines the port where data lines are connected to
    DEFINE LCD_DBIT 4 	'defines the position of data lines for 4-bit interface (0 or 4)
    DEFINE LCD_RSREG PORTD 	'defines the port where RS line is connected to
    DEFINE LCD_RSBIT 2 	'defines the pin where RS line is connected to 
    DEFINE LCD_EREG PORTD 	'defines the port where E line is connected to 
    DEFINE LCD_EBIT 3 	'defines the pin where E line is connected 
    DEFINE LCD_RWREG 0 	'defines the port where R/W line is connected to (set to 0 if not used)
    DEFINE LCD_RWBIT 0 	'defines the pin where R/W line is connected to (set to 0 if not used)
    DEFINE LCD_COMMANDUS 2000 	'defines the delay after LCDOUT statement 
    DEFINE LCD_DATAUS 200 		'delay in micro seconds
    'END of LCD DEFINES
    
    
       Pause 500       ' Wait for LCD to startup
    
    loop1:   
       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 loop1       ' Do it forever

Similar Threads

  1. Newbie? Problem with LCD
    By lew247 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th December 2009, 19:48
  2. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

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