CFAG320240C-FMI-T with a PIC18F8722

Tylerman

New member
Hi,
I have a CFAG320240C-FMI-T with a PIC18F8722 and with a 40MHz but it doesn't working. I thinks that it's my inititalisation and code... Can you send me un example for PICC to initialize ans write some information on the LCD...


thanks Yves
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

CF Support

Administrator
Here is some code we use on a demonstration board in-house with an ATMega32. You'll need to change the macros, but you should be able to port it over.
Code:
#define sbi(sfr,bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define cbi(sfr,bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

#define CLR_CS (cbi(PORTC,PC0))
#define SET_CS (sbi(PORTC,PC0))
  
#define CLR_RES (cbi(PORTB,PB5))
#define SET_RES (sbi(PORTB,PB5))
  
#define SET_A0 (cbi(PORTC,PC1))
#define CLR_A0 (sbi(PORTC,PC1))

#define CLR_E (cbi(PORTC,PC7))
#define SET_E (sbi(PORTC,PC7))

#define SDATA(x) (PORTA=x)
#define DATA(x) (PORTA=x)
/*   
void wait() 
{
	//_delay_cycles(4); //375nS
//	_delay_cycles(11); //1.031.25uS
	_delay_ms(10.0); //1.031.25mS
}
*/

void wait() 
{
	//_delay_cycles(4); //375nS
//	_delay_cycles(11); //1.031.25uS
	_delay_ms(1); //1.031.25mS
}

void COM_W(unsigned char data)
  {
  DATA(data);
  wait();
  SET_A0;
  wait();
  CLR_CS;
  //R/W is hardwired low
  wait();
  SET_E;
  wait();
  CLR_E;
  wait();
//  SET_CS;
  wait();
  }
void DATA_W(unsigned char data)
  {
  DATA(data);
  CLR_A0;
  CLR_CS;
  //R/W is hardwired low
  wait();
  SET_E;
  wait();
  CLR_E;
//  SET_CS;
  wait();
  }

void main(void) 
{
	Set_Default_Port_Directions();
  	//Idle the control lines & reset the display
	CLR_RES;
  	CLR_E;
  	CLR_A0;
  	SET_CS;
  	DATA(0);
  	wait();
	SET_RES;
  	wait();


	//SYSTEM_SET:
	COM_W(0x40);
	DATA_W(0x30);
	DATA_W(0x87); //FX
	DATA_W(0x07); //FX
	DATA_W(0x27); //CR
	DATA_W(0x42); //TC/R
	DATA_W(0xEF); //L/F
	DATA_W(0x28); //APL
	DATA_W(0x00); //APH
 
	//SCROLL:
	COM_W(0x44);
	DATA_W(0x00);
	DATA_W(0x00);
	DATA_W(0xEF); //L/F
	DATA_W(0x60); //SAD_2L
	DATA_W(0x09); //SAD_2H
	DATA_W(0xEF); //L/F
	//DATA_W(0x25); //SAD_3L
	//DATA_W(0x2F); //SAD_3H
	DATA_W(0x00); //SAD_3L
	DATA_W(0x00); //SAD_3H
	DATA_W(0x00);
	DATA_W(0x00);
	//HDOT_SCR:
	COM_W(0x5A);
	DATA_W(0x00);  //NO SCROLL
	//OVERLAY:
	COM_W(0x5B);
	//  DATA_W(0x00);   //GRAPHIC & OR
	DATA_W(0x01);   //GRAPHIC & XOR
	//  DATA_W(0x01F);   //"PRIORITY OR"
	//CSR_FORM:
	COM_W(0x5D);
	DATA_W(0x07);
	DATA_W(0x87);
	//CSR_DIR:
	COM_W(0x4C);

	//DISP_ON:
	COM_W(0x59);
	DATA_W(0x14);

//	Clear_Text_Layer();
//	CLEAR_LAYER_2();


	//CALL    POS2
	COM_W(0x46);
	DATA_W(0x60);
	DATA_W(0x09);

	//Dump the bitmap to the display
	COM_W(0x42);

	CLR_A0;
	CLR_CS;

	unsigned int i;

	for(i=0;i<240;i++)
	{
		DATA(i);
		SET_E;
		wait();
		CLR_E;
	}
	
	SET_CS;
/*
	//CALL    POS1
	COM_W(0x46);
	DATA_W(0x00);
	DATA_W(0x00);
	//Clear loop
	COM_W(0x42);
	CLR_A0;
	CLR_CS;

*/


	for(;;)
	{
		sbi(PORTD, PD2);
		_delay_ms(500);

		cbi(PORTD, PD2);
		_delay_ms(500);
	}
	
}
 

Tylerman

New member
Check it please

Hi,
I send to you a example of my code but I don't work... Can you help me...

