FYD12864-0402B液晶显示模块C语言程序

各位网友大家好,我想让大家帮忙找找FYD12864-0402B液晶显示模块的C语言程序,谢谢大家... 各位网友大家好,我想让大家帮忙找找FYD12864-0402B液晶显示模块的C语言程序,谢谢大家 展开
 我来答
手机用户02424
2008-08-26
知道答主
回答量:2
采纳率:0%
帮助的人:5.7万
展开全部
/*此程序适用于FYD12864-0402B*/
#include <REG932.H>

#define uchar unsigned char
#define uint unsigned int

//uchar data CMD;
//uchar data DATA;
uchar idata busy,Line,Col;
sbit RS= P2^0;
sbit RW= P2^1;
sbit E= P1^7;
sbit LCD_LIGHT= P2^7;
sbit LCD_RST= P2^6;
code char STR1[]= "成都飞宇达";
code char STR2[]= "欢迎您";
code char STR3[]= "谢谢";
code char STR4[]= "SCCDCYB";

void Read_Busy();
void Delay100us(volatile uint n);
void Clear_LCD();
void Write_Single_CMD(uchar cmd);
void Write_Single_Data(uchar a);
void Init_LCD();
void Display(uchar *ptr,uchar ddram) ;
void Init_IO(void);
void Reset_St7920(void);
void DispSetCursor(uchar LineNum,uchar ColumnNum);

void main(void)
{
uchar i,j;
Init_IO();
Reset_St7920();
// LCD_LIGHT=1;
Clear_LCD();
Init_LCD();
Write_Single_CMD(0X01);
Display(STR1,0X80);
Display(STR2,0X90);
Display(STR3,0X88);
Display(STR4,0X98);
Delay100us(200);
Write_Single_CMD(0x80);
j=0;
for (i=0;i<32;i++)
{
Write_Single_Data(0xb4);
Write_Single_Data(0xde+j);
// Write_Single_CMD(0x01); //将光标移到0x9C
j++;
}
// Write_Single_CMD(0x01); //将光标移到0x9C
Write_Single_CMD(0x01); //光标移到0x9C
Write_Single_CMD(0x34); //将光标移到0x9C
Write_Single_CMD(0x36); //将光标移到0x9C
for (i=0;i<32;i++)
{
Write_Single_CMD(0x80+i);
Write_Single_CMD(0x80);
// Write_Single_CMD(0x01); //将光标移到0x9C
for (j=0;j<8;j++)
{
Write_Single_Data(0x00);
Write_Single_Data(0x00);
}
}
for (i=0;i<32;i++)
{
Write_Single_CMD(0x80+i);
Write_Single_CMD(0x88);
// Write_Single_CMD(0x01); //将光标移到0x9C
for (j=0;j<8;j++)
{
Write_Single_Data(0x00);
Write_Single_Data(0x00);
}
}
for (i=0;i<32;i++)
{
Write_Single_CMD(0x80+i);
Write_Single_CMD(0x80);
// Write_Single_CMD(0x01); //将光标移到0x9C
for (j=0;j<8;j++)
{
Write_Single_Data(0xFF);
Write_Single_Data(0xFF);
}
}
for (i=0;i<32;i++)
{
Write_Single_CMD(0x80+i);
Write_Single_CMD(0x88);
// Write_Single_CMD(0x01); //将光标移到0x9C
for (j=0;j<8;j++)
{
Write_Single_Data(0xFF);
Write_Single_Data(0xFF);
}
}

// DispSetCursor(1,3);
// for (i=0;i<64;i++)
// {
// for (j=0;j<16;j++)
// {
// Write_Single_Data(0x3f);
// Write_Single_Data(0xff);
// }
// }

while(1)
{
}

}

void Init_IO(void)
{
P0M1=0X00;
P0M2=0X00; //P0=I/O
P1M1=0X00; //P1.4:输入(DR)
P1M2=0X00; //P1=P1.6为推挽,其它为I/O
P2M1=0X00; //P2.6、P2.7:输入(AM、CD)
P2M2=0X00; //P2=I/O
P3M1=0X00;
P3M2=0X00; //P3=I
}

void Read_Busy(void) //读忙操作
{
P0=0x0ff;
RS=0;
RW=1;
do{
E=1;
busy=P0;
E=0;
}while(busy>0x7f);
}

void Reset_St7920(void)
{
LCD_RST=0;
Delay100us(100);
LCD_RST=1;
Delay100us(200);
}

void Delay100us(volatile uint n)
{
uchar i;
while(n--)
for(i=0;i<40;i++)
;
}

void Write_Single_CMD(uchar cmd) //写单字节命令字
{
Read_Busy();
RS=0;
RW=0;
E=1;
P0=cmd;
E=0;
P0=0xff;
}

