I'm trying to use the C18 xlcd library to control a 16x2 LCD with an 18F1320. I've never used the screen before, but it initalises OK according to my question in another thread. I can see all blocks on one row (I assume the top).
I've only built this on breadboard so far and I have the following connections (tested with a multimeter between the PIC pin and the LCD):
RB0: Pin 11 of LCD
RB1: Pin 12 of LCD
RB2: Pin 13 of LCD
RB3: Pin 14 of LCD
RB4: Pin 6 of LCD (Enable)
RB5: Pin 4 of LCD (RS)
RB6: PGC to Junebug
RB7: PGD to Junebug
I have tied pin 5 (RW) and pins 7 to 10 (data) to ground.
I'm using U5V and the Junebug power (approx. voltage is about 4.3V on the LCD control pins). I have a capacitor across the power rails and also a resistor/LED to show when it is on.
My code is below. I've traced it with MPLAB and it never gets past the call to OpenXLCD(). A breakpoint on the line below never fires and it appears to sit waiting for the busy flag to clear.
One thing that seems really odd is this. When the code hits the line if(DATA_PORT&0x08), which checks the BUSY flag, pin 14 of the LCD (RB3) reads 0v. But a watch on PORTB shows 10011111. This means the BUSY flag is always set and it gets stuck in the BusyXLCD() loop, despite the fact there is no voltage on the pin.
The only other things that share the pin are CCP and P1A, I have tried disabling these with the following code but it didn't help:
If anybody can tell me what's wrong with it, or test it to see if it works for you, that would be excellent.
I've only built this on breadboard so far and I have the following connections (tested with a multimeter between the PIC pin and the LCD):
RB0: Pin 11 of LCD
RB1: Pin 12 of LCD
RB2: Pin 13 of LCD
RB3: Pin 14 of LCD
RB4: Pin 6 of LCD (Enable)
RB5: Pin 4 of LCD (RS)
RB6: PGC to Junebug
RB7: PGD to Junebug
I have tied pin 5 (RW) and pins 7 to 10 (data) to ground.
I'm using U5V and the Junebug power (approx. voltage is about 4.3V on the LCD control pins). I have a capacitor across the power rails and also a resistor/LED to show when it is on.
My code is below. I've traced it with MPLAB and it never gets past the call to OpenXLCD(). A breakpoint on the line below never fires and it appears to sit waiting for the busy flag to clear.
One thing that seems really odd is this. When the code hits the line if(DATA_PORT&0x08), which checks the BUSY flag, pin 14 of the LCD (RB3) reads 0v. But a watch on PORTB shows 10011111. This means the BUSY flag is always set and it gets stuck in the BusyXLCD() loop, despite the fact there is no voltage on the pin.
The only other things that share the pin are CCP and P1A, I have tried disabling these with the following code but it didn't help:
Code:
CCP1CONbits.CCP1M0 = 0;
CCP1CONbits.CCP1M1 = 0;
CCP1CONbits.CCP1M2 = 0;
CCP1CONbits.CCP1M3 = 0;
If anybody can tell me what's wrong with it, or test it to see if it works for you, that would be excellent.
Code:
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config OSC = INTIO2
#pragma config MCLRE = ON
#pragma config DEBUG = ON
#pragma config PWRT = ON
#pragma config BOR = OFF
#include <p18F1320.h>
#include <xlcd.h>
#include <delays.h>
void DelayFor18TCY( void )
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void DelayPORXLCD (void)
{
Delay1KTCYx(30); // Delay of 15ms
// Cycles = (TimeDelay * Fosc) / 4
// Cycles = (15ms * 8MHz) / 4
// Cycles = 30,000
return;
}
void DelayXLCD (void)
{
Delay1KTCYx(10); // Delay of 5ms
// Cycles = (TimeDelay * Fosc) / 4
// Cycles = (5ms * 8MHz) / 4
// Cycles = 10,000
return;
}
void main( void )
{
OSCCON = 0x72; /* Set internal oscillator at 8 Mhz */
ADCON0 = 0x00; /* Disable internal ADC */
ADCON1 = 0x7F; /* Set all PORTB to digital I/O */
// Have attempted delaying for up to 6*15ms here
// configure external LCD
OpenXLCD( FOUR_BIT & LINES_5X7 );
while(BusyXLCD());
WriteCmdXLCD(BLINK_ON);
while(BusyXLCD());
WriteDataXLCD(0x47); // write "Good Morning Dave"
while(BusyXLCD());
WriteDataXLCD(0x6F);
while(BusyXLCD());
// More the same as the above
while(1);
}