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

📄 s6b33bd.c

📁 S6B33BD 点亮原程序
💻 C
字号:

#include <AT89X52.H>
#include <intrins.h>
#define CS1                    P3_5
#define RST                    P3_4
sbit SDA=P3^0;
sbit SCK=P3^1;

sbit SET=P1^2;



void Delay(unsigned int n)
{
    while(n--);
	return;
}

#pragma disable
void Write_Data(unsigned char dat)
{
    unsigned char idata i;
	SCK=0;
	Delay(1);
    SDA=1;
 	_nop_();
	SCK=1;
	_nop_();
	for(i=0;i<8;i++)
	{
	    SCK=0;
		SDA=dat&0x80;
		dat=dat<<1;
		SCK=1;
	}
	return;
}

#pragma disable
void Write_Instruction(unsigned char idata cmd)
{
    unsigned char idata i;
	SCK=0;
	_nop_();
    SDA=0;
	_nop_();
	SCK=1;
	_nop_();   
	for(i=0;i<8;i++)
	{
	    SCK=0;
		_nop_();
		SDA=cmd&0x80;
		cmd=cmd<<1;
		_nop_();
		SCK=1;
		_nop_();
	}
	return;
}

void OTP(unsigned char dat)
{
    RST=0;
	Delay(200);
    RST=1;
	Delay(10000);
    Write_Instruction(0x10);// sleep in

    Write_Instruction(0xd0);// set otp mode
    Write_Data(0x03);//0x00 0ff  0x03 on

    Write_Instruction(0xd3);// set otp data
    Write_Data(dat);//

    Write_Instruction(0xd1);// set otp address
    Write_Data(0x00);//0x00 elctronic volume  0x01 id2

    Write_Instruction(0xd2);// otp write 
    Write_Data(0x01);//0x00 disable  0x01 enable

    Delay(65000);
    Delay(65000);

    Write_Instruction(0xd2);// otp write 
    Write_Data(0x00);//0x00 disable  0x01 enable

    RST=1;
	Delay(10000);

	return;
}

#pragma disable
void Initial(void)
{
    Write_Instruction(0x11);// sleep out

    Write_Instruction(0x13);// normal diaplay mode on
   // Write_Instruction(0x23);// all pixel on

    Write_Instruction(0x25);// write contrast
    Write_Data(0x2f);//0x4f  def:3f    nor:2f  

	Write_Instruction(0x29);// display on

    Write_Instruction(0x2a);// column address set
    Write_Data(0x00);
    Write_Data(0x61);
    Write_Instruction(0x2b);// page address set
    Write_Data(0x00);
    Write_Data(0x45);

    Write_Instruction(0x36);// meory adta access control 
    Write_Data(0x00);

   // Write_Instruction(0x38);//idle mode off

    Write_Instruction(0x3a);// interface pixel format
    Write_Data(0x05);

}



/*
void Display_Grid(unsigned char value_first,unsigned char value_second)
{
    unsigned char i,j;

	Initial_Dispay_Line(0x40);
    for(i=0;i<0x06;i++)
	{
		Set_Page_Address(i);
        Set_Column_Address(0x00);
		for(j=0;j<96;j++)
		{
		    Write_Data(value_first);
		    Write_Data(value_second);
		}
	}
    return;
}
*/
void Display_Picture(unsigned char pic[])
{
    register unsigned char  i,j;
    register unsigned int tmp1=0;
	Write_Instruction(0x2c);  // memory write
    for(j=0;j<0x8c;j++)
	{
        for(i=0;i<0x62;i+=2)
		{
            Write_Data(pic[tmp1]);
            Write_Data(pic[tmp1+1]);
		    tmp1+=2;
	    }
	}
    return;
}

void Display_Color(unsigned char dat1,unsigned char dat2)
{
    register unsigned char  i,j;
	Write_Instruction(0x2c);  // memory write
    for(i=0;i<0x46;i++)
	{
		for(j=0;j<0x62;j++)
		{
		    Write_Data(dat1);
		    Write_Data(dat2);
		}
	}
    return;
}

void main(void)
{
    unsigned char tmp1=0x00;
    unsigned char tmp2=0x00;
    unsigned char tmp=0x00;
	Delay(1000);
	CS1=0;

    Initial();
    Display_Picture(pic);
	Delay(1000);

    while(SET==1)
	{
	  P1=0xff;
      if (P1_0==0)
	  { 
	      Delay(6000);
	      if (P1_0==0)  
		  { 
		      while(P1_0==0); 
			  if (tmp1<=0x0e) tmp1++; 
              Write_Instruction(0x25);
		      Write_Data(0x2f+(tmp1-tmp2)*2);
		  }
	  }
      if (P1_1==0)
	  { 
	      Delay(6000);
	      if (P1_1==0) 
		  { 
		      while(P1_1==0); 
			  if (tmp2<=0x0e) tmp2++; 
              Write_Instruction(0x25);
		      Write_Data(0x2f+(tmp1-tmp2)*2);
		  }
	  }

	}

	if (tmp1>tmp2) tmp=tmp1-tmp2;
    if (tmp1<tmp2) tmp=tmp2-tmp1+0x10;
	if (tmp1==tmp2) tmp=0x00;

    OTP(tmp);

    Initial();
	while(1)
	{
	Display_Picture(pic);
	Delay(65000);
    Delay(65000);

    Display_Color(0xf8,0x00);
 	Delay(65000);
 	Delay(65000);

    Display_Color(0x07,0xe0);
 	Delay(65000);
 	Delay(65000);

    Display_Color(0x00,0x1f);
 	Delay(65000);
 	Delay(65000);

    Display_Color(0xff,0xff);
 	Delay(65000);
 	Delay(65000);
    }

}

⌨️ 快捷键说明

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