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

📄 lcd.bak

📁 此源码是用的NEC公司的MCU78F0396
💻 BAK
📖 第 1 页 / 共 2 页
字号:
/******************************************************
//  Filename :	lcd.c
//  Abstract :	This file implements main function.
//
//  Device    :	uPD78F0396
//  CreateTime: 2006/11/
//  ModifyTime:
//  Author    :  

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


/****************************************************************************
; 78K0/Lx2 LCD control sample program
;****************************************************************************
; LCD controller/driver control -- Processing file--
;****************************************************************************
;[History]
; 2005.06.-- Newly created
; 2005.07.01 [050701] Provisionally added voltage supply to VLC0
; 2006.01.11 Modified to use Applilet-generated IIC routines - rdh
; 2006.01.27 Correction in LcdDrvOff in turning off VLCON - rdh
; 2006.03.30 Use routines for writing only for Application Notes
****************************************************************************/
//#pragma sfr
/*===========================================================================
; INCLUDE
;==========================================================================*/
//#include "macrodriver.h" 
#include "UsrComm.h"
#include"AllSerial.h"
#include "LCD.h"
//extern MD_STATUS IIC0_MasterStartAndSend(unsigned char ucSAdr, unsigned char* pIICTxBuf, unsigned int wIICTxLength);
static void LcdDrvClkOut( void );
static void LcdDrvClkStop( void );
/*===========================================================================
; Definition of control area for LCD driver and various settings
;==========================================================================*/
/*===========
; Slave ID
;==========*/
#define CSLV_ID_LCDCTL 0b01110000 /* Control register (LCDCTL) */
#define CSLV_ID_LCDSEG 0b01110010 /* Segment data (LCDSEG) */
/*===========
; Definition of control register settings on main side
;==========*/
/*-- Clock output select register --*/
#define LDR_CKS CKS
#define LDR_CKS_CLOE LDR_CKS.4 /* Clock output enable/disable */
/*-- Port/port mode register (directly connected in microcontroller) --*/
#define PO_LDR_RST  P13.0 /* Reset to LCD chip */
#define PM_LDR_OUT  PM14.0 /* Clock output to LCD chip */
/*-- Port/port mode register --*/ /*[050701]>>*/
#define PO_VLC0_HL P7.7 /* Voltage supply to VLC0 */
#define PM_VLC0_HL PM7.7 /* Voltage supply to LLC0 [050701] */
								  /*===========
								  Control register setting
==========*/
/* Selects LCD reference voltage generator: internal step-up mode */
#define CLDR_LCDMD_VOL 0b00000010
/********************************************************************
; LCD driver initialization
;--------------------------------------------------------------------
; [I N] -
; [OUT] 0= Setting OK, 1 = NACK received, 2 = Busy
;*******************************************************************/
unsigned char LcdDrvInit( void )
{
	register unsigned char result = CLDR_ERR_NONE;
	PO_LDR_RST = 1; /* Cancels LCD chip's reset status */
	LDR_CKS = ( CLDR_CKS & 0b00001111); /* Output clock setting (CCS3-0) */
	/*-- Enables clock output to LCD chip --*/
	LcdDrvClkOut();
	/*-- Selects reference voltage generator --*/
	result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDMD, CLDR_LCDMD );
	/*-- Clears segment data --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvSegClr();
	}
	/*-- Selects display mode --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b00000111 ));
	}
	/*-- LCD clock setting --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDC, CLDR_LCDC );
	}
	return ( result );
}

/********************************************************************
; LCD driver display ON wait start pre-processing (when step-up mode is selected)
;--------------------------------------------------------------------
; << Note >>
;
; Only N is called when internal step-up mode is selected for the reference
; voltage generator. After this processing is called, a wait period
; of at least 500 ms should occur, then the "LcdDrvOn" should be called.
;
;--------------------------------------------------------------------
; [I N] -
; [OUT] 0= Setting OK, 1 = NACK received, 2 = Busy
;*******************************************************************/
unsigned char LcdDrvOnWait( void )
{
#if (CLDR_LCDMD==CLDR_LCDMD_VOL)
	/* Reference voltage generator: internal step-up mode */
	register unsigned char result = CLDR_ERR_NONE;
	/*-- Enables clock output to LCD chip --*/
	LcdDrvClkOut();
	/*-- Sets LCD step-up level and contrast--*/
	result = LcdDrvCtrWrite1Byte( CLDR_ADDR_VLCG0, CLDR_VLCG0 );
	/*-- Enables LCD step-up --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b00100111 ));
	}
	/* -- After 500 ms, the "LcdDrvOnWait" function must be called -- */
	return ( result );
#else/*!(CLDR_LCDMD==CLDR_LCDMD_VOL)*/
	/* Reference voltage generator: resistor division mode */
	return ( 0 );
#endif/*(CLDR_LCDMD)*/
}
/********************************************************************
; LCD driver ON processing
;--------------------------------------------------------------------
; << Note >>
;
; When internal step-up mode has been selected for the reference voltage
; generator, after the "LcdDrvOnWait" has been called, a wait period of
; at least 500 ms must occur before calling the next function.
;
;--------------------------------------------------------------------
; [I N] -
; [OUT] 0= Setting OK, 1 = NACK received, 2 = Busy
;*******************************************************************/
unsigned char LcdDrvOn( void )
{
	register unsigned char result = CLDR_ERR_NONE;
#if (CLDR_LCDMD==CLDR_LCDMD_VOL)
	/* Reference voltage generator: internal step-up mode */
	/*-- Setting of deselect potential output --*/
	result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b01100111 ));
	/*-- Display ON setting --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b11100111 ));
	}
	
#else/*!(CLDR_LCDMD==CLDR_LCDMD_VOL)*/
	/* Reference voltage generator: resistor division mode */
	/*-- Enables clock output to LCD chip --*/
	LcdDrvClkOut();
	/*-- Setting of deselect potential output --*/
	result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b01000111 ));
	/*-- Display ON setting --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b11000111 ));
	}
#endif/*(CLDR_LCDMD)*/
	return ( result );
}
/********************************************************************
; LCD driver display OFF processing
;--------------------------------------------------------------------
; [I N] -
; [OUT] 0= Setting OK, 1 = NACK received, 2 = Busy
;
; *Clears AX register
;*******************************************************************/
unsigned char LcdDrvOff( void )
{
	register unsigned char result = CLDR_ERR_NONE;
	/*-- Clears segment data --*/
	result = LcdDrvSegClr();
	/*-- Display OFF setting --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b01100111 ));
	}
	/*-- Segment/common buffer output disable setting --*/
	if( result == CLDR_ERR_NONE ){
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b00100111 ));
	}
