⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3816(33b6).c

📁 yu sheng lcd driver program
💻 C
字号:
/**************************************************
	Summary       : 3816 FPC (IC: S6B33B6)							  
	First Edition : 2005-12-07
	Last Updata   : 2005-12-07
    Programmer    : skim							  
**************************************************/



#include <reg51.h>
#include <pic.h>

/***************************************************/
sbit  DI  = P3^5;
sbit  CS1 = P3^3;
sbit  WRE = P3^4;
sbit  RES = P3^7;

sbit  PUSH1 = P2^3;
sbit  PUSH2 = P2^2;
sbit  PUSH3 = P2^1;

	int con_v = 210;
	int int_v = 0;



/****************************************************
* D) Function Prototypes*
****************************************************/

void delay(unsigned int n)
{
unsigned int i,j;
for (i=0;i<n;i++)
  for (j=0;j<350;j++)
  {;}
  }


 /////////////////////////////////////////////////////////////////



void data_out(unsigned char i,j)
{
	DI  = 1;
//	RDE = 1;
	WRE = 0;
	P1  = i;
	WRE = 1;
	WRE = 0;
    P1  = j;
    WRE = 1;
}
void comm_out(unsigned char i)
{
	DI  = 0;
//	RDE = 1;
	WRE = 0;
    P1  = i;
	WRE = 1;
}


void resetLCD()
{

RES= 0;
delay(50);
RES= 1;
}



void init_LCD()
{
  	CS1  = 0;

  	comm_out(0x2C);//Standby mode off
  	delay(20);

  	comm_out(0x02);//Oscillation Mode Set
  	comm_out(0x01);//EXT=0, OSC=1
  	delay(20);

	
  	comm_out(0x26);//Driver Output Mode Set
  	comm_out(0x01);//DCDC1=1 (1'st booster On)
  	delay(20);

  	comm_out(0x26);//DCDC and AMP ON/OFF set
  	comm_out(0x09);//AMP=1
  	delay(20);

  	comm_out(0x26);
  	comm_out(0x0B);//DCDC2=1 (2'nd booster On)
  	delay(20);

  	comm_out(0x26);
  	comm_out(0x0F);//DCDC3=1 (3'rd booster On)
  	delay(20);


	comm_out(0x10);//Driver Output Mode Set
	comm_out(0x02);//DLN=00,MY=0,MX=0,SWP=1,CDIR=0

	comm_out(0x20);//DC-DC Select
	comm_out(0x02);//DC=10 (x2.0)

	comm_out(0x24);//DCDC Clock Division Set
	comm_out(0x0A);//DIV=1010 (fPCK=fOSC/22)

	comm_out(0x28);//Temperature Compensation Set
	comm_out(0x01);//TCS=1

  	comm_out(0x2A);//
  	comm_out(210); //

  	//comm_out(0x2B);
  	//comm_out(0xA0);

	comm_out(0x30);//Addressing Mode Set
	comm_out(0x0B);//GSM=0,DSG=0,SGF=1,SGM=1,SGP=01	

	comm_out(0x32);//ROW Vector Mode Set
	comm_out(0x0E);//INC=111,VEC=0

	comm_out(0x34);//N-block Inversion Set
	comm_out(0x0D);//FIM=0, FIP=0, N-block=13

	comm_out(0x36);//Driving Mode Set
	comm_out(0x00);//LFS=0

	comm_out(0x40);//Entry Mode Set
	comm_out(0x80);//16B=1,MDI=0,Y/X=0,RMW=0
	delay(10);

  	comm_out(0x42);//Row address Area Set
  	comm_out(0x00);//
  	comm_out(0x7F);//
	
	comm_out(0x43);//Column address Area Set
  	comm_out(0x00);//
  	comm_out(0x7F);//

	comm_out(0x45);//RAM skip Area Set
	comm_out(0x00);//RSK=00

	comm_out(0x53);//Specified Display Pattern Set
	comm_out(0x00);//SDP=00

	comm_out(0x55);//Partial Display Mode Set
	comm_out(0x00);//PT=0

  	delay(200);

	comm_out(0x51);//Display ON




}
/****************************************************
* LCD Demo Program for S6B33B0A *
* Main Program*
****************************************************/
void setColorMode(unsigned char i)
{
  switch (i)
   {
     case 1:
     //p256d
     comm_out(0x30);
     comm_out(0x6D);
     break;
     case 2:
     //p64kd
     comm_out(0x30);
     comm_out(0x0D);
     break;
     default: ;
   }
}

void dispPic(row,col,colorMode,unsigned char code *picture)
{
unsigned int i,j;
setColorMode(colorMode);
comm_out(0x51);
for(i=0;i<row*2;i++)///for(i=0;i<row*2;i++)
   {
     for(j=0;j<col-1;j=j+2)
      {
           data_out(picture[i*col+j],picture[i*col+(j+1)]);
      }
   }
}

