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

📄 lcddrive.c

📁 Keil平台
💻 C
字号:
/*****************************************************************************/
/*           Used only for MCU_board ZMC001-1 apply to JK                    *
/*****************************************************************************/
#include "config.h"
//
//#include <reg167.h>
//#include <stdlib.h>
//#include <stdio.h>
//#include <math.h>
//#include "hard.h"
//#include "includes.h"
#define     INITEEP		0x220A					 //定义P2.10为EEprom 初始化设置,输入,低有效
#define     LCDBG       0x121E                   //P1.30 液晶背光启动信号,输出,低有效
#define     LCDEN       0x3219            		 //P3.25为液晶使能,输出,低有效 
#define     LCDCD       0x121F            		 //P1.31 液晶控制器指令/数据选择信号
#define     LCDWR       0x321A                   //P3.26 液晶控制器复位信号,输出,低有效
#define     LCDS8       (0xFF << 23)	         //P0[30:23]
/*****************************************************************************/
/*    This function use for LCD delay time.                                  */
/*****************************************************************************/
void Delayus(uint16 time)
{
    uint16 i;
    for(i=0;i<time;i++)
    {
        __asm
        {
            nop;
        }
    }
}
/*
*************************************************************************************************************
** 函数名称: LcdOutCode
** 功能描述: This function use for LCD out code
** 输 入: parameter
** 输 出: 无
** 全局变量: 无
** 调用模块: 
**
** 作 者: Tianqi
** 日 期: 2006-12-20
**-----------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-----------------------------------------------------------------------------------------------------------
*************************************************************************************************************
*/
void LcdOutCode(uint8 parameter)
{
    ///FIO1DIR  = LCDS8;			// 设置LED1控制口为输出
    SetIO(LCDCD);Delayus(5);//ClrIO(LCDCD);//IO0CLR  =LCDCD;
    ClrIO(LCDWR);Delayus(5);//SetIO(LCDWR);//IO0SET  =LCDWR;//IO0CLR  =LCDWR;
    ClrIO(LCDEN);Delayus(5);//SetIO(LCDEN);//IO0SET  =LCDEN;//IO0CLR  =LCDEN;
    //FIO0PIN  =(FIO0PIN&(~(0xff<<23)))|(parameter<<23);
	FIO0MASKU&=	0x807F;//((FIO0PINU&0x807F)|(0X00<<7));
	FIO0PINU =	(FIO0PINU&(~(0xFF<<7))|(parameter<<7));
	FIO0MASKU|=	(~0x807F);
    Delayus(5);//
    SetIO(LCDEN);Delayus(5);//ClrIO(LCDEN);//IO0CLR  =LCDEN;//IO0SET  =LCDEN;
    SetIO(LCDWR);Delayus(5);//ClrIO(LCDWR);//IO0CLR  =LCDWR;//IO0SET  =LCDWR;
    //FIO0PIN  =(IO0PIN&(~(0xff<<23)))|(0xFF<<23);Delayus(5);//使用后将数据口线置高
	FIO0PINU =	(FIO0PINU&(0x807F)|(0xFF<<7)); 
}

/*
*************************************************************************************************************
** 函数名称: LcdOutData
** 功能描述: This function use for LCD out data.
** 输 入: parameter
** 输 出: 无
** 全局变量: 无
** 调用模块: 
**
** 作 者: Tianqi
** 日 期: 2006-12-20
**-----------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-----------------------------------------------------------------------------------------------------------
*************************************************************************************************************
*/
void LcdOutData(uint8 parameter)
{
    ///FIO1DIR  = LCDS8;			// 设置LED1控制口为输出
    ClrIO(LCDCD);Delayus(5);//SetIO(LCDCD);//IO0SET  =LCDCD;//IO0CLR  =LCDCD;
    ClrIO(LCDWR);Delayus(5);//SetIO(LCDWR);//IO0SET  =LCDWR;//IO0CLR  =LCDWR;
    ClrIO(LCDEN);Delayus(5);//SetIO(LCDEN);//IO0SET  =LCDEN;//IO0CLR  =LCDEN;
    //FIO0PIN  =(FIO0PIN&(~(0xff<<23)))|(parameter<<23);
	FIO0MASKU&=	0x807F;
	FIO0PINU =	(FIO0PINU&(~(0xFF<<7))|(parameter<<7));
	FIO0MASKU|=	(~0x807F);
    Delayus(5);
    SetIO(LCDEN);Delayus(5);//ClrIO(LCDEN);//IO0CLR  =LCDEN;//IO0SET  =LCDEN;
    SetIO(LCDWR);Delayus(5);//ClrIO(LCDWR);//IO0CLR  =LCDWR;//IO0SET  =LCDWR;
    //FIO0PIN  =(IO0PIN&(~(0xff<<23)))|(0xFF<<23);Delayus(5);//使用后将数据口线置高
	FIO0PINU =	(FIO0PINU&(0x807F)|(0xFF<<7));	
}

