p18f452 programming the CFAG320240CX-FMI-T

lloyen

New member
Hello,
I looked at the sample C code in the datasheet and converted it over to the pic I'm using, but cannot get the LCD to display anything. Here is my code:

Code:
#include "F:\TESTLCD\TESTLCD.h"
#include <math.h>

#use delay(clock=4000000)
void DATA_W(unsigned char);
void DATA(unsigned char);
void COM_W(unsigned char);
#define CLR_CS Pin_A2
#define SET_CS Pin_A2

#define CLR_A0 Pin_A1
#define SET_A0 Pin_A1

#define CLR_RES Pin_A3
#define SET_RES Pin_A3

#define CLR_E Pin_E1
#define SET_E Pin_E1
volatile unsigned int row;
volatile unsigned int col;
volatile unsigned int i;
volatile unsigned char c;

void DATA(char data1)
{
output_d (data1);
}
void COM_W(unsigned char data1)
{
DATA(data1);
output_high (SET_A0);
output_low  (CLR_CS);
output_high (SET_E);
output_low  (CLR_E);
}
void DATA_W(unsigned char data1)
{
DATA(data1);
output_low (CLR_A0);
output_low (CLR_CS);
output_high (SET_E);
output_low (CLR_E);
}




void main()
{
double i;
char c;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_oscillator(False);

//Idle control lines and reset the display
output_low (CLR_RES);
output_low (CLR_E);
output_low (CLR_A0);
output_high (SET_CS);
DATA(0x00);
delay_ms(1);
output_high (SET_RES);
delay_ms(100);

//Sets the LCD
COM_W(0x40);
DATA_W(0x30);
DATA_W(0x87);
DATA_W(0x07);
DATA_W(0x27);
DATA_W(0x42);
DATA_W(0xEF);
DATA_W(0x00);
delay_ms(100);

//SCROLLING ON LCD
COM_W(0x44);
DATA_W(0x00);
DATA_W(0x00);
DATA_W(0xEF);
DATA_W(0x60);
DATA_W(0x09);
DATA_W(0xEF);
DATA_W(0x00);
DATA_W(0x00);
DATA_W(0x00);
DATA_W(0x00);

//Horizontal Dot Screen
COM_W(0x5A);
DATA_W(0x00);

//Overlay
COM_W(0x5B);
DATA_W(0x01);

COM_W(0x58);
DATA_W(0x56);

//clear text layer and call position 1
c='A';
COM_W(0x46);
DATA_W(0x00);
DATA_W(0x00);
//Clear the loop
COM_W(0x42);
output_low (CLR_A0);
output_low (CLR_CS);


for(i=0;i<(0x28*30);i=i+1)
{
DATA(0x20);
output_high (SET_E);
output_low (CLR_E);
}
output_high (SET_CS);
//end clear text layer

//clear layer 2
COM_W(0x46);
DATA_W(0x60);
DATA_W(0x09);
//Clear loop
COM_W(0x42);
output_low (CLR_A0);
output_low (CLR_CS);
for(i=0; i<((0x28)*240);i=i+1) //240*APL
{
DATA(0x00);
output_high (SET_E);
output_low  (CLR_E);
}
output_high (SET_CS);
//end clear layer 2

//chip select read and write
COM_W(0x46);
DATA_W(0x00);
DATA_W(0x00);

//CSRFORM
COM_W(0x5D);
DATA_W(0x04);
DATA_W(0x86);

COM_W(0x59);//DISPLAY ON

COM_W(0x4C);//cursor direction shift to the right

COM_W(0x42);
DATA_W(0x20);//""
DATA_W(0x45);//E
DATA_W(0x50);//P
DATA_W(0x53);//S
DATA_W(0x4F);//O
DATA_W(0x4E);//N

while(1)
{
}

}
I think its a hardware problem but am not sure. Any suggestions?
Thanks!
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

lloyen

New member
Alright, here's the hardware setup. I have pin1 to ground, pin2 to an external pot(25k), pin3 to the same pot and going to +5V. Pin4 is going to pin9 on the pic. Pin5 is going to ground, pin6 is going to pin3 on the pic. Pin7-14 are going to port D, pin15 is going to pin4 on the pic. Pin16 is going to pin5 on the pic, pin17 is going to the pot, pin18 is going to ground. Pin19 is hardwired +5V and I have no clue what to do with pin20 the wait pin.
 

CF Support2

Administrator
For your supply, try just having your ground and +5v on pins 1 and 2. Since the CFAG320240CX has contrast circuitry built in, you can leave the pot off for controlling contrast -- the onboard pot should be good for you to start. This would have you leave Pin 3 open (Vo). Pins 19 and 20 we typically leave as no-connects when we work with this module. See if that helps.
 
Top