• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

CFAH2004L-TMI-JP and dspic microcontroller

Aaron

New member
Hi I am trying to use the CFAH2004L-TMI-JP in 4 bit mode and just display some characters on the lcd screen. I have tried to initilize the lcd driver and send A 3 times to the screen, but it doesnt seem to work. All I get is a blinking box that shifts itself 3 times to the right. Could someone look at my code and see where i might be going wrong? Thanks
Code:
#include "p30f2010.h"
#include "delay.h"
#define FCY 7372800		//XT oscillator frequency


_FOSC(CSW_FSCM_OFF & XT);			//XT , Failsafe clock off
_FWDT(WDT_OFF);						//Watchdog timer disabled
_FGS(CODE_PROT_OFF);				//Code protect disabled
_FBORPOR(PBOR_OFF & MCLR_EN &PWRT_16);    	//Brown-out reset disabled, MCLR reset enabled

	
	




/* #defines of the data pins and the corresponding tris pins */
#define PIN7            PORTEbits.RE0
#define PIN6            PORTEbits.RE1
#define PIN5            PORTEbits.RE2
#define PIN4            PORTEbits.RE3


//#define PIN3            PORTEbits.RE3
//#define PIN2            PORTEbits.RE2
//#define PIN1            PORTEbits.RE1
//#define PIN0            PORTEbits.RE0





#define E                 PORTCbits.RC13       
#define RW                PORTEbits.RE4       
#define RS                PORTEbits.RE5     

/*
#define E                TRISCbits.TRISRC13    
#define RW               TRISDbits.TRISRE4    
#define RS               TRISDbits.TRISRE5   
*/


void Delay200usXLCD(void);
void DelayMs(int dly);
void startup(void);
void A(void);
void DelayXLCD(void);
void space(void);




int main(void)

{
TRISE = 0x0000;				// All port E,D,C as output 
TRISD = 0x0000;
TRISC=0;

//servopwm();

startup();
Delay200usXLCD();

A();
A();
A();
DelayMs(9999);


return;
}


//lcd initilization as per lcd documentation

void startup(void)
{
DelayMs(200);

E=0;
Delay200usXLCD();
RS=0;
RW=0;


PIN7=0;
PIN6=0;
PIN5=1;
PIN4=1;
E=1;
Delay200usXLCD();
E=0;

DelayXLCD();


PIN7=0;
PIN6=0;
PIN5=1;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;

Delay200usXLCD();

PIN7=0;		//N
PIN6=0;		//F
PIN5=0;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;

DelayXLCD();

PIN7=0;
PIN6=0;
PIN5=1;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;

Delay200usXLCD();

PIN7=0;		//N
PIN6=0;		//F
PIN5=0;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;

DelayXLCD();


PIN7=0;
PIN6=0;
PIN5=0;
PIN4=0;
Delay200usXLCD();
E=1;
Delay200usXLCD();
E=0;

PIN7=1;
PIN6=1;		//D
PIN5=0;		//C
PIN4=0;		//B
E=1;
Delay200usXLCD();
E=0;

DelayXLCD();


PIN7=0;
PIN6=0;
PIN5=0;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;

PIN7=0;
PIN6=0;
PIN5=0;
PIN4=1;
E=1;
Delay200usXLCD();
E=0;

DelayMs(5);


PIN7=0;
PIN6=0;
PIN5=0;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;

PIN7=0;
PIN6=1;
PIN5=0;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;

DelayMs(50);


}

void A(void)		// A = binary 0100 0001
{
E=0;
RS=1;
RW=0;
Delay200usXLCD();


PIN7=0;
PIN6=0;
PIN5=1;
PIN4=0;
E=1;
Delay200usXLCD();
Delay200usXLCD();
E=0;

PIN7=0;
PIN6=1;
PIN5=0;
PIN4=0;
E=1;
Delay200usXLCD();
E=0;
}

void DelayMs(int dly)
{
 unsigned int x;

 while(dly >0)
 {
  x=5000;  
  while(--x)continue;  
  dly--;
 }
}


void Delay200usXLCD(void)	/* provides delay for 200uS */
{
    int i;
    for(i=0;i<72;i++)
        asm("clrwdt");
}

void DelayXLCD(void)  		/* provides delay for atleast 5msec */
{
    int i;
    for(i=0;i<1800;i++)
        asm("clrwdt");
}
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Top