LCD problem


Closed Thread
Results 1 to 9 of 9

Thread: LCD problem

  1. #1

    Default LCD problem

    i am using a 18F4550 and the plan is to send messages from usb to the lcd, the problem is i can not get my screen stable, can i run the pic at 20Mhz?

    Any ideas would be welcome
    Code:
    INCLUDE "MODEDEFS.BAS"
    
    DEFINE LOADER_USED 1
    DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader
    
    DEFINE OSC 20				' Define crystal as 20Mhz
    
    'Define ACDIN parameters
    Define ADC_BITS 10 			' Set number of bits in result
    DEFINE ADC_CLOCK 3 			' Set clock source ( 3 = RC )
    DEFINE ADC_SAMPLEUS 50 		' Set sampling time to micro-seconds
    
    'This Part set PORTA 0-3 an analog inputs,4 as digital 
    TRISA = %00011111 			'set PORTA 0-5 as inputs
    ADCON1 = %00001010 			'ADC use vss and vdd as ref.
    ADCON2 = %10000111			'FRC (clock derived from A/D RC oscillator),Right justify output
    
    TRISC = %10000000
    TRISB = %10011000
    TRISD = %00000000
    
    '**************************************Serial port setup*************************************
    '*Serial port Setup 3800 8N1*
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 56  ' 38400 Baud @ 48MHz, -0.16%
    SPBRGH = 1
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    '**************************************LCD setup*********************************************
    ' Set LCD Data port
    DEFINE LCD_DREG PORTD
    ' Set starting Data bit (0 or 4)if 4-bit bus
    DEFINE LCD_DBIT 0
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTD
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 5
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTD
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 4
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 2000
    ' Set data delay time in us
    DEFINE LCD_DATAUS 50
    '**************************************Variables*********************************************
    buffer	Var	Byte[70]
    cnt	Var	Byte
    LED	Var	PORTD.4
    CELL1 var byte[70]
    i var byte
    
    USBInit
    Low LED		' LED off
    
    '**************************************Main Program******************************************
    
    
    LCDOUT $FE,1
    PAUSE 1000	
    main:
    	LCDOUT $FE,2
    	LCDOUT "line 1"
    	LCDOUT $FE, $C0
    	LCDOUT "line 2"
    	PAUSE 1000
    goto main 
    
    END

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


    Did you find this post helpful? Yes | No

    Default

    Hi Andre, Try this, dunno if it will help, but worth a try,
    Code:
    main:
    	LCDOUT $FE,$80
    	LCDOUT "line 1              "
    	LCDOUT $FE, $C0
    	LCDOUT "line 2"
    	PAUSE 1000
    goto main
    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.

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


    Did you find this post helpful? Yes | No

    Default

    How do you have the OSC configed?
    This might be a clue
    http://www.picbasic.co.uk/forum/show...9&postcount=14
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Dave, I don't think that your link will help because the code show that the OP use MicroChip bootloader.

    One day I should Try it myself

    Main Problem is
    Code:
    DEFINE OSC 20
    As far as I remember, Microchip Bootloader config fuses and code assume 48MHz BUT with a 20MHz crystal. So I would try
    Code:
    DEFINE OSC 48
    Last edited by mister_e; - 26th January 2009 at 23:13.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Well at least I got the OSC 48 part.
    Never used a boot loader though.

    Do you set the configs the same as with out one?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Most Bootloader I know, will ignore the config fuses in your code as they're already set in their firmware and don't have the ability to re-program them on the fly. HOWEVER, for many PIC18, you can do it later in your code. Darrel Already post something on that... BUT, using this, you will probably screw up most Bootloader... no free lunch

    Bootloader are nice for firmware upgrade, but for development, they have their own limitations.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for the info.
    Dave
    Always wear safety glasses while programming.

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Thanks guys
    Changing to define osc 48 fixed all the problems, LCD serial everything. Now for the question -- Why???
    On all the other projects you set the define to the cristal freq. but now you set almost 1.5 times higher.

    I am confused can someone PLEASE explain this to me

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


    Did you find this post helpful? Yes | No

    Default

    Well, look in the datasheet, Oscillator section, and check the available configuration fuses setting. Yes they're a bit tricky to understand...

    From there, you may discover that you can even have a processor speed of 48MHz using a 4MHz crystal... this is accomplished by the internal set of clock divider and PLL.

    As Microchip's bootloader set the Config Fuses for an internal processor speed of 48Mhz, your code must follow it.
    Steve

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

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. Newbie? Problem with LCD
    By lew247 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th December 2009, 19:48
  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 : 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