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

📄 12864.c

📁 这是一个我以前用AT89S52单片机做的128-64液晶屏的驱动显示程序
💻 C
字号:
#include<reg52.h>
#include"12864-pin.h"
#include<intrins.h>


/*////////////////////////////////////////////////////////////////////////////*/

void delay(uint ms)
{
	uint i;						
	while(ms--)
	{
		for(i=0;i<100;i++);																		  
	}
}										 	

/*////////////////////////////////////////////////////////////////////////*/
/* 等待,直到12864液晶模块处于就绪状态 */

void chk_busy(void)
{
   /* BF = 1;
    DI = 0;
    RW = 1;
    E  = 1;	//	delay(1);
//	while(BF);  
	E  = 0;	
*/

uchar i;
for(i=0;i<10;i++);			


}

																			   	



/*////////////////////////////////////////////////////////////////////////*/
/* 向12864液晶模块传输指令 */

void send_i(uchar instrution)
{																		
   	chk_busy();	
    DI = 0;
    RW = 0;
    DB = instrution; 
    E = 1;
#ifdef NOP
     _nop_(); // delay(1);  
     _nop_(); 
#endif
    E = 0;
}

/*////////////////////////////////////////////////////////////////////////*/
/* 向12864液晶模块传输数据 */

void send_d(uchar dt)								
{
    chk_busy();
    DI = 1;
    RW = 0;
    DB = dt;
    E = 1;
#ifdef NOP
     _nop_();  // delay(1);
     _nop_(); 
#endif
    E = 0;
}

 /*/////////////////////////////////////////////////////////////////////////*/
 /* 初始化12864液晶模块 */
									  			 
void init_LCD(void)
{
    RST = 0;
    delay(200);
    RST = 1;
#ifdef NOP
    _nop_();
#endif
   	E = 0;
	CS1 = 1;
	send_i(0x34);		//扩充指令;
    send_i(0x30);	//  8位数据,基本指令;
													
	send_i(0x01);  //清除显示,DDRAM 填满20H	  ;  
	delay(20);
	send_i(0x06);	 //	 游标进入点设定;
//	send_i(0x14);  //	游标或显示移位控制
	send_i(0x0e);	//  显示开关,。

}				
/*////////////////////////////////////////////////////////////////////////*/
/* 设置文本输出位置;x取值范围:0~7;y取值范围:0~3 */

void gotoxy(uchar x, uchar y)
{																						
    switch(y)
    {
        case 0: 
		send_i(0x80+x);
	break;
        case 1:
		 send_i(0x90+x);break;
        case 2: send_i(0x88+x);break;
        case 3: send_i(0x98+x);break;
    }
}




/*////////////////////////////////////////////////////////////////////////*/
/* 连续向LCD发送string指向的num个数据 */
void LCD_puts(Ucode* string, uchar num)											
{
    while(num--)
    {
        send_d(*string++);
    }
}



/*////////////////////////////////////////////////////////////////////////*/
/* 汉字显示清屏 */

void clrddram()
{
    send_i(0X01);delay(6);	    //清除显示,DDRAM 填满20H  ;
	send_i(0x34);				 //扩充指令;
    send_i(0X30);		//  8位数据,基本指令;	
}
 /*////////////////////////////////////////////////////////////////////////*/
/* 设置图形模式输出位置;x取值范围(byte):0~7,单位为16位/2个字节,共128位;
   y取值范围(bit):0~63		 */
void setxy(uchar x, uchar y)
{
	send_i(0x34);				 //扩充指令;
    if(y&0xe0)		// y>=32
    {
		send_i(0x80+y-32);
       		send_i(0x88+x);
    }
    else				   // y<32
    {
		send_i(0x80+y);		//  	设定DDRAM 地址,第一行80H~87H,第二行90H~97H 
    	send_i(0x80+x);
	}
	 send_i(0x30);			 //基本指令;

}

/*////////////////////////////////////////////////////////////////////////*/
/* 显示点阵子程序,以lcd_data填充图形显示空间(GDRAM) */
void fill_GD(uchar x,uchar y,uchar l,uchar w,uchar Data)
{
	uchar i;
	while(w--)
    {   
		send_i(0x34);	// setxy()需要工作在扩充指令模式下
        setxy(x, y++);	// 设置输出到图形缓冲区的地址
        send_i(0x30);	// send_d()需要工作在基本指令模式下
        for( i=l;i--;)
        {
            send_d(Data);	
            send_d(Data);
        }
    }
   	send_i(0x36);			 //  扩充指令,图形显示开 
    send_i(0x30);			// 返回基本指令模式
}

/*////////////////////////////////////////////////////////////////////////*/
/* x代表要输出的目标行地址,其取值范围是0~ 7,单位是2个字节,即16位 */
/* y代表要输出的目标列地址,其取值范围是0~63,单位是1位 */
/* l代表图形文件的长度,单位是2个字节,即16位 */
/* w代表图形文件的宽度,单位是1位 */
void putsBMP(uchar x, uchar y, uchar l, uchar w,uchar code *p)		//反白;
{
    uchar i;

	while(w--)
    {   
		send_i(0x34);	// setxy()需要工作在扩充指令模式下
        setxy(x, y++);	// 设置输出到图形缓冲区的地址
        send_i(0x30);	// send_d()需要工作在基本指令模式下
        for( i=l;i--;)
        {
            send_d(*p++);	
            send_d(*p++);
        }
    }
    send_i(0x36);		// 绘图开;
    send_i(0x30);			// 返回基本指令模式
}
/*////////////////////////////////////////////////////////////////////////*/
/* 清空点阵区		*/
void clrgdram()
{
    fill_GD(0,0,8,64,0);
}

⌨️ 快捷键说明

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