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

📄 zlg_avalon_lcd128_64.c

📁 周立功 SOPC嵌入式系统实验教材 LCD12864驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzhou ZHIYUAN ELECTRONIC CO.,LTD.
**                                      Research centre
**                          http://www.zyinside.com, http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			  zlg_avalon_lcd128_64.c
** Latest modified Date:  2006-2-8
** Latest Version:		  2.0
** Descriptions:		  All hardware ralative defines
**                       
**                        
**
**------------------------------------------------------------------------------------------------------
** Created by:			  Zhang Gaosong
** Created date:		  23 Dec, 2004
** Version:				    1.0
** Descriptions:		  The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:           Zhou Shuwu
** Modified date:         2006-2-8
** Version:               2.0
** Descriptions:          Modified for NiosII
**
********************************************************************************************************
**------------------------------------------------------------------------------------------------------
** Modified by:           Jing.Zhang
** Modified date:         2006-2-19
** Version:               2.0
** Descriptions:          Modified for API
**
********************************************************************************************************/

/****************************************************************************
* 功能:ST7920中文液晶显示并行方式驱动程序。
* 说明:NiosII,晶振48MHz调试。
****************************************************************************/
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "zlg_avalon_lcd128_64.h"

#include  "priv/alt_busy_sleep.h"

#define 	SET_LCD_LIGHT(data)	IOWR_ALTERA_AVALON_PIO_DATA(LCD_LIGHT_BASE, data)
//#define 	SET_LCD_nRST(data)	IOWR_ALTERA_AVALON_PIO_DATA(LCD_nRST_BASE, data)

//=============================================================================
// Lowest lever LCD operation functions
//=============================================================================
//static void  DelayNuS(alt_u32 us);
//static void DelayNmS(alt_u32 ms);
static void ST7920_Reset(void);
static int ST7920_CheckBusy(void);
static int ST7920_SendCMD(alt_u8 cmd);

static int ST7920_ReadDATA(alt_u8 from,alt_u8 cmd, alt_u8* pdata, alt_u8 len);
static alt_u8 DDRAMaddr[4][8] = {
	{0,1,2,3,4,5,6,7},
	{16,17,18,19,20,21,22,23},
	{8,9,10,11,12,13,14,15},
	{24,25,26,27,28,29,30,31}
};
/****************************************************************************
* 名称:DelayNuS
* 功能:N uS软件延时
* 入口参数:us		延时参数N
* 说明:用户根据自已的系统的时钟频率相应更改,48M频率NiosII/e时约5uS
****************************************************************************/
/*
static void  DelayNuS(alt_u32 us)
{ 
	  while(us--);
}
*/
/****************************************************************************
* 名称:DelayNmS
* 功能:N mS软件延时
* 入口参数:ms		延时参数N
* 说明:用户根据自已的系统的时钟频率相应更改,48M频率NiosII/e时约1mS
****************************************************************************/
/*
static void DelayNmS(alt_u32 ms)
{ 
    alt_u32 i;
    for(; ms>0; ms--)
    {
       for(i=220; i>0; i--);
    }
}
*/

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/****************************************************************************
*名称:  ST7920_Reset
*功能:  ST7920芯片上电复位
*说明:  用户根据自己的系统调用
****************************************************************************/
/*
static void ST7920_Reset(void)
{
	SET_LCD_nRST(0);
	//DelayNmS(100);
	alt_busy_sleep(100000);//Delay 100ms
	SET_LCD_nRST(1);
	//DelayNmS(20);
    alt_busy_sleep(20000);//Delay 20ms
}
*/
/****************************************************************************
*名称:  ST7920_BacklightCon
*功能:  ST7920液晶背光驱动控制
*入口参数:  status  (LEDON、LEDOFF)
*说明:  用户根据自己的系统调用
****************************************************************************/
void LCD_BacklightCon(alt_u8 status)
{
     SET_LCD_LIGHT(status);
}

/****************************************************************************
*名称:  ST7920_CheckBusy
*功能:  等待ST7920芯片处于空闲状态
*说明:  0,成功; <0 忙等待超时  .
****************************************************************************/
static int ST7920_CheckBusy(void)
{
	  int i;
	  alt_u8 busy;

	  for(i=0; i<10000; i++)
	  {
	  	//busy = *LCD_READ_STATUS;
	  	busy = LCD_READ_STATUS();
	  	if((busy&LCD_BUSY_FLAG)!=LCD_BUSY_FLAG)
	  		return LCD_ERR_OK;
	  	//DelayNuS(5);
	    //alt_busy_sleep(25);//Delay 25us
	  }
	  return LCD_ERR_TIMEOUT;
}
/****************************************************************************
*名称:  ST7920_SendCMD
*功能:  ST7920命令发送子程序
*入口参数:  cmd Instuction code(指令代码)
*说明:  发送ST7920芯片控制指令,两次数据或命令传输必须间隔40us以上
*       0,成功;<0 忙等待超时。
****************************************************************************/
static int ST7920_SendCMD(alt_u8 cmd)
{
	int ret_code;
    ret_code = ST7920_CheckBusy();
    if(ret_code == LCD_ERR_TIMEOUT)
    	return ret_code;
    //*LCD_WRITE_COMMAND = cmd;
    LCD_WRITE_COMMAND(cmd);
    return LCD_ERR_OK;
}

/****************************************************************************
*名称:  ST7920_SendDATA
*功能:  ST7920显示数据发送子程序
*入口参数:  data (数据信息)
*说明:  发送ST7920芯片数据
*       0,成功;<0 忙等待超时。
****************************************************************************/
int ST7920_SendDATA(alt_u8 data)
{
    int ret_code;
    ret_code = ST7920_CheckBusy();
    if(ret_code == LCD_ERR_TIMEOUT)
    	return ret_code;
    //*LCD_WRITE_DATA = data;
    LCD_WRITE_DATA(data);
    return LCD_ERR_OK;
}

