Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

EasyPic2 + PIC 16f877A+LCD

Status
Not open for further replies.

common792

Junior Member level 3
Joined
Aug 20, 2011
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,486
Hi Everyone,

I am working on a development board called easypic2. I have to drive a LCD(160x128).
I am new in programming, My tutor gave my a code which displays few colours one at a time(red,green etc...).

He just wants me to write "Hello word" instead of all these colours.
Here is the code,cold give me an hand please?

Code:
//PORT DECLARATIONS
#define RS PORTB.F1
#define CS PORTB.F4
#define RW PORTB.F2
#define RST PORTB.F3
#define RD PORTB.F5
//-----------------------------------------------------------------------------

//------------------------------------------------------------------------------
//WRITE SEQUENCE
void write_1command(unsigned char command)
{
     PORTD = 0x00;
     RS = 0;

     CS = 0;
     RW = 0;
     PORTD = command;
     RW = 1;
     CS = 1;
     RS = 1;
}
void write_data(unsigned char data)
{
     PORTD = 0x00;
     CS = 0;
     RW = 0;
     PORTD = data;
     RW = 1;
     CS = 1;
}
void write_2command(unsigned char comm1,unsigned char comm2)
{
     write_1command(comm1);
     write_data(comm2);
}

void write_data_RGB(unsigned char Rdata,unsigned char Gdata,unsigned char Bdata)
{
     PORTD = 0x00;

     CS = 0;
     RW = 0;
     PORTD = Rdata;
     RW = 1;
     CS = 1;
     PORTD = 0x00;
     CS = 0;
     RW = 0;
     PORTD = Gdata;
     RW = 1;
     CS = 1;
     PORTD = 0x00;

     CS = 0;
     RW = 0;
     PORTD = Bdata;
     RW = 1;
     CS = 1;
}

//SHOW REGULAR PATTERN
void Fill_RAM(unsigned char Data1,unsigned char Data2,unsigned char Data3)
{
unsigned char i,j;

	for(i=0;i<128;i++)
	{
		for(j=0;j<160;j++)
		{

			Write_data_RGB(Data1,Data2,Data3);
		}
	}
}
//Setting start point of RAM
void Set_RAMSTART(unsigned char a, unsigned char b)
{
	Write_1Command(0x20);			// Display RAM X Starting Address
	Write_1Command(a);			//   Default => 0x00
	Write_1Command(0x21);			// Display RAM Y Starting Address
	Write_1Command(b);			//   Default => 0x00
}


//-------------------------------------------------------------------------------
//  Show Regular Pattern (Partial or Full Screen)
//
//    a: Start X Address
//    b: Start Y Address
//    c: Total Columns Devided by 2
//    d: Total Rows
void Fill_Block(unsigned char Data1, unsigned char Data2, unsigned char Data3, unsigned char a, unsigned char b, unsigned char c, unsigned char d)
{
unsigned char i,j;

	for(i=b;i<(b+d);i++)
	{
		for(j=0;j<c;j++)
		{
			Set_RAMSTART(a+j,i);
                        write_1command(0x22);
			Write_data_RGB(Data1,Data2,Data3);
		}
	}
}

//SHOW CHECKERBOARD PATTERN
void Checkerboard(unsigned char colour1R,unsigned char colour1G,unsigned char colour1B,
unsigned char colour2R,unsigned char colour2G,unsigned char colour2B)
{
unsigned char i,j,k,l;
         for(j=0;j<8;j++)
         {
         for(k=0;k<8;k++)
         {
         for(i=0;i<10;i++)
         {
               for(l=0;l<8;l++)
               {
               Write_data_RGB(colour1R,colour1G,colour1B);
               }
               for(l=0;l<8;l++)
               {
               Write_data_RGB(colour2R,colour2G,colour2B);
               }
        }
        }

        for(k=0;k<8;k++)
        {
        for(i=0;i<10;i++)
         {
               for(l=0;l<8;l++)
               {
               Write_data_RGB(colour2R,colour2G,colour2B);
               }

               for(l=0;l<8;l++)
               {
               Write_data_RGB(colour1R,colour1G,colour1B);
               }
        }
        }

        }
}