void Write_Single_Data(uchar a) //写单字节数据
{
Read_Busy();
RS=1;
RW=0;
E=1;
P0=a;
E=0;
P0=0xff;
}

void Init_LCD(void) //初始化LCD模块
{
Write_Single_CMD(0x30); //功能设置--8BIT控制界面,基本指令集
Delay100us(10);
Write_Single_CMD(0x30); //功能设置--8BIT控制界面,基本指令集
Delay100us(5);
Write_Single_CMD(0X0C);
Delay100us(5);
Write_Single_CMD(0x01); //清除屏幕显示,将DDRAM的地址计数器清零
Delay100us(2);
Write_Single_CMD(0x06); //DDRAM的地址计数器(AC)加1
Delay100us(1);
}

void DispSetCursor(uchar LineNum,uchar ColumnNum)
{
uchar i=0x00;
switch(LineNum&0x0f) //确定行号
{
case 0x00: i=0x80; break;
case 0x01: i=0xa0; break;
case 0x02: i=0x88; break;
case 0x03: i=0xa8; break;
default : break;
}
i = (ColumnNum&0x0f)|i; //确定列号
Write_Single_CMD(i);

}

void Clear_LCD(void)
{
Read_Busy();
RS=0;
RW=0;
P0=0x01;
E=1;
E=0;
}

/*
void ExpandFucntionEnable(void)
Function:
*/
void ExpandFunctionEnable(void)
{
Write_Single_CMD(0x34);
}

/*
void ExpandFunctionDisable(void)
Function:
*/
void ExpandFunctionDisable(void)
{
Write_Single_CMD(0x30);
}

/*
void ClearScreen(void)
Function:
*/
void ClearScreen(void)
{
Write_Single_CMD(0x01);
Delay100us(100);
}

/*
void CursorGoHome(void)
Funtion:
Cursor go home,DDRAM's address counter 'AC=0x00'.
*/
void CursorGoHome(void)
{
Write_Single_CMD(0x02);
}

/*
void DisplayOn(void)
Function:
*/
void DisplayOn(void)

{
Write_Single_CMD(0x0d); //整体显示开,游标开,游标位置反白禁止

}

/*
void DisplayOff(void)
Function:
*/
void DisplayOff(void)
{
Write_Single_CMD(0x09);
}

/*
void IdleMode(void)
Function:
Expand instruction.
*/
void IdleMode(void)
{
Write_Single_CMD(0x01);
}

/*
void RollInstructionEnable(void)
Function:
Expand instruction.
*/
void RollInstructionEnable(void)
{
Write_Single_CMD(0x03);
}

/*
void RollInstructionDisable(void)
Function:
Expand instruction.
*/
void RollInstructionDisable(void)
{
Write_Single_CMD(0x02);
}

/*
void SetRollAddress(unsigned char WhichLine)
Function:
Expand instruction.
*/
void SetRollAddress(uchar WhichLine)
{
ExpandFunctionEnable();
RollInstructionEnable();
Write_Single_CMD(WhichLine|0x40);
ExpandFunctionDisable();
}

/*
void Sleep(void)
Function:
Expand instruction.
*/
void Sleep(void)
{
Write_Single_CMD(0x08);
}

/*
void Waken(void)
Function:
Expand instruction.
*/
void Waken(void)
{
Write_Single_CMD(0x0c);
}

/*
void NegativeDisplay(uchar WhichLine)
Function:
Expand instruction
WhichLine=1,2,3,4
*/
void NegativeDisplay(uchar WhichLine)
{
if(WhichLine>4)return;
if(WhichLine==0)return;
Write_Single_CMD((WhichLine-1)|0x04);
}

void Display(uchar *ptr,uchar ddram)
{
uchar i,l,x;
l=0;
if(ddram<0x88)
{ Line=0; } //定位行地址:第一行
else if(ddram<0xA0)
{ Line=2; } //定位行地址:第三行
else if(ddram<0xA8)
{ Line=1; } //定位行地址:第二行
else
{ Line=3; } //定位行地址:第四行

Col=0x0f&ddram; //定位列地址
if(Col>0x07)
{ Col=Col-0x08;}
x=Col*2;
Write_Single_CMD(ddram); // 定位显示起始地址
while ((ptr[l])!='\0')
{l++;}
for (i=0;i<l;i++)
{
Write_Single_Data(ptr[i]); //输出单个字符
x++;
if (x ==0x10)
{
x=0;
Line++;
switch (Line)
{
case 0:Write_Single_CMD(0x80);
break;
case 1:Write_Single_CMD(0xA0);
break;
case 2:Write_Single_CMD(0x88);
break;
case 3:Write_Single_CMD(0xA8);
}
if (Line>3)
{
Write_Single_CMD(0x80);
Line=0;
}
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式