/****************************************************************************
*名称:  ST7920_ReadDATA
*功能:  ST7920读取显示RAM程序
*入口参数: from,  the start address of AC;
	         cmd,   read command
	         pdata, the point to data buffer;
	         len  , the count of required data;
*出口参数:  
*说明:  发送ST7920芯片数据
*       0,成功;<0 忙等待超时。
****************************************************************************/
static int ST7920_ReadDATA(alt_u8 from,alt_u8 cmd, alt_u8* pdata, alt_u8 len)
{
    int ret_code;
    
    ST7920_SendCMD(cmd|from);
    ret_code = ST7920_CheckBusy();
    if(ret_code == LCD_ERR_TIMEOUT)
       return ret_code;
    //from = *LCD_READ_DATA;  //dummy read 
    from = LCD_READ_DATA();  //dummy read   
    for(; len>0; len--)
    {
      ret_code = ST7920_CheckBusy();
      if(ret_code == LCD_ERR_TIMEOUT)
    	   return ret_code;
      //*pdata++ = *LCD_READ_DATA;
      *pdata++ = LCD_READ_DATA();
    }
       return LCD_ERR_OK;
}

//###########################################################################
/****************************************************************************
*名称:  ST7920_ClearScreen
*功能:  Clear Screen to nothing
*说明:  Base instruction,清屏后必须延时2ms以上(根据液晶屏的参数来定)
****************************************************************************/
int ST7920_ClearScreen(void)
{
	return ST7920_SendCMD (LCD_CMD_CLEAR);
	//DelayNmS(15);	
	alt_busy_sleep(10000);//Delay 10ms
}

/****************************************************************************
*名称:  ST7920_CursorGoHome
*功能:  Cursor go home,DDRAM's address counter 'AC=0x00'.
*说明:  Base instruction
****************************************************************************/
int ST7920_CursorGoHome(void)
{
	return ST7920_SendCMD (LCD_CMD_RST_AC);
}

/****************************************************************************
*名称:  ST7920_CursorMove
*功能:  Cursor movement and whole picture movement
*入口参数:  MoveMode(0x04,0x05,0x06,0x07)
*说明:  Base instruction
****************************************************************************/
int ST7920_CursorMove(alt_u8 mode)
{
    
	return ST7920_SendCMD (mode|LCD_CMD_CURSOR_MOV);
}

/****************************************************************************
*名称:  ST7920_DisplayOn
*功能:  Display On Screen
*说明:  Base instruction
****************************************************************************/
int ST7920_DisplayOn(void)
{
	return ST7920_SendCMD(LCD_CMD_DISP_ON);      //D=1: 整体显示ON,C=0:游标OFF,B=0:反白OFF。
}

/****************************************************************************
*名称:  ST7920_DisplayOff
*功能:  Display OFF
*说明:  Base instruction
****************************************************************************/
int ST7920_DisplayOff(void)
{
	return ST7920_SendCMD(LCD_CMD_DISP_OFF);      //D=0: 整体显示OFF,C=0:游标OFF,B=0:反白OFF。
}

/****************************************************************************
*名称:  ST7920_CursorOn
*功能:  Display On Screen
*说明:  Base instruction
****************************************************************************/
int ST7920_CursorOn(void)
{
	return ST7920_SendCMD (LCD_CMD_CURSOR_ON);      //D=1: 整体显示ON,C=1:游标ON,B=1:反白ON。
}

/****************************************************************************
*名称:  ST7920_CursorOff
*功能:  Display OFF
*说明:  Base instruction
****************************************************************************/
int ST7920_CursorOff(void)
{
	return ST7920_SendCMD(LCD_CMD_CURSOR_OFF);      //D=1: 整体显示ON,C=0:游标OFF,B=0:反白OFF。
}

/****************************************************************************
*名称:  ST7920_CursorMoveRight
*功能:  Cursor move to right
*说明:  Base instruction
****************************************************************************/
int ST7920_CursorMoveRight(void)
{
	return ST7920_SendCMD (0x14);          //AC=AC+1
}

/****************************************************************************
*名称:  ST7920_CursorMoveLeft
*功能:  Cursor move to left
*说明:  Base instruction
****************************************************************************/
int ST7920_CursorMoveLeft(void)
{
	return ST7920_SendCMD (0x10);          //AC=AC-1
}

/****************************************************************************
*名称:  ST7920_ScreenMoveRight
*功能:  Screen move to right
*说明:  Base instruction
****************************************************************************/
int ST7920_ScreenMoveRight(void)
{
	return ST7920_SendCMD (0x1C);          //AC=AC >>
}

/****************************************************************************
*名称:  ST7920_ScreenMoveLeft
*功能:  Screen move to left
*说明:  Base instruction
****************************************************************************/
int ST7920_ScreenMoveLeft(void)
{
	return ST7920_SendCMD (0x18);          //AC=AC <<
}

/****************************************************************************
*名称:  ST7920_ExpandFunctionDisable
*功能:  Expand Function Disable
*说明:  Base instruction
****************************************************************************/
int ST7920_ExpandFunctionDisable(void)
{
	return ST7920_SendCMD (LCD_CMD_8BIT);      //Base instruction
}

/****************************************************************************
*名称:  ST7920_ExpandFunctionEnable
*功能:  Expand Function Enable
*说明:  Base instruction
****************************************************************************/
int ST7920_ExpandFunctionEnable(void)
{
	return ST7920_SendCMD (0x34);      //Expand instruction
}

⌨️ 快捷键说明

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