您的位置 首页 芯闻

STC89C52单片机12864液晶显示

实现功能:在实验板上所佩带的LCD12864上显示想显示的汉字,达

///////////////////////////////////////////////////////////////////////

完结功用:在试验板上所佩戴的LCD12864上显现想显现的汉字,到达学习操作
12864的意图
试验板类型:KBL-XYD-C52
试验称号: lcd12864汉字显现试验
编写人: 谢应东
编写日期: 2012-5-3
///////////////////////////////////////////////////////////////////////
#include

#define uchar unsigned char
#define uint unsigned int

#define Lcd_IO P0
#define Commd 0
#define Data 1

sbit LCDRS=P3^4; //12864是数据挑选端仍是指令挑选端
sbit LCDRW=P3^5; //12864的读写操作端
sbit LCDEN=P3^6; //12864的使能端
sbit LCDPSB=P3^7; //挑选12864是并行输入仍是串行输入

sbit wei=P2^7; //界说数码管的位选
sbit duan=P2^6; //界说数码管的段选

//一幅公鸡图形数据
uchar code Lcd_num[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x70,0x00,0x70,0xC0,0x02,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x70,0x00,0x70,0xC0,0x0F,0x03,0x00,0x3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x00,0x70,0xC0,0xFF,0x83,0x00,0xC0,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xE8,0x03,0xFE,0xC0,0x1C,0x03,0x03,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xCC,0x00,0x70,0xC0,0x1C,0x33,0x04,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xC7,0x00,0x76,0xDC,0x1C,0x33,0x08,0x00,0x01,0x00,0x00,0x00,0xE0,0x30,0x00,
0x03,0x87,0x87,0x7F,0xFC,0x1C,0x33,0x18,0x06,0x0C,0xE0,0x00,0x00,0xC0,0x30,0x00,
0x07,0x03,0xF7,0xFF,0xFC,0xFF,0xB3,0x10,0x06,0x1D,0xC0,0x00,0x00,0xC0,0x30,0x00,
0x0C,0x01,0xE7,0xFE,0xDC,0xFF,0xB3,0x20,0x0E,0x3A,0xF0,0x00,0x00,0xC0,0x70,0x00,
0x1F,0xFF,0xE7,0x0E,0xDC,0x1C,0x33,0x20,0x0E,0x31,0xD0,0x00,0x01,0xC0,0x70,0x00,
0x2F,0xFF,0xA3,0x04,0xDC,0x3C,0x33,0x20,0x0E,0x70,0x60,0x00,0x01,0xC0,0x70,0x00,
0x00,0x70,0x03,0xFC,0xDC,0x3E,0x33,0x40,0x0C,0xE0,0x00,0x00,0x01,0xC0,0x60,0x00,
0x00,0x70,0x00,0x18,0xDC,0x3F,0x33,0x40,0x0C,0xC1,0x9F,0xC3,0xD9,0xBC,0x6E,0x1C,
0x00,0x70,0x00,0x70,0xDC,0x3F,0x33,0x40,0x1D,0x81,0x9F,0xE7,0xF9,0xFC,0x6E,0x18,
0x1F,0xFF,0xE0,0xF2,0xDC,0x7F,0x33,0x40,0x1F,0x81,0x98,0xE7,0x39,0x8E,0xE6,0x38,
0x1F,0xFF,0xE0,0x76,0xDC,0x7D,0x33,0x40,0x1F,0x03,0x98,0xEE,0x33,0x8E,0xE6,0x30,
0x08,0x70,0x00,0x7C,0xDC,0x5C,0x33,0x20,0x1F,0x83,0xB8,0xCE,0x33,0x8C,0xE6,0x30,
0x0C,0x71,0x87,0xF8,0xDC,0xDC,0x33,0x20,0x1B,0x83,0x38,0xCE,0x33,0x0C,0xC6,0x60,
0x06,0x71,0x07,0xF1,0xDC,0x9C,0x33,0x20,0x19,0x83,0x38,0xCC,0x33,0x0C,0xC6,0x60,
0x07,0x73,0x07,0x71,0xDD,0x9C,0x03,0x10,0x39,0xC3,0x31,0xCC,0x73,0x1C,0xC6,0xC0,
0x03,0x72,0x00,0x71,0x9C,0x1C,0x03,0x18,0x39,0xC3,0x31,0xCC,0x77,0x1D,0xC6,0xC0,
0x03,0x76,0x00,0x71,0x9C,0x1C,0x03,0x08,0x39,0xC7,0x31,0xDC,0x67,0x1D,0xC7,0x80,
0x02,0x74,0x00,0x73,0x1C,0x1C,0x03,0x04,0x38,0xE7,0x71,0x9C,0xE7,0x39,0x83,0x80,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x06,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0xC0,0x00,0x0C,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0xC0,0x00,0x0C,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x80,0x00,0x18,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x00,0x30,0x00,0x05,0x04,0x84,0x00,0x00,0x00,0x01,0x04,0x00,0x14,0x00,
0x00,0x11,0x10,0x08,0x00,0x04,0x82,0x48,0x1F,0xF0,0x00,0x00,0x84,0x00,0x12,0x00,
0x00,0x1F,0xF0,0x04,0x00,0x04,0x0F,0xFE,0x00,0x10,0x00,0x00,0x04,0x00,0x10,0x00,
0x00,0x00,0x40,0x04,0x03,0xFF,0x88,0x02,0x08,0x10,0x00,0x03,0xE7,0x8F,0xFE,0x00,
0x00,0x12,0x40,0x0A,0x00,0x04,0x03,0xF8,0x04,0x10,0x00,0x00,0x04,0x00,0x10,0x00,
0x00,0x3F,0x78,0x0A,0x00,0x04,0x00,0x10,0x02,0x10,0x00,0x02,0x44,0x00,0x10,0x00,
0x00,0x12,0x88,0x0A,0x01,0xF4,0x00,0x20,0x00,0x50,0xFF,0xE1,0x5F,0x87,0xD0,0x00,
0x00,0x12,0x20,0x11,0x00,0x44,0x0F,0xFE,0x01,0x90,0x00,0x01,0x50,0x81,0x10,0x00,
0x00,0x1E,0x20,0x11,0x00,0x42,0x00,0x40,0x06,0x10,0x00,0x00,0x90,0x81,0x08,0x00,
0x00,0x12,0x50,0x20,0x80,0x42,0x80,0x40,0x38,0x10,0x00,0x00,0xD0,0x81,0x0A,0x00,
0x00,0x12,0x50,0x40,0x40,0x79,0x80,0x40,0x00,0x10,0x00,0x03,0x1F,0x81,0xE6,0x00,
0x00,0x1E,0x88,0x80,0x23,0x80,0x81,0xC0,0x00,0xE0,0x00,0x00,0x10,0x8E,0x02,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x11,0xF0,0x04,0x00,0x40,0x00,0x80,0x13,0xE0,0x51,0x00,0x20,0x00,0x00,
0x00,0x00,0x1C,0x90,0x04,0x00,0x20,0x1F,0xFC,0x12,0x20,0x51,0x07,0xFF,0x00,0x00,
0x00,0x00,0x24,0x91,0x3F,0x87,0xFF,0x11,0x04,0x13,0xE0,0x91,0x01,0x04,0x00,0x00,
0x00,0x00,0x49,0x30,0x84,0x80,0x80,0x0F,0xF8,0x7E,0x20,0xBF,0x80,0x88,0x00,0x00,
0x00,0x00,0x3E,0x00,0x04,0x80,0x80,0x02,0x20,0x13,0xE1,0x91,0x03,0xFE,0x00,0x00,
0x00,0x00,0x2A,0xA0,0x04,0x80,0xFE,0x01,0xC0,0x10,0x00,0x91,0x02,0x52,0x00,0x00,
0x00,0x00,0x3E,0xF0,0x7F,0xC0,0x82,0x1E,0x38,0x1B,0xF0,0x91,0x02,0x8A,0x00,0x00,
0x00,0x00,0x2B,0x20,0x04,0x00,0x82,0x00,0x80,0x70,0x80,0xFF,0xC3,0x76,0x00,0x00,
0x00,0x00,0x3E,0x20,0x8A,0x01,0x02,0x1F,0xFC,0x12,0xE0,0x80,0x02,0x52,0x00,0x00,
0x00,0x00,0x2A,0xF1,0x0A,0x01,0x02,0x02,0xA0,0x12,0x80,0x91,0x02,0x72,0x00,0x00,
0x00,0x00,0x2A,0x20,0x11,0x02,0x02,0x04,0x90,0x12,0x80,0xA0,0x82,0x02,0x00,0x00,
0x00,0x00,0x46,0x20,0x60,0xC4,0x1C,0x18,0x8C,0x35,0xF0,0xC0,0x42,0x06,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
///////////////////////////////////////////////////////////////////////
函数称号:DelayUs
函数功用:让单片机延时10us,即当iNumber=10时,延时为100us
参数介绍:iNumber:界说要延时10us的次数
返回值:
注意事项:无
///////////////////////////////////////////////////////////////////////
void DelayUs(uint iNumber)
{
for(;iNumber>0;iNumber–);
}
///////////////////////////////////////////////////////////////////////
函数称号:毫秒延时函数
函数功用:完结毫秒级的延时
参数介绍:Delay_MS: 界说需求延时的毫秒的数值
iNumber: 记载Delay_MS的数值,以for句子完结所要求的延时
iValue: 要延时毫秒所要进行的循环数值,本数值为实践测得
返回值:
注意事项:本试验是在所用晶振为12M的前提下完结的毫秒延时,本函数是经过循环的形
式完结,所以假如改动了晶振的频率,请做相应的改动
///////////////////////////////////////////////////////////////////////
void DelayMs(uint Delay_MS)
{
uint iNumber,iValue;
for(iNumber=0;iNumber{
iValue=107;
while(iValue–);
}
}
///////////////////////////////////////////////////////////////////////
函数称号:WriteLCD_CommdData
函数功用:向12864写入一条指令或一个字节的数据
参数介绍:cCommd:挑选是写入指令了仍是数据,当cCommd=1时,为指令,cCommd=0相反
返回值: cData:要写入的指令或数据
注意事项:无
///////////////////////////////////////////////////////////////////////
void WriteLCD_CommdData(uchar cCommd,uchar cData)
{
if(cCommd)
LCDRS=1; //数据
else LCDRS=0; //指令
Lcd_IO=cData;
LCDRW=0;
LCDEN=1;
DelayUs(30);
LCDEN=0;
}
///////////////////////////////////////////////////////////////////////
函数称号:Init_LCD()
函数功用:初始化12864液晶
参数介绍:无
返回值:
注意事项:初始化的详细进程请看12864的数据手册
///////////////////////////////////////////////////////////////////////
void Init_LCD() //液晶初始化
{
DelayUs(10); //外部复位
LCDPSB=1; //挑选12864为并行形式
WriteLCD_CommdData(Commd,0x30); //根本指令格局
DelayUs(30);
WriteLCD_CommdData(Commd,0x01); //液晶清屏
DelayMs(30);
WriteLCD_CommdData(Commd,0x06); //设置显现格局,光标方位
WriteLCD_CommdData(Commd,0x0c);
}
//液晶自界说显现
void Lcd_define(uchar *str)
{
uint m,n;
WriteLCD_CommdData(Commd,0x34); //设置位扩展指令格局
for(m=0;m<32;m++)
{
for(n=0;n<8;n++)
{
WriteLCD_CommdData(Commd,0x80+m); //写纵坐标,00H–1FH
WriteLCD_CommdData(Commd,0x80+n); //写横坐标,00H–07H
WriteLCD_CommdData(Data,str[m*16+n*2]);
WriteLCD_CommdData(Data,str[m*16+n*2+1]);//接连写两个数据
}
}

for(m=32;m<64;m++)
{
for(n=0;n<8;n++)
{
WriteLCD_CommdData(Commd,0x80+m-32); //写纵坐标,00H–1FH
WriteLCD_CommdData(Commd,0x88+n); //写横坐标,08H–0FH
WriteLCD_CommdData(Data,str[m*16+n*2]);
WriteLCD_CommdData(Data,str[m*16+n*2+1]); //接连写两个数据
}
}
WriteLCD_CommdData(Commd,0x30); //根本指令格局
WriteLCD_CommdData(Commd,0x01); //清屏
DelayMs(30);
WriteLCD_CommdData(Commd,0x34); //扩展指令格局
WriteLCD_CommdData(Commd,0x36); //显现自界说图形
}
//主函数
void main()
{
wei=1;
P0=0XFF;
wei=0;
duan=1;
P0=0x00;
duan=0;

Init_LCD();
Lcd_define(Lcd_num);
while(1);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/xinwen/262850.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部