//MAIN PROGRAM
void main()
{
     ADCON1 = 0x07;
     TRISA = 0x00;
     PORTA = 0x00;
     TRISC = 0xFF;
     PORTC = 0x00;
     PORTB = 0x00;
     TRISD = 0x00;
     TRISB = 0x00;

     //------------------------------------------------------------------------
     //wait for button press on PORTC 0
     while(PORTC.F0 == 0)
     {
     Portd = 0x00;
     delay_ms(10);
     }
     //-------------------------------------------------------------------------
     //INITIAL STARTUP
     RD = 1;
     RS = 0;
     CS = 0;
     RW = 0;
     RST = 0;
     delay_ms(100);
     RST = 1;

     write_2command(0x06,0x00);    //Set Display On_Off (display off)
     write_2command(0x05,0x00);    //Set SOFT_RST (normal mode)
     write_2command(0x04,0x03);    //Set REDUCE_CURRENT (disp off analog RST)
     delay_ms(10);
     write_2command(0x04,0x00);    //(disp off, normal)
     delay_ms(10);
     write_2command(0x3B,0x00);
     write_2command(0x02,0x41);    //Set OSC_CTL (internal OSC on)
     write_2command(0x03,0x30);    //Set CLOCK_DIV (OSC clock 1)

     write_2command(0x08,0x01);    //Set PRECHARGE_TIME_R (1 CLK)
     write_2command(0x09,0x02);    //Set PRECHARGE_TIME_G (1 CLK)
     write_2command(0x0A,0x01);    //Set PRECHARGE_TIME_B (1 CLK)

     write_2command(0x0B,0x0A);    //Set PRECHARGE_CURRENT_R
     write_2command(0x0C,0x0A);    //Set PRECHARGE_CURRENT_G
     write_2command(0x0D,0x0A);    //Set PRECHARGE_CURRENT_B

     write_2command(0x10,0x46);    //Set DRIVING_CURRENT_R
     write_2command(0x11,0x38);    //Set DRIVING_CURRENT_G
     write_2command(0x12,0x3A);    //Set DRIVING_CURRENT_B

     write_2command(0x13,0x00);    //Set DISPLAY_MODE_SET (normal)
     write_2command(0x14,0x31);    //Set RGB_IF (MPU mode)
     write_2command(0x28,0x2F);    //Set DUTY
     write_2command(0x29,0x00);    //Set DSL

     write_2command(0x16,0x76);    //Set MEMORY_WRITE_MODE (Triple 6-bit mode)
     delay_ms(10);
     write_2command(0x3B,0x00);

     write_2command(0x80,0x00);    //Set IREF (controlled by external resistor)


     //write_2command(0x15,0x00);    //Set RGB_POL

     write_2command(0x17,0x00);    //Set MX1_ADDR
     write_2command(0x18,0x9F);    //Set MX2_ADDR
     write_2command(0x19,0x00);    //Set MY1_ADDR
     write_2command(0x1A,0x7F);    //Set MY2_ADDR
     write_2command(0x20,0x00);    //Set MEMORY_ACCESS_POINTER X
     write_2command(0x21,0x00);    //Set MEMORY_ACCESS_POINTER Y

     write_2command(0x2E,0x00);    //Set D1_DDRAM_FAC
     write_2command(0x2F,0x00);    //Set D1_DDRAM_FAR
     write_2command(0x31,0x00);    //Set D1_DDRAM_SAC
     write_2command(0x32,0x00);    //Set D1_DDRAM_SAR
     write_2command(0x33,0x00);    //Set SCR1_FX1 (0)
     write_2command(0x34,0x9F);    //Set SCR1_FX2 (159)
     write_2command(0x35,0x00);    //Set SCR1_FY1 (0)
     write_2command(0x36,0x7F);    //Set SCR1_FY2 (127)


     delay_ms(100);
     write_2command(0x06,0x01);    //Set DISP_ON_OFF (Display on)

     write_1command(0x22);         //Access Data Ram port

     while(1)
     {


     /*Fill_RAM(0x00,0x00,0x00);

     Fill_Block(0x00,0x00,0xFC,10,10,20,20);
     delay_ms(3000);*/

     Fill_RAM(0x00,0x00,0xFC);     //Fill screen with blue
     delay_ms(5000);

     Fill_RAM(0xFC,0x00,0x00);     //Fill screen with red
     delay_ms(5000);

     Fill_RAM(0x00,0xFC,0x00);     //Fill screen with green
     delay_ms(5000);

     Fill_RAM(0xFC,0xFC,0xFC);     //Fill screen with white
     delay_ms(5000);

     Checkerboard(0x00,0xFC,0x00,0x60,0x00,0xFC);   //show checkerboard
     delay_ms(10000);
     }


}


And Here is MY code.

#define ldata PORTD
#define RS PORTB.F1
#define CS PORTB.F4
#define RW PORTB.F2
#define RST PORTB.F3
#define RD PORTB.F5


void lcdcmd(unsigned char );
void lcddata(unsigned char );
void msdelay(unsigned char);
void write_2command(unsigned char);
 char value1='A';

void write_2command(unsigned char one, unsigned char two)
{
   lcdcmd(one);
   lcddata(two);
}
   