/*****************************************************************************/
/*    This function use for LCD Initiate.                                    */
/*****************************************************************************/
void LCD_Initiate( void )
{
//    LCD_EL  = 1;                            // LCD Back Light.
//    LCD_RST = 0;
    //delay( 50 );                            // 8000ns.
//    LCD_RST = 1;
    FIO0DIR  |= LCDS8;							 // 设置管脚P0[30:23]为输出模式
    SetIO_Func(LCDBG  ,0,1);                     //P1.30 液晶背光启动信号,输出,低有效
    SetIO_Func(LCDEN  ,0,1);                     //P3.25为液晶使能,输出,低有效 
    SetIO_Func(LCDCD  ,0,1);                     //P1.31 液晶控制器指令/数据选择信号
    SetIO_Func(LCDWR  ,0,1);                     //P3.26 液晶控制器复位信号,输出,低有效


    LCD_Write_Code( 0x40,0x20,0x00 );       // Text  Area First Address.
    LCD_Write_Code( 0x41,0x1e,0x00 );       // Text  Area Width.
    LCD_Write_Code( 0x42,0x00,0x08 );       // graph Area First Address.
    LCD_Write_Code( 0x43,0x1e,0x00 );       // graph Area Width.
    LCD_Write_Code( 0x81,0xff,0xff );       // CGRAM OR.
    LCD_Write_Code( 0x9f,0xff,0xff );       // Open  graph.
    LCD_Write_Code( 0x24,0x00,0x08 );       // Operate graph Address in DRAM.
    LCD_Write_Code( 0xA2,0xff,0xff );       // cursor state.
    LCD_Clear_All();
}

/*****************************************************************************/
/*    This function use for LCD Write Code.                                  */
/*    Par1.Par2=0xff is no Parameter Instruction.                            */
/*****************************************************************************/
void LCD_Write_Code( unsigned char Code,unsigned char Par1,unsigned char Par2 )
{
    unsigned char i;
    if( Par1 != 0xff )
    {
       LcdOutData(Par1);          //Par1.
    }
    if( Par2 != 0xff )
    {
       LcdOutData(Par2);          //Par2.
    }
    LcdOutCode(Code);            //Code.
}

void LCD_Write_Line( unsigned char Code,unsigned char Par1,unsigned char Par2 )
{
//    unsigned char i;
     LcdOutData(Par1);            //Par1.
     LcdOutData(Par2);            //Par2.
     LcdOutCode(Code);            //Code.
}

/*****************************************************************************/
/*    This function use for LCD Write Data.                                  */
/*    The  Parateter is Write Byte.                                          */
/*****************************************************************************/
void LCD_Write_Data( unsigned char Data )
{
    // Delayus(1);
    LcdOutData(Data) ;       //Data.
    //Delayus(1);
    LcdOutCode(0xc0) ;            //Code.
}

/*****************************************************************************/
/*    This function use for detect LCD State.                                */
/*    No  Parateter                                                          */
/*****************************************************************************/
void LCD_Read_State( void )
{
    unsigned char LCD_StateBYTE;
}

/*****************************************************************************/
/*    This function use for display LCD 8Bit.                                */
/*    Parateter x,y,*HZ,BackFlag.                                            */
/*****************************************************************************/
void LCD_Draw_Byte( unsigned int x,unsigned int y,unsigned char  HZ,unsigned char BackFlag )
{
    unsigned int  iTemp;
    unsigned char AddressL,AddressH;

    LCD_Write_Code( 0x24,0x00,0x08 );       //graph Area First Address.
    iTemp = x/8+y*30;
    AddressL = iTemp&0x00ff;
    AddressH = (iTemp&0xff00)>>8;
    LCD_Write_Line( 0x24,AddressL,AddressH+0x08);
    if(BackFlag == 1)
    {
        LCD_Write_Data( ~HZ );
    }
    else
    {
        LCD_Write_Data( HZ );
    }

    LCD_Write_Code( 0x24,0x00,0x08 );       //graph Area First Address.

}
/*****************************************************************************/
/*    This function use for display LCD Cursor.                              */
/*    Parateter x,y,*HZ,BackFlag.                                            */
/*****************************************************************************/
void LCD_Draw_Cursor( unsigned int x,unsigned int y)
{
    LCD_Write_Line( 0x21,x,y);
}

/*****************************************************************************/
/*    This function use for Draw a Dot to LCd.                               */
/*    X Coordinate Range 0-239,Y Coordinate Range 0-63.                      */
/*****************************************************************************/
void LCD_Draw_Dot( unsigned char CoordX,unsigned char CoordY,unsigned char Mode )
{
    unsigned int iTemp;
    unsigned char AddressL,AddressH,WriteBit;

    iTemp = (int)CoordX/8+30*(int)CoordY;
    AddressL =  iTemp&0x00ff;
    AddressH = (iTemp&0xff00)>>8;
    WriteBit = 7-CoordX%8;                           //Covert 0-7 to 7-0.

    if( Mode == 1 )
    {
        LCD_Write_Code( 0x24,AddressL,AddressH+0x08 );   //graph Area First Address.
        LCD_Write_Code( 0xf8|WriteBit,0xff,0xff );       //graph Area Bit Operate.
    }
    else
    {
        LCD_Write_Code( 0x24,AddressL,AddressH+0x08 );   //graph Area First Address.
        LCD_Write_Code( 0xf0|WriteBit,0xff,0xff );       //graph Area Bit Operate.
    }

}

/*****************************************************************************/
/*    This function use for Clear LCD Dram                                   */
/*****************************************************************************/
void LCD_Clear_All( void )
{
    unsigned int i;

    LCD_Write_Code( 0x24,0x20,0x00 );
    for(i=0;i<240;i++)
    {
       LCD_Write_Data( 0x00 );
    }
    LCD_Write_Code( 0x24,0x00,0x08 );
    for(i=0;i<1920;i++)
    {
       LCD_Write_Data( 0x00 );
    }
    LCD_Write_Code( 0x24,0x00,0x08 );

}

⌨️ 快捷键说明

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