#if (CLDR_LCDMD==CLDR_LCDMD_VOL)
	/*-- LCD step-up disable setting --*/
	if( result == CLDR_ERR_NONE ){
#if 0 /* correction 060127 - bit 5 is 1, does not turn off VLCON */
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b00100111 ));
#else /* correction turns off VLCON by having bit 5 as zero */
		result = LcdDrvCtrWrite1Byte( CLDR_ADDR_LCDM, ( CLDR_LCDM & 0b00000111 ));
#endif
	}
#endif/*(CLDR_LCDMD)*/
	if( result == CLDR_ERR_NONE ){
		/*-- Disables clock output to LCD chip --*/
		LcdDrvClkStop();
	}
	return ( result );
}


/********************************************************************
; Writes LCD driver control data
;--------------------------------------------------------------------
; [I N] src : Control register data's storage address
; addr : Control register address value
; size : Number of bytes to be transmitted (4 bytes maximum)
; [OUT] 0= Setting OK, 1 = NACK received, 2 = Busy, 3 = Parameter error
;*******************************************************************/
unsigned char SLDRCTLW( unsigned char *src,
					   unsigned char addr, unsigned char size )
{
	register unsigned char result = CLDR_ERR_NONE;
/*	register unsigned char cnt;
	unsigned short status;
	unsigned char buf[5];
	unsigned char uc;
	//-- Enables clock output to LCD chip 

⌨️ 快捷键说明

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