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

📄 lcd.c

📁 LPC2132点亮NH12864的源码
💻 C
字号:
/**--------------File Info-------------------------------------------------------------------------------
** File name:			lcd.c
** Last modified Date:  2006-10-14
** Last Version:		1.0
** Descriptions:		lcd function 
**
**------------------------------------------------------------------------------------------------------
** Created by:			hujing
** Created date:		2006-10-14
** Version:				1.0
** Descriptions:		The original version
**
**----------------------------------------------------------------------------------------------------*/

#include "config.h"

#define X_ADRESS		(uint8)0xB8	/* Adress base for Page 0 */
#define Y_ADRESS		(uint8)0x0040	/* Adress base for Y0	  */
#define START_LINE		0xC0	/* Adress base for line 0 */
#define DISPLAY_ON		0x3F	/* Turn display on	  */
#define DISPLAY_OFF		0x3E	/* Turn display off	  */

#define Left                    1
#define Right                   2


/*空指令*/
uint8 Column=0, Page=0;
void Delay(uint8 ms)
{							// 延时子程序
	uint8 i;
	uint8 m;
	while(ms--)
	{
		for(i = 0; i< 250; i++)
		{
		  m=0;
		  m=1;
		}
	}
}
/*
uint32 bf(void)
{    
	uint32 a;
     	IO0DIR=0X20018000;	//设置P0.29,P0.16,P0.15为输出;P0.4-P0.11(D0-D7)为输入
     
    
     	IO1CLR=0x00030000;	//245(2)数据读入ARM
      
     	IO0CLR=1<<16; //RS(D/I)=0
     	IO0SET=1<<15; //R/W=1
     	IO0SET=1<<29; //E=1
     	Delay(1);   
     	a=IO0PIN&0X00000FF0;
     	IO0CLR=1<<29; //E=0
     	return(a);
    
}
*/
           
   /*写指令*/
void LcdInstruction(uint8 x)  
{
	uint32 y=x;//把8位的x转换成32位y,y的低8位为x里的内容。
    	y=y&0x000000FF;//将Y的高24位清零
    	
    	IO0SET=1<<16;	//CS1=1
   	IO0SET=1<<17;	//CS2=1
    	
    	IO0CLR=1<<18; 	//DI=0
     	IO0CLR=1<<19; 	//RW=0
     	
     	Delay(1);
     	IO1PIN=(IO1PIN&0XFC03FFFF)|(y<<18);
     	Delay(1);
     	
     	IO0SET=1<<20; //E=1    
     	Delay(1);     
     	IO0CLR=1<<20; //E=0
     	
     	IO0CLR=1<<16; 	//CS=0
     	IO0CLR=1<<17; 	//CS=0    	    	    		
}
//写数据
void LcdDataWrite (uint8 u8Data,uint8 Direction)
{
	uint32 y=u8Data;//把8位的x转换成32位y,y的低8位为x里的内容。
    	y=y&0x000000FF;//将Y的高24位清零
       
        if(Direction==Left)
        {                    
        	IO0SET=1<<16;	//CS1=1
        }
        else
        {
        	IO0SET=1<<17;	//CS2=1 
        }
        //if(Direction==Right)           IO0SET=1<<17;	//CS2=1 
        
        
       	IO0SET=1<<18;				/* Instruction mode */
       	IO0CLR=1<<19;				/* write mode */
        
        
       	Delay(1);
     	IO1PIN=(IO1PIN&0XFC03FFFF)|(y<<18);
     	Delay(1);
     	
     	IO0SET=1<<20; //E=1    
     	Delay(1);     
     	IO0CLR=1<<20; //E=0
     	
     	IO0CLR=1<<16; 	//CS=0
     	IO0CLR=1<<17; 	//CS=0 
}	
     
/*清屏*/   
void GLCD_ClearScreen(void)
{   	
   	uint8 i,j;
        for(i=0;i<8;i++)
        {
                LcdInstruction(X_ADRESS | i); /* Set the page number */
      		LcdInstruction(Y_ADRESS);
                for(j=0;j<128;j++)
                {
                        if(j<=63)       LcdDataWrite (0x00,Left);
                        else            LcdDataWrite (0x00,Right);                       
                }
        }     
}       
/*初始化*/     
void GLCD_LcdInit(void) 
   {
   	IO0SET=1<<16;	//CS1=1
   	IO0SET=1<<17;	//CS2=1
   	
        IO0SET=1<<18;	//DI=1
        IO0SET=1<<19;	//RW=1
        IO0SET=1<<20;	//E=1
        
        
        LcdInstruction(0xC0);
        LcdInstruction(0x3F);
        
       	GLCD_ClearScreen ();
           
   }

/*定写入位置*/
//显示坐标定位
void GLCD_Locate (uint8 u8Column, uint8 u8Line)
{
	Page = u8Line;
	Column = u8Column;
}
/*数据显示*/
//写单字节
void GLCD_Write_Byte (uint8  u8Byte)
{
       LcdInstruction(X_ADRESS | Page);

        if(Column<64)
        {
                LcdInstruction(Y_ADRESS | Column);
                LcdDataWrite (u8Byte,Left);
        }
        else if(Column<128)
        {
                LcdInstruction(Y_ADRESS | (Column-64));
                LcdDataWrite (u8Byte,Right);
        }      
}
/**********END OF FILE**********************/     
     
     
     
     
     

⌨️ 快捷键说明

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