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;
}
}
}