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

📄 lcd.c

📁 S3C4510的LCD測試程式(含源碼,可以順利修改自己的功能)
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/*      lcd.c                      KS32C5000, KS32C50100   : version 1.0 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      LCD Test Program for SNDS100 Board                               */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      hbahn           09-15-1998      Created initial version 1.0      */
/*      in4maker        12-18-1998      Some function added & updated.   */
/*************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "snds.h"
#include "lcd.h"
#include "system.h"


/*
 * Function : LCDTest
 * Description : LCD Test
 */
void LCDTest(void) 
{
	char lcd_str[40];
	int i = 1;
	
	while(i++)
	{
		sprintf( lcd_str, "number=0x%x", i );
        	printf( "%s \r\n", lcd_str );
        	l2Print( lcd_str, "-> www.lumit.org");
        }
        
}

void LTestPutString(char *ptr) 
{
    while(*ptr )
	{
        lPut_byte(*ptr++ );
	WaitLcd(5000);
	}
}


/*
 * Function : LCDInit
 * Description : Initialize LCD 
 */
void LCDInit(void) 
{
	// Initialize EXTDBWTH : 8Byte Operation
	// Initialize EXTACON0 
#if 0	
	EXTDBWTH &= 0xFFCFFFFF ;
	EXTDBWTH |= DSX0 ; 
	EXTACON0 = LTCOS0 | LTACS0 | LTCOH0 | LTACC0 ; 
#endif
printf( "lcd init 1 \r\n" );

	EXTDBWTH &= 0xff3fffff ;
	EXTDBWTH |= DSX1 ; 
	EXTACON0 = LTCOS1 | LTACS1 | LTCOH1 | LTACC1 ; 
printf( "lcd init 2 \r\n" );
	// Initialize
	WaitLcd(200) ;
printf( "lcd init 3 \r\n" );
	/* ---
	 * Function Set
	 *     Interface Data Length is : 8 bit
	 *     Display Numer of Line is 2
	 * --- */
LInstRegWrite((U8)0x30) ; WaitLcd(200) ; 
LInstRegWrite((U8)0x30) ; WaitLcd(200) ; 
LInstRegWrite((U8)0x30) ; WaitLcd(200) ; 

	LInstRegWrite((U8)0x38) ; WaitLcd(100) ; 
	
LInstRegWrite((U8)0x06) ; WaitLcd(200) ; 
LInstRegWrite((U8)0x0f) ; WaitLcd(200) ; 	

return;
	/* ---
	 * Display On/Off Control
	 *     Display On
	 *     Cursor Display
	 *     Cursor Blink
	 * --- */
	LInstRegWrite((U8)0x0F) ; WaitLcd(100) ; 

	/* ---
	 * Clear Display
	 * --- */
	LInstRegWrite((U8)0x01) ; WaitLcd(100) ; 

	/* ---
	 * Cursor or Display Shift
	 *     Shift Left
	 * --- */
	LInstRegWrite((U8)0x18) ; WaitLcd(100) ; 

	/* ---
	 * Entry Mode Set
	 *     Increment DD Ram Address
	 * --- */
	LInstRegWrite((U8)0x06) ; WaitLcd(100) ; 
printf( "lcd init 99 \r\n" );
	/*ClearLcdDisplay() ;*/
}

/*
 * Function : LInstRegWrite
 * Description : LCD Control Register Write
 */
void LInstRegWrite(U8 DATA) 
{ 
	U8 *LcdInstWrAddr ;
printf( "lcd init 91 LCD_Addr_Base = %x \r\n", LCD_Addr_Base );	
	LcdInstWrAddr = (U8 *)LINSTWR ;
printf( "lcd init 92 LcdInstWrAddr=%x; data=%x \r\n", LcdInstWrAddr, DATA );
	*LcdInstWrAddr=  DATA ; 
printf( "lcd init 93 \r\n" );
}

/*
 * Function : LInstRegRead, LDataRegRead
 * Description : LCD Control Register Write
 */
U8 LInstRegRead(void) 
{
	U8 ReadData ;
	ReadData = (U8)LINSTRD ;
	return ReadData ;
}


U8 LDataRegRead(void) 
{
	U8 ReadData ;
	ReadData = (U8)LDATARD ;
	return ReadData ;
}

/*
 * Function : WaitLcd
 * Description : LCD Control Register Write
 */
void WaitLcd(int milisec)
{
	int second ;

	if (!CACHE_ENABLED) second = milisec * 40 ;
	else second = milisec * 200 ;

	while(second--) ;
}

/*
 * Function : LcdBusyCheck
 * Description : Wait Until LCD Busy Flag is Cleared
 */
void LcdBusyCheck(void) 
{
	U8 ReadData ;
	ReadData = (U8)LINSTRD ;
	while (!ReadData) ;
}

/*
 * Function : Mv2LcdLine
 * Description : Move Second LCD Line
 */
void Mv2LcdLine(void)
{
	// Set DD Ram Address to 
	LInstRegWrite((U8)0xA8) ; WaitLcd(100) ; 
}

/*
 * Function : ClearLcdDisplay
 * Description : Clear LCD Displayed Character
 */
void ClearLcdDisplay(void)
{
	LInstRegWrite((U8)0x01) ; WaitLcd(100) ; 
        l2Print("                ","                ") ;
	Mv2LcdLine() ; // Change LCD Line to 2'th Line
}


/*
 * Function : lPut_byte
 * Description : LCD Byte Data Write
 */
void lPut_byte(U8 DATA) 
{ 
	U8 *LcdDataWrAddr ;
	LcdDataWrAddr = (U8 *)LDATAWR ;
	*LcdDataWrAddr=  DATA ; 
	WaitLcd(3) ; 
}

/*
 * Function : lPrint
 * Description : Wait Until LCD Busy Flag is Cleared
 */
void lPrint(char *ptr ) 
{
    while(*ptr )
        lPut_byte(*ptr++ );
}

void  l1Print(char *prt) 
{
    LInstRegWrite((U8)0x01) ; WaitLcd(100) ; 
    lPrint(prt) ;
    Mv2LcdLine() ; // Change LCD Line to 2'th Line
}

void  l2Print(char *L1,char *L2) 
{
    LInstRegWrite((U8)0x01) ; WaitLcd(100) ; 
    lPrint(L1) ;
    Mv2LcdLine() ; // Change LCD Line to 2'th Line
    lPrint(L2) ;
}


void lfPrint(char *L2,char *fmt,...)
{
    va_list argptr;
    char temp_buf[LCD_DIGIT_NO];

    va_start(argptr, fmt);
    vsprintf(temp_buf, fmt, argptr);
    LInstRegWrite((U8)0x01) ; WaitLcd(100) ; 
    l2Print(temp_buf,L2);
    va_end(argptr);
}


/*
 * Function : LcdUsrModeSet
 * Description : User Mode LCD Display
 *               Shifted Display
 */
void LcdUsrModeSet() 
{
	LInstRegWrite((U8)0x30) ; WaitLcd(100) ; 
	LInstRegWrite((U8)0x01) ; WaitLcd(100) ; // Clear
	LInstRegWrite((U8)0x8F) ; WaitLcd(100) ; 
	/* ---
	 * Entry Mode Set
	 *     Increment DD Ram Address
	 *     Shift Character
	 * --- */
	LInstRegWrite((U8)0x07) ; WaitLcd(100) ; 
}


⌨️ 快捷键说明

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