void main(void)
{
     ADCON1 = 0x07;
     TRISA = 0x00;
     PORTA = 0x00;
     TRISC = 0xFF;
     PORTC = 0x00;
     PORTB = 0x00;
     TRISD = 0x00;
     TRISB = 0x00;
     
 while(PORTC.F0 == 0)
     {
     Portd = 0x00;
     msdelay(10);
     }
     //-------------------------------------------------------------------------
     //INITIAL STARTUP
     RD = 1;
     RS = 0;
     CS = 0;
     RW = 0;
     RST = 0;
     msdelay(10);
     RST = 1;


     write_2command(0x06,0x00);    //Set Display On_Off (display off)
     write_2command(0x05,0x00);    //Set SOFT_RST (normal mode)
     write_2command(0x04,0x03);    //Set REDUCE_CURRENT (disp off analog RST)
     msdelay(10);
     write_2command(0x04,0x00);    //(disp off, normal)
     msdelay(10);
     write_2command(0x3B,0x00);
     write_2command(0x02,0x41);    //Set OSC_CTL (internal OSC on)
     write_2command(0x03,0x30);    //Set CLOCK_DIV (OSC clock 1)

     write_2command(0x08,0x01);    //Set PRECHARGE_TIME_R (1 CLK)
     write_2command(0x09,0x02);    //Set PRECHARGE_TIME_G (1 CLK)
     write_2command(0x0A,0x01);    //Set PRECHARGE_TIME_B (1 CLK)

     write_2command(0x0B,0x0A);    //Set PRECHARGE_CURRENT_R
     write_2command(0x0C,0x0A);    //Set PRECHARGE_CURRENT_G
     write_2command(0x0D,0x0A);    //Set PRECHARGE_CURRENT_B

     write_2command(0x10,0x46);    //Set DRIVING_CURRENT_R
     write_2command(0x11,0x38);    //Set DRIVING_CURRENT_G
     write_2command(0x12,0x3A);    //Set DRIVING_CURRENT_B

     write_2command(0x13,0x00);    //Set DISPLAY_MODE_SET (normal)
     write_2command(0x14,0x31);    //Set RGB_IF (MPU mode)
     write_2command(0x28,0x2F);    //Set DUTY
     write_2command(0x29,0x00);    //Set DSL


     write_2command(0x16,0x76);    //Set MEMORY_WRITE_MODE (Triple 6-bit mode)


     msdelay(10);
     write_2command(0x3B,0x00);

     write_2command(0x80,0x00);    //Set IREF (controlled by external resistor)


     //write_2command(0x15,0x00);    //Set RGB_POL

     write_2command(0x17,0x00);    //Set MX1_ADDR
     write_2command(0x18,0x9F);    //Set MX2_ADDR
     write_2command(0x19,0x00);    //Set MY1_ADDR
     write_2command(0x1A,0x7F);    //Set MY2_ADDR
     write_2command(0x20,0x00);    //Set MEMORY_ACCESS_POINTER X
     write_2command(0x21,0x00);    //Set MEMORY_ACCESS_POINTER Y

     write_2command(0x2E,0x00);    //Set D1_DDRAM_FAC
     write_2command(0x2F,0x00);    //Set D1_DDRAM_FAR
     write_2command(0x31,0x00);    //Set D1_DDRAM_SAC
     write_2command(0x32,0x00);    //Set D1_DDRAM_SAR
     write_2command(0x33,0x00);    //Set SCR1_FX1 (0)
     write_2command(0x34,0x9F);    //Set SCR1_FX2 (159)
     write_2command(0x35,0x00);    //Set SCR1_FY1 (0)
     write_2command(0x36,0x7F);    //Set SCR1_FY2 (127)


     msdelay(100);
     write_2command(0x06,0x01);    //Set DISP_ON_OFF (Display on)

     lcdcmd(0x22);         //Access Data Ram port
     }
void lcdcmd(unsigned char value1)
{
ldata=0;
RS=0;
RW=0;
CS=0;
RD=1;
ldata=value1;
msdelay(1);
RD=0;
RW=1;
CS=1;
RS=1;
}
void lcddata(unsigned char value1)
{
ldata=value1;
RS=1;
RW=0;
RD=1;
ldata= value1;
msdelay(1);
RD=0;
CS=1;
RS=1;
}

void msdelay(unsigned char itime)
{
unsigned char i,j;
for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}

My code is compiling(no errors) but it doesn't work. The display stay off.

Use CODE Tags when posting your code.

Thank you
 
Last edited by a moderator:

Can you post the schematic of your circuit and the datasheet of the particular GLCD?

BigDog
 

Hi,

I hope you are well.
Here is the schematic.
 

Attachments

  • Untitled.png
    Untitled.png
    71.3 KB · Views: 45

Hi,

Have you forgotten about me?:)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top