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

📄 st7036.c

📁 一款车载蓝牙用单色屏液晶初始化代码
💻 C
字号:
#include <reg51.h>
#include <intrins.h>

#define Write_Address 0x78/*器件地址选择及写标志*/
#define Read_Address 0x79/*器件地址选择及读标志*/
#define CMD   0
#define DAT   1

sbit SDA=P1^7;/*串行数据*/
sbit SCL=P1^6;/*串行时钟*/
sbit RST=P3^5;/*复位*/


unsigned char code font[]=
{

};


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

/*发送起始条件*/
void Start(void)/*起始条件*/
{
    SDA=1;
    SCL=1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    SDA=0;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    return;
}

void Stop(void)/*停止条件*/
{
    SDA=0;
    SCL=1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    SDA=1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    return;
}

void Ack(void)/*应答位*/
{
    SDA=0;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    SCL=1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    SCL=0;
    return;
}

void Check_Ack(void)/*应答位*/
{
    unsigned char ack;
	SDA=1;
    SCL=1;
    _nop_();
    _nop_();
    _nop_();
    while(ack==1){ack=SDA;};
    _nop_();
    SCL=0;
    return;
}

void NoAck(void)/*反向应答位*/
{
    SDA=1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    SCL=1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    SCL=0;
    return;
}

void Send(unsigned char Data)/*发送数据子程序,Data为要求发送的数据*/
{
    unsigned char BitCounter=8;/*位数控制*/
    unsigned char temp;/*中间变量控制*/
    do
    {
        temp=Data;
        SCL=0;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        if((temp&0x80)==0x80)/*如果最高位是1*/
        SDA=1;
        else
        SDA=0;
        SCL=1;
        temp=Data<<1;/*RLC*/
        Data=temp;
        BitCounter--;
    }
	while(BitCounter);
    SCL=0;
}

void tansfer(unsigned char Flg,unsigned char Dat)
{
	Start();
	Send(Write_Address);
    Check_Ack();
    if (Flg==CMD)
        Send(0x00);  
    else
        Send(0x40);  	   
    Check_Ack();
	Send(Dat);
    Check_Ack();
	Stop();	
	Delay(50);    
}

unsigned char Read(void)/*读一个字节的数据,并返回该字节值*/
{
    unsigned char temp=0;
    unsigned char temp1=0;
    unsigned char BitCounter=8;
    SDA=1;
    do{
        SCL=0;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        SCL=1;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        if(SDA)/*如果SDA=1;*/
            temp=temp|0x01;/*temp的最低位置1*/
        else
            temp=temp&0xfe;/*否则temp的最低位清0*/
        if(BitCounter-1)
        {
	        temp1=temp<<1;
            temp=temp1;
        }
        BitCounter--;
    }
    while(BitCounter);
    return(temp);

}

#pragma disable
void Initial(void)
{
    tansfer(CMD,0x38);
	Delay(100);
    tansfer(CMD,0x39);
	Delay(100);
    tansfer(CMD,0x1c);
    tansfer(CMD,0x7f);
    tansfer(CMD,0x5b);
    tansfer(CMD,0x6f);
    tansfer(CMD,0x0c);
    tansfer(CMD,0x06);
	Delay(100);
}

#pragma disable
void Set_CGRAM(void)
{
    unsigned char i;
    tansfer(CMD,0x38);
	Delay(100);
    tansfer(CMD,0x40);  
 	for(i=0;i<0x04;i++)
     	{
        tansfer(DAT,0x00);
        tansfer(DAT,0xff);
        }
 	for(i=0;i<0x04;i++)
     	{
        tansfer(DAT,0xff);
        tansfer(DAT,0x00);
        }
 	for(i=0;i<0x08;i++)
     	{
        tansfer(DAT,0x15);
        }
 	for(i=0;i<0x08;i++)
     	{
        tansfer(DAT,0x0a);
        }
    tansfer(CMD,0x39);
	Delay(100);
}

main()
{ 
    unsigned char i;
    Initial();
	Set_CGRAM();
 while(1)
	{
/*---------------------------------------------*/
    tansfer(CMD,0x40);
	for(i=0;i<0x4f;i++)
	    {
        tansfer(DAT,0xff);
        }
    tansfer(CMD,0xc0);
	for(i=0;i<0x0f;i++)
     	{
        tansfer(DAT,font[i]);
        }
    Delay(60000);
    Delay(60000);


    tansfer(CMD,0x40);
	for(i=0;i<0x4f;i++)
	    {
        tansfer(DAT,0x00);
        }
    tansfer(CMD,0xc0);
	for(i=0;i<0x0f;i++)
     	{
        tansfer(DAT,0x00);
        }
    Delay(60000);
    Delay(60000);

    tansfer(CMD,0x40);
	for(i=0;i<0x4f;i++)
	    {
        tansfer(DAT,0xff);
        }
    tansfer(CMD,0xc0);
	for(i=0;i<0x0f;i++)
     	{
        tansfer(DAT,0x01);
        }
    Delay(60000);
    Delay(60000);

    tansfer(CMD,0x40);
	for(i=0;i<0x4f;i++)
	    {
        tansfer(DAT,0x00);
        }
    tansfer(CMD,0xc0);
	for(i=0;i<0x0f;i++)
     	{
        tansfer(DAT,0x02);
        }
    Delay(60000);
    Delay(60000);

    tansfer(CMD,0x40);
	for(i=0;i<0x4f;i++)
	    {
        tansfer(DAT,0xff);
        }
    tansfer(CMD,0xc0);
	for(i=0;i<0x0f;i++)
     	{
        tansfer(DAT,0x03);
        }
    Delay(60000);
    Delay(60000);
    }
}

⌨️ 快捷键说明

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