📄 ym12864r.c
字号:
/**************************************
创建于:2006.9.6
修改于:2006.12.14
作 者 : liaowenbing
****************************************/
#include"YM12864R.h"
///**
//***函数名称:lcd_delay_us
//***说 明:仅限本函数使用
//**/
//static void LcdDelayUs(uint n)
//{
// while(--n);
//}
/**
***函数名称:LcdInit
***功能说明:清除显示,并地址归位,光标不显示
**/
void LcdInit(void)
{
LcdWriteCommand(cmLcdClear); //显示清屏
LcdWriteCommand(cmLcdOpen); //显示开
//LcdWriteCommand(cmLcdGoBack); //地址归位
//LcdWriteCommand(cmLcdLocal);
}
/**
***函数名称:LcdWaitFree
***功能说明:等待lcd空闲
**/
//void LcdWaitFree(void)
static void LcdWaitFree(void)
{
io_SetDir(LCD_Date_DDr,PortIn); //设置输入
io_SetBit(RS,0);
io_SetBit(RW,1);
io_SetBit(EN,1);
macLcdDelay1Us();
while((LCD_Data&0x80) != 0);
io_SetBit(EN,0);
io_SetDir(LCD_Date_DDr,PortOut); //设置输出
}
/**
***函数名称:LcdWriteCommand
***说明:写命令前面自己已经等待了lcd为空闲
**/
void LcdWriteCommand(unsigned char cmd)
{
LcdWaitFree();
io_SetDir(LCD_Date_DDr,PortOut); //设置输出
io_SetBit(EN,0);
io_SetBit(RS,0);
io_SetBit(RW,0);
io_SetData(LCD_Data,cmd);
io_SetBit(EN,1);
macLcdDelay1Us();
io_SetBit(EN,0);
io_SetBit(RW,1);
}
/**
***函数名称:LcdWriteData
***说明:调用前外部函数必须判断lcd状态是否空闲
**/
void LcdWriteData(unsigned char value)
{
LcdWaitFree();
io_SetDir(LCD_Date_DDr,PortOut); //设置输出
io_SetBit(EN,0);
io_SetBit(RS,1);
io_SetBit(RW,0);
io_SetData(LCD_Data,value);
io_SetBit(EN,1);
macLcdDelay1Us();
io_SetBit(EN,0);
io_SetBit(RW,1);
io_SetBit(RS,0);
}
/**
***函数名称:LcdSetXY
*** 功 能 : 设置LCD显示的起始位置
***输入参数:x、y : 显示字符串的位置,X:0-7,Y:0-3
*** 说 明 :LCD第一行显示寄存器地址:0x80-0x87,
*** LCD第二行显示寄存器地址:0x90-0x97
*** LCD第三行显示寄存器地址:0x88-0x8F
*** LCD第四行显示寄存器地址:0x98-0x9F
**/
void LcdSetXY( unsigned char x, unsigned char y )
{
unsigned char address;
switch(y)
{
case 0:
{
address = 0x80 + x;
break;
}
case 1:
{
address = 0x90 + x;
break;
}
case 2:
{
address = 0x88 + x;
break;
}
case 3:
{
address = 0x98 + x;
break;
}
default:
{
address = 0x80 + x;
break;
}
}
LcdWriteCommand( address );
}
/**
***函数名称:LcdWriteString
*** 说 明 :连续写完一个字符串(用指针的时候务必用0结尾),自动换行调整行序功能
**/
void LcdWriteString(unsigned char x,unsigned char y,unsigned char *s)
{
unsigned char thex,they;
LcdSetXY( x, y );
thex = x + x; //
they = y;
while(*s)
{
LcdWriteData( *s);
s++;
if(*s)
{
thex++;
if(thex>15)
{
thex = 0;
they++;
if(they>3)
they = 0;
LcdSetXY( thex, they );
}
}
}
}
/**
***函数名称:LcdWriteStr
***说明:此函数只做”在当前位置显示完一个字符串用,不做位置调整等操作
**/
void LcdWriteStr(unsigned char *s)
{
while(*s)
{
//LcdWriteData( *s++);
LcdWriteData( *s);
s++;
}
}
/**
***函数名称:LcdWriteCountStr
***说明:此函数也只显示指定个数个数据,并不做位置和字符串结尾显示
**/
void LcdWriteCountStr(unsigned char count,unsigned char *s)
{
while(count--)
{
//LcdWriteData( *s++);
LcdWriteData( *s);
s++;
}
}
/**
***函数名称:LcdReadData
*** 说 明 :读出当前地址的值
**/
unsigned char LcdReadData(void)
{
unsigned char ret;
io_SetDir(LCD_Date_DDr,PortIn); //设置输入
io_SetBit(RS,1);
io_SetBit(RW,1);
io_SetBit(EN,1);
macLcdDelay1Us();
ret = LCD_Data;
io_SetBit(EN,0);
io_SetDir(LCD_Date_DDr,PortOut); //设置输出
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -