PIC 18f4525 to 16x1 LCD Programming Issue

jac4ever2000

New member
Hi. I'm interfacing the 18f4525 with a CFAH1601A-NYA-JP. I've tested the lcd with the software through the parallel port to check and make sure everything is ok. It is and displays words fine. Voltage, etc... I've written a program to try to display a word on the lcd from the pic done in MPLAB IDE. When we pop the pic on the board and connect the power, it just shows the blocks on the lcd while faintly flashing as if its trying to do the initilization and routine we have written. The display does some crazy things with the solid blocks showing. Any help is appreciated.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Last edited:

jac4ever2000

New member
Here is our code were working with. We re-wrote it from scratch again, going through step by step with the data sheets. The pic is behaving wierdly though. We have high voltages where we shouldn't it seems like. Any help is much appreciated.
Code:
#include "p18f4525.h"
#include "stdlib.h"
#include "stdio.h"
#include "delays.h"
#include "header3.h"

#define E PORTDbits.RD7
#define RW PORTDbits.RD6
#define RS PORTDbits.RD5

 
void main(void)
{

PORTB = 0x00;	// port b register has initial value of all zeros
TRISB = 0x00;	// set port b as all outputs

TRISDbits.TRISD7=0;		// sets E (portD bit 7) as output
TRISDbits.TRISD6=0;		// sets RW (portD bit 6) as output
TRISDbits.TRISD5=0;		// sets RS (portD bit 5) as output


/*		begin initialization routine		*/

DelayPO();

RW =0;
RS =0;
PORTB = 0x30;		// send function set
E = 1; 
Delay_100();
E = 0;

Delay_41();		// delay 4.1ms
PORTB = 0x30;		// send function set
E = 1; 
Delay_100();
E = 0;

Delay_100();		// delay 100us
PORTB = 0x30;		// send function set
E = 1; 
Delay_100();
E = 0;

Delay_41();		// delay 4.1ms
PORTB = 0x30;		// send function set
E = 1; 
Delay_100();
E = 0;


while(BusyLCD());
PORTB = 0x08;	// set port to display off
E = 1;
Delay_100();
E = 0;

while(BusyLCD());
PORTB = 0x01;	// set port display clear
E = 1;
Delay_100();
E = 0;

while(BusyLCD());
PORTB = 0x07;	// set port to entry mode set
E = 1;
Delay_100();
E = 0;

/*		end initialization routine  */

DelayPO();


/*		send data		*/

RS = 1;
RW = 0;

while(BusyLCD());
PORTB = 0x42;	// send letter "B"
E = 1;
Delay_100();
E = 0;

while(BusyLCD());
PORTB = 0x6C;	// send letter "l"
E = 1;
Delay_100();
E = 0;

while(BusyLCD());
PORTB = 0x75;	// send letter "u"
E = 1;
Delay_100();
E = 0;

while(BusyLCD());
PORTB = 0x65;	// send letter "e"
E = 1;
Delay_100();
E = 0;

while(BusyLCD());
RS = 0;
RW = 0;
PORTB = 0x02;	// send command Return Home
E = 1;
Delay_100();
E = 0;

while(BusyLCD());
RS = 0;
RW = 0;
PORTB = 0x0C;	// send command Display ON
E = 1;
Delay_100();
E = 0;

/*		end of data send	*/



//while(1);
return;
}



/*   delays @ 1Mhz  */

void DelayPO(void)	// power on delay = 15ms min
{
Delay10TCYx(375);	// 3750TCY = 15,000 clock cycles
}

void Delay_41(void)	// delay = 4.1ms min
{
Delay10TCYx(103);	// 1030TCY = 4,120 clock cycles
}

void Delay_100(void)	// delay = 100us min
{
Delay10TCYx(3);	// TCY 30 = 120 clock cycles
}


void DelayFor18TCY(void)
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}



/*    test busy flag   */

unsigned char BusyLCD(void)
{
        RW = 1;                     // Set the control bits for read
        RS = 0;
        DelayFor18TCY();
        E = 1;                      // Clock in the command
        DelayFor18TCY();

        if(PORTB & 0x80)                      // Read bit 7 (busy bit)
        {                               // If high
                E = 0;              // Reset clock line
                RW = 0;             // Reset control line
                return 1;               // Return TRUE
        }
        else                            // Bit 7 low
        {
                E = 0;              // Reset clock line
                RW = 0;             // Reset control line
                return 0;               // Return FALSE
        }
}
 
Your last "send function set", 0x30, in the init portion, leaves the display in 4 bit mode, and none of your following command or data writes are double-nibble. If you want 8 bit data bus mode, your init should be: 0x30, 0x30, 0x30, 0x38, etc. Otherwise, the rest looks like it should work.
 
Top