Thanks
Code:
#include "test.h"
#include "..\commandes.h"

#define OK 'a'
#define C_DELAY 5


  void init()
   {

      setup_adc_ports(NO_ANALOGS|VSS_VDD);
        setup_adc(ADC_OFF|ADC_TAD_MUL_0);
       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_timer_3(T3_DISABLED|T3_DIV_BY_1);
       setup_timer_4(T4_DISABLED,0,1);
       setup_comparator(NC_NC_NC_NC);
       setup_vref(VREF_LOW|-2);
       setup_low_volt_detect(FALSE);
      setup_oscillator(False);


      	set_tris_b(0b10011111);
      	set_tris_c(0b10000000);
      	set_tris_d(0b00000000);

         set_tris_f(0b00000000);
         set_tris_j(0b00000000);


   }


//-------------------------------------------------------------------------------
      void datalcd( int8 data )  // Send one byte of data to LCD
      {



          output_f((data));
			 //output_d((data));
          delay_cycles(C_DELAY);

          output_bit(ENABLE,1);
          delay_cycles(C_DELAY);

          output_bit(ENABLE,0);



}

//-------------------------------------------------------------------------------
      void comlcd(int8 a){

         output_bit(A0,1);

         delay_cycles(C_DELAY);

         output_f((a));

         delay_cycles(C_DELAY);

         output_bit(ENABLE,1);

         delay_cycles(C_DELAY);

         output_bit(ENABLE,0);

         delay_cycles(C_DELAY);

         output_bit(A0,0);




    }
// -------------------------------------------------------------------------------

      void wipescreen( void )   // Wipe all three screen layers
      {
         //unsigned short t;  // Tempo
			int t;

         comlcd (0x46);	// Place cursor on the first data position
         datalcd(0x00);
         datalcd(0x00);

         comlcd (0x42);


	datalcd(0x00);
         datalcd(0x00);
         datalcd(0x00);
         datalcd(0x00);
         datalcd(0x00);

		}

// -------------------------------------------------------------------------------

    void init_afficheur(){

       output_j(0x00);
       output_f(0x00);



      // Chip Select
      output_bit(CS,0);

      // LCD Mode Write
      output_bit(RW,0);
      delay_ms(20);

      // Reset du controlleur
      output_bit(RES,0);
      delay_ms(20);
      output_bit(RES,1);
      delay_ms(20);

      



      comlcd(0x40);  // System set
      datalcd(0x30);	// P1 Internal CG ROM, No D6 correction, 8-pixel char height, Single-panel drive
      datalcd(0x87);	// P2 Cars 8 dots (FX)
      datalcd(0x07);	// P3 Cars 8 dots high  (FY)
      datalcd(39);  	// P4 C/R
      datalcd(0x42);  // P5 TC/R  ???
      datalcd(239);  	// P6 screen is 240 dots high L/F  (240-1)
      datalcd(0x28);  // P7 APL  Virtual screen ?
      datalcd(0x00);  // P8 APH  Virtual screen ?

      comlcd (0x44);	// Set display start adress and display regions
      datalcd(0x00);	// P1 Adresse Low  screen 1
      datalcd(0x00);	// P2 Adresse High screen 1
      datalcd(240);	// P3 Number of lines Y  (240)
      datalcd(0x80);  // P4 Adresse Low  screen 2
      datalcd(0x25);  // P5 Adresse High screen 2
      datalcd(240);   // P6 Number of lines Y   (240)
      datalcd(0x00);  // P7 Adresse Low   screen 3
      datalcd(0x4B);  // P8 Adresse High  screen 3

      comlcd (0x5A);	// Set horiz scroll position
      datalcd(0x00);	// P1 00 Scroll

      comlcd (0x5B);	// Set display overlay format
      datalcd(0x1D);  // P1 Exclusive-OR

      comlcd (0x5D);	// Cursor form
      datalcd(0x07);	// P1 Cursor 7 dots
      datalcd(0x87);	// P2 Block cursor, 8 dots high

      comlcd (0x4C); // Set cursor shift direction to right

      wipescreen();  // Erase (wipe) data in all tree screens

      comlcd (0x59);	// Display ON
      datalcd(0x54);	// Cursor OFF, Layer 1-2-3 à ON



    }



void main()
{
	

   init();

   init_afficheur();


   // Example to send data to screen

   comlcd (0x46);	// Place cursor in the middle of the screen 1 (aprox)
   datalcd(0xC0);

   datalcd(0x12);

   comlcd (0x42);
   datalcd(0x55);    // 0101010101     dots in this binary arrangement will be shown
   datalcd(0x20);
	comlcd (0x59);
   // END


   while(1){

      delay_ms(500);

   }
}
 
Top