void setDispArea(unsigned char x1,unsigned char x2,unsigned char y1,unsigned char y2)
{
 comm_out(0x42);
 comm_out(x1);
 comm_out(x2);//0x9F);
 comm_out(0x43);
 comm_out(y1);//0x00);
 comm_out(y2);//0x7F);
}
void Fulldisplay(unsigned char d1,d2)
{
    int i,j;
	comm_out(0x51);
    for(i=0;i<128;i++)
    {
       for(j=0;j<128;j++)
          {
           data_out(d1,d2);
          }
    }
}
void DISCONTEST(unsigned char d1,d2,d3,d4)
{
   int i,j;
   comm_out(0x51);
   for (j=0;j<32;j++)
      {
         for(i=0;i<128;i++)
            {
              data_out(d1,d2);
            }
       }
   for (j=0;j<64;j++)
      {
         for(i=0;i<29;i++)
            {
              data_out(d1,d2);
            }
          for(i=0;i<70;i++)
            {
              data_out(d3,d4);
            }
          for(i=0;i<29;i++)
            {
              data_out(d1,d2);
            }
       }
      for (j=0;j<32;j++)
         {
         for(i=0;i<128;i++)
            {
              data_out(d1,d2);
            }
         }
}

void DISPLAYCOLTP1()
{
   int i,j;
   comm_out(0x51);
   for(j=0;j<128;j++)
     {
        for(i=0;i<32;i++)
           {
            data_out(0xf8,0x00);
            }
        for(i=0;i<32;i++)
           {
            data_out(0x07,0xe0);
            }
        for(i=0;i<32;i++)
           {
            data_out(0x00,0x1f);
            }
        for(i=0;i<32;i++)
           {
            data_out(0xff,0xff);
            }
      }
}

void DISPLAYCOLTP2()
{
   int i,j;
   comm_out(0x51);
   for(j=0;j<32;j++)
     {
        for(i=0;i<128;i++)
           {
            data_out(0xf8,0x00);
           }
     }
   for(j=0;j<32;j++)
      {
        for(i=0;i<128;i++)
           {
            data_out(0x07,0xe0);
            }
      }
   for(j=0;j<32;j++)
       {
        for(i=0;i<128;i++)
           {
            data_out(0x00,0x1f);
            }
        }
   for(j=0;j<32;j++)
       {
        for(i=0;i<128;i++)
           {
            data_out(0xff,0xff);
            }
        }
}




void contrast (void) interrupt 0 using 0
{



	int j;
	j =	1;

	P2    = 0x07;
    PUSH1 = 1;
	PUSH2 = 1;
	PUSH3 = 1;


	while(j)
	{
		unsigned long i;
		while((PUSH1&&PUSH2&&PUSH3)!=0);
		for(i=0;i<2000;i++);
			switch(P2&0x0E)
			{
			case 0x06 :
				    comm_out(0x2A);	//set contrast and gain
    				comm_out(++con_v);
					comm_out(0x2B);//partial mode 2 contrast control
  					comm_out(0xA0);//v1=2.00

					break;
			case 0x0A :
				    comm_out(0x2A);	//set contrast and gain
    				comm_out(--con_v);
					comm_out(0x2B);//partial mode 2 contrast control
  					comm_out(0xA0);//v1=2.00
					break;
			case 0x0C :
			        j = 0;
					break;
			default:
			        break;

			}
	}

	while((PUSH1&&PUSH2&&PUSH3)==0);




	comm_out(0x51);

}


void main(void)
{



        TMOD   =  0x11;         // TMOD: 定时器1:模式1:16位;定时器2:模式1:1位   //
        IP  = 0x05;             //中断优先寄存器IP:|D7_x |x|x|PS|PT1|PX1|PT0|D0_PX0|//

        EX0=1;
        EA =1;


	init_LCD();
	while(1)
	{

		CS1= 0;
		delay(100);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		Fulldisplay(0xff,0xff);
		delay(500);

		setDispArea(0x00,0x7F,0x00,0x7F);
		Fulldisplay(0x00,0x00);
		delay(500);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		Fulldisplay(0xf8,0x00);
		delay(250);

		setDispArea(0x00,0x7F,0x00,0x7F);
		Fulldisplay(0x07,0xe0);
		delay(250);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		Fulldisplay(0x00,0x1f);
		delay(250);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		DISCONTEST(0X00,0X00,0xff,0xff);
		delay(250);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		DISCONTEST(0Xff,0Xff,0x00,0x00);
		delay(250);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		DISPLAYCOLTP1();
		delay(250);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		DISPLAYCOLTP2();
		delay(250);

		setDispArea(0x00,0x7F,0x00,0x7F);//setDispArea(0x00,0x9F,0x00,0x7F);
		dispPic(128,128,2,test);
		delay(500);
	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -