P18F4550 Clock setting and LCD problem

General discussion on mikroC.
Post Reply
Author
Message
Zed
Posts: 41
Joined: 20 Apr 2005 08:47
Location: UK

P18F4550 Clock setting and LCD problem

#1 Post by Zed » 11 Jun 2005 00:08

I am new to the P18F4550. Can someone please tell me which is the correct Project clock setting when using a 4MHz resonator in XT mode:

a. 004.000000 MHz with CPUDIV_OSC1_PPL2_1L selected, or

b. 001.000000 MHz with CPUDIV_OSC4_PPL6_1L selected.

Either of the above gives me the correct 1 second delay where coded below. However, the LCD I have connected to PortD resets on power-up, and the cursor flashes constantly at pos 1, 1. No string is displayed when the button is pressed/released, with either osc setting. The led functions normally.

I can replace the P18F4550 with a P18F452, recompile the same code, and everything works as expected. A second 4550 fails also.

Code: Select all

/*  PIC18F4550 with 4MHz resonator. Config bits:

    FOSC_XT_XT_1H
    PWRT_ON_2L
    WDT_OFF_2H
    PBADEN_OFF_3H
    LVP_OFF_4L

    Compiled with mikroC 2.0.0.3
    Programmed with PICFlash

    Trivial program to exercise an LED and LCD dislay, before learning the
    pitfalls of USB programming on a 4550...
*/







char *text1 = "Button pressed..";
char *text2 = "Button released.";

main()
{
    char x;

    PORTB  = 0b00000000;            // PortB outputs off
    TRISB  = 0b00010001;            // RB4, RB0 i/p, rest o/p
    RBPU   = ON;                    // PortB pull-ups on

    PORTD  = 0b00000000;            // Reset outputs
    TRISD  = 0b00000000;            // PortD all o/p

    LCD_Init(&PORTD);               // Initialise and clear the display
    LCD_Cmd(LCD_CLEAR);
    LCD_Cmd(LCD_CURSOR_OFF);

    for(x = 0; x < 10; x++)         // Flash LED 5 times, using 1 sec pause
    {
        led = !led;
        delay_ms(1000);
    }

    while(1)
    {
        if(!button)                 // Wait for the Start button
        {
            led = ON;               // Turn on LED and
            Lcd_Out(1, 1, text1);   // print text1 to LCD
            delay_ms(1000);         // then delay for 1 sec
            Lcd_Out(1, 1, text2);   // and print text2 to LCD
        }
        else                        // No push, so reset the LED
        {
            led = OFF;
        }
    }
}

Once I get this dang LCD sorted, I can play with USB... :( Help please!!

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: P18F4550 Clock setting and LCD problem

#2 Post by zristic » 11 Jun 2005 08:28


Zed
Posts: 41
Joined: 20 Apr 2005 08:47
Location: UK

#3 Post by Zed » 11 Jun 2005 13:06

Yep, that did the trick :)

Thanks very much to you, and to Jim (the original poster).

Post Reply

Return to “mikroC General”