【文件属性】:
文件名称:LCD12864显示汉字和图案(C语言)
文件大小:40KB
文件格式:RAR
更新时间:2015-02-25 13:01:55
LCD12864显示汉字和图案(C语言)
/***********************************************************
实验名称:LCD12864显示汉字示例程序
程序说明:烧好程序,正确插上LCD12864即可观察到LCD上显示的汉字。
注意:USB供电可能不足,这时需要用变压器供电。
***********************************************************/
/***********************************************************
模块名称:st7920 并行方式驱动12864液晶驱动
功能概要:st7920显示驱动
完成日期:2008.07.08
驱动芯片:st7920
***********************************************************/
#include
#define uint unsigned int
#define uchar unsigned char
#define x1 0x80
#define x2 0x88
#define y 0x80
#define comm 0
#define dat 1
sbit RS = P2^0; //H=data; L="command";
sbit RW = P2^1; //H=read; L="write";
sbit E = P2^2; //input enable;
sbit PSB= P2^3; //H=并口; L="串口";
sbit RST= P2^5; //Reset Signal 低电平有效
sbit busy=P1^7; //lcd busy bit
void wr_lcd (uchar dat_comm,uchar content);
void chk_busy (void);
void delay (uint us);
uchar code tab31[]={
" RF-X1开发板 "
" 您学习的首选 "
};
uchar code tab32[]={
/*-- 调入了一幅图像:F:\梁\画图\HOCO12832.bmp --*/
/*-- 宽度x高度=128x32 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x7F,0x80,0x00,0x00,0x00,0x00,0x18,0x0C,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x01,0xFF,0x80,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x13,0x10,0x03,0xFE,0x00,
0x03,0xFF,0xC0,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x3F,0x30,0x1F,0xFF,0xC0,
0x03,0xFF,0xE0,0x00,0x00,0x00,0x00,0x8C,0x03,0xF0,0x00,0x7F,0xE0,0x7C,0x01,0xE0,
0x03,0xFF,0xF0,0x00,0x00,0x00,0x01,0x36,0x06,0xC0,0x00,0x5F,0xC0,0xFF,0xFC,0x60,
0x01,0xFF,0xF0,0x00,0x00,0x00,0x02,0x1B,0x0F,0x80,0x00,0xFF,0x01,0xFE,0x0F,0x30,
0x00,0xEF,0xF0,0x00,0x00,0x00,0x02,0x6D,0x9F,0x00,0x00,0x3E,0x03,0xFF,0xF1,0x90,
0x00,0xFF,0xF8,0x00,0x00,0x00,0x04,0x36,0xFE,0x00,0x01,0xFF,0x07,0xFF,0xFC,0x90,
0x00,0xEF,0xFF,0xFF,0x80,0x00,0x04,0xDB,0x7E,0x00,0x03,0xFF,0x87,0xFF,0xFC,0xD0,
0x00,0x0F,0xFF,0xFF,0xC0,0x00,0x04,0x6D,0xFC,0x00,0x07,0xFF,0x8F,0xFF,0xFE,0x50,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x36,0xFC,0x10,0x07,0xFF,0x8F,0xFF,0xFE,0x90,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x1B,0xF8,0x10,0x07,0xFF,0xCF,0xFF,0xFE,0x80,
0x00,0x0F,0xFF,0xFF,0xF0,0x00,0x04,0x0F,0xF8,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0x07,0xFF,0xFF,0xF0,0x00,0x04,0x07,0xF0,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x02,0x03,0xF0,0x20,0x07,0xFF,0xFF,0xFF,0xBA,0x00,
0x00,0xFD,0xFF,0xFF,0xFC,0x00,0x02,0x03,0xF0,0x20,0x03,0xFF,0xFF,0xDF,0xB8,0x00,
0x00,0xC1,0xC0,0x3F,0xFC,0x00,0x01,0x01,0xE0,0x40,0x00,0xFF,0xFF,0xDF,0xB0,0x00,
0x00,0x81,0xC0,0x3F,0xCE,0x00,0x00,0x81,0xE0,0x80,0x00,0x7F,0xFF,0xDF,0xA0,0x00,
0x00,0x81,0x80,0x1D,0xCF,0x00,0x00,0x41,0xE1,0x00,0x00,0x3F,0xFF,0x9B,0x00,0x00,
0x01,0x83,0x80,0x1F,0xC7,0x80,0x00,0x21,0xE2,0x00,0x00,0x1F,0xFD,0xB6,0x00,0x00,
0x01,0xC3,0x00,0x0E,0xE6,0x80,0x00,0x19,0xEC,0x00,0x00,0x07,0xFE,0x20,0x00,0x00,
0x00,0xC3,0x00,0x07,0x67,0x40,0x00,0x07,0xF0,0x00,0x00,0x03,0x3E,0x00,0x00,0x00,
0x00,0x02,0x00,0x03,0xE7,0xA0,0x00,0x00,0x00,0x00,0x00,0x02,0x8E,0x00,0x00,0x00,
0x00,0x06,0x00,0x03,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x00,0x00,0x00,
0x00,0x06,0x00,0x07,0x03,0x00,0x77,0x46,0x74,0x24,0x80,0x06,0x04,0x00,0x00,0x00,
0x00,0x1C,0x00,0x06,0x00,0x00,0x55,0x45,0x54,0x57,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x1C,0x00,0x0E,0x00,0x00,0x45,0x45,0x74,0x57,0x80,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x00,0x00,0x55,0x45,0x44,0x74,0x80,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x00,0x00,0x77,0x76,0x47,0x54,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code tab5[]={
/*-- 调入了一幅图像:F:\梁\画图\COCK.bmp --*/
/*-- 宽度x高度=128x64 --*/
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,0x04,0x00,0xC0,0x00,0x38,
0x00,0x00,0x30,0x00,0x00,0x69,0xC0,0x00,
0x00,0x00,0x00,0x04,0x18,0xC0,0x00,0x18,
0x00,0x00,0x30,0x00,0x01,0xFF,0xF0,0x00,
0x00,0x00,0x00,0x0C,0x18,0xC0,0x0A,0xBD,
0x50,0x1D,0x75,0xE0,0x01,0xC0,0xF0,0x00,
0x00,0x74,0x00,0x3F,0x8C,0x80,0x1F,0xFF,
0xF0,0x3F,0xFF,0xF0,0x00,0x0D,0xE0,0x00,
0x03,0x8F,0x00,0xF0,0x3F,0xF0,0x30,0x18,
0x00,0x18,0x30,0x60,0x00,0x07,0x00,0x00,
0x0C,0x03,0x80,0xDF,0x30,0x70,0x00,0x38,
0x00,0x1D,0x75,0x60,0x05,0x57,0x54,0x00,
0x10,0x41,0x80,0x3E,0x30,0x20,0x07,0xFF,
0xE0,0x1F,0xFF,0xE0,0x1F,0xFF,0xFF,0x80,
0x21,0xC1,0xC0,0x04,0x3C,0xF0,0x02,0x08,
0x00,0x18,0x30,0x60,0x3F,0x47,0xBF,0x80,
0x40,0xC1,0x80,0x7F,0x9F,0xA0,0x02,0x19,
0x80,0x1D,0x7F,0xE0,0x30,0x03,0x03,0x00,
0xC1,0xC1,0x80,0x2E,0x05,0x80,0x27,0x99,
0x80,0x0F,0xFF,0xE0,0x00,0x03,0x00,0x00,
0x81,0x83,0x00,0x04,0x0D,0x00,0x33,0xE3,
0x00,0x0C,0x70,0x00,0x00,0x03,0x00,0x00,
0x81,0x86,0x00,0x0D,0x99,0x80,0x60,0x3E,
0x00,0x00,0x38,0x01,0x00,0x07,0x00,0x00,
0x81,0xBC,0x00,0x0F,0x39,0xC6,0xE0,0x0F,
0xB6,0x00,0x3F,0xBF,0x00,0x07,0x00,0x00,
0x83,0xF0,0x00,0x1E,0xE0,0xFE,0xE0,0x03,
0xFE,0x00,0x0F,0xFE,0x01,0xFF,0x00,0x00,
0xC3,0x30,0x00,0x89,0x80,0x7C,0x00,0x01,
0xF8,0x00,0x07,0xFC,0x00,0x7C,0x00,0x00,
0x63,0x31,0xFF,0x00,0x00,0x00,0x00,0x00,
0x20,0x00,0x00,0x50,0x00,0x00,0x00,0x00,
0x63,0x19,0x12,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0x19,0x04,0x3F,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,
0x07,0x19,0x88,0x3F,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,
0x06,0x0C,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0E,0x0C,0x20,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
0x3E,0x0E,0x40,0x0A,0x6D,0xB4,0x07,0x84,
0x35,0x1A,0x67,0xA2,0x01,0xA7,0x9B,0x00,
0x45,0x86,0x80,0x0A,0xAA,0xB4,0x04,0x44,
0x26,0x92,0x68,0xA2,0x01,0x34,0x93,0x00,
0x00,0x03,0x01,0x0E,0xAE,0xB4,0x04,0x44,
0x61,0x1B,0x68,0xA2,0x01,0x0C,0x5B,0x00,
0x00,0x07,0x03,0x0A,0xBA,0xD8,0x06,0x84,
0x41,0xF2,0xC8,0x22,0x03,0x08,0xD7,0x00,
0x00,0x07,0x87,0x0D,0x96,0x68,0x05,0x84,
0x61,0x9B,0xE8,0x22,0x02,0x0C,0x5F,0x00,
0x00,0x1F,0xF6,0x0D,0xB6,0x58,0x04,0x84,
0x45,0x15,0xA8,0xA2,0x03,0x14,0xD5,0x00,
0x00,0x10,0xFC,0x05,0x92,0x48,0x04,0x84,
0x25,0x93,0xAC,0xA2,0x01,0x24,0x95,0x00,
0x00,0x00,0x00,0x0D,0x96,0x49,0x04,0x44,
0x3D,0x14,0xA7,0x1C,0x41,0xE7,0x15,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,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,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,
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,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,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
};
/******************************************************************************************
* 函数名称 :
* 功能描述 :
* 参数 : 参数名称: 输入/输出? 类型 描述
*
* 返回值 :
* 作者 :
* 创建日期 :2007-12-19
* 全局变量 :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本 : 修改人: 修改日期:
* 修改说明 :
******************************************************************************************/
void init_lcd (void)
{
RST = 1;
PSB = 1;
wr_lcd(comm,0x30); /*30---基本指令动作*/
wr_lcd(comm,0x01); /*清屏,地址指针指向00H*/
wr_lcd(comm,0x06); /*光标的移动方向*/
wr_lcd(comm,0x0c); /*开显示,关游标*/
}
/******************************************************************************************
* 函数名称 :chn_disp
* 功能描述 : 显示汉字或字符
* 参数 : 参数名称: 输入/输出? 类型 描述
*
* 返回值 :
* 作者 :
* 创建日期 :2007-12-19
* 全局变量 :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本 : 修改人: 修改日期:
* 修改说明 :
******************************************************************************************/
void chn_disp(uchar code *chn)
{
uchar i,j;
wr_lcd(comm,0x30);
wr_lcd(comm,0x80);
for(j=0;j<4;j++)
{
for(i=0;i<16;i++)
wr_lcd(dat,chn[j*16+i]);
}
}
/******************************************************************************************
* 函数名称 :chn_disp1
* 功能描述 : 上半屏显示汉字或字符
* 参数 : 参数名称: 输入/输出? 类型 描述
*
* 返回值 :
* 作者 :
* 创建日期 :2007-12-19
* 全局变量 :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本 : 修改人: 修改日期:
* 修改说明 :
******************************************************************************************/
void chn_disp1(uchar code *chn)
{
uchar i,j;
wr_lcd(comm,0x30);
wr_lcd(comm,0x80);
j=0;
for(i=0;i<16;i++)
wr_lcd(dat,chn[j*16+i]);
wr_lcd(comm,0x90);
j=1;
for(i=0;i<16;i++)
wr_lcd(dat,chn[j*16+i]);
}
/******************************************************************************************
* 函数名称 :img_disp
* 功能描述 : 显示图形
* 参数 : 参数名称: 输入/输出? 类型 描述
*
* 返回值 :
* 作者 :
* 创建日期 :2007-12-19
* 全局变量 :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本 : 修改人: 修改日期:
* 修改说明 :
******************************************************************************************/
void img_disp(uchar code *img)
{
uchar i,j;
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
wr_lcd(comm,0x34);
wr_lcd(comm,y+j);
wr_lcd(comm,x1+i);
wr_lcd(comm,0x30);
wr_lcd(dat,img[j*16+i*2]);
wr_lcd(dat,img[j*16+i*2+1]);
}
}
for(j=32;j<64;j++)
{
for(i=0;i<8;i++)
{
wr_lcd(comm,0x34);
wr_lcd(comm,y+j-32);
wr_lcd(comm,x2+i);
wr_lcd(comm,0x30);
wr_lcd(dat,img[j*16+i*2]);
wr_lcd(dat,img[j*16+i*2+1]);
}
}
wr_lcd (comm,0x36);
}
/******************************************************************************************
* 函数名称 :img_disp1
* 功能描述 : 下半屏显示图形
* 参数 : 参数名称: 输入/输出? 类型 描述
*
* 返回值 :
* 作者 :
* 创建日期 :2007-12-19
* 全局变量 :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本 : 修改人: 修改日期:
* 修改说明 :
******************************************************************************************/
void img_disp1(uchar code *img)
{
uchar i,j;
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
wr_lcd(comm,0x34);
wr_lcd(comm,y+j);
wr_lcd(comm,x2+i);
wr_lcd(comm,0x30);
wr_lcd(dat,img[j*16+i*2]);
wr_lcd(dat,img[j*16+i*2+1]);
}
}
wr_lcd(comm,0x36);
}
/******************************************************************************************
* 函数名称 :lat_disp
* 功能描述 : 显示点阵
* 参数 : 参数名称: 输入/输出? 类型 描述
*
* 返回值 :
* 作者 :
* 创建日期 :2007-12-19
* 全局变量 :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本 : 修改人: 修改日期:
* 修改说明 :
******************************************************************************************/
void lat_disp(uchar data1,uchar data2)
{
uchar i,j,k,x;
x=x1;
for(k=0;k<2;k++)
{
for(j=0;j<16;j++)
{
for(i=0;i<8;i++)
{
wr_lcd(comm,0x34);
wr_lcd(comm,y+j*2);
wr_lcd(comm,x+i);
wr_lcd(comm,0x30);
wr_lcd(dat,data1);
wr_lcd(dat,data1);
}
for(i=0;i<8;i++)
{
wr_lcd(comm,0x34);
wr_lcd(comm,y+j*2+1);
wr_lcd(comm,x+i);
wr_lcd(comm,0x30);
wr_lcd(dat,data2);
wr_lcd(dat,data2);
}
}
x=x2;
}
wr_lcd(comm,0x36);
}
/******************************************************************************************
* 函数名称 :con_disp
* 功能描述 : 当data1=0xff,data2=0xff时,在x0,y0处反白显示16xl*yl
* 参数 : 参数名称: 输入/输出? 类型 描述
*
* 返回值 :
* 作者 :
* 创建日期 :2007-12-19
* 全局变量 :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本 : 修改人: 修改日期:
* 修改说明 :
******************************************************************************************/
void con_disp(uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl)
{
uchar i,j;
for(j=0;j
【文件预览】:
LCD12864显示汉字和图案(C语言)
----12864_Uv2.Bak(2KB)
----12864_Opt.Bak(1KB)
----12864.hex(5KB)
----12864.Opt(1KB)
----12864.OBJ(6KB)
----12864.LST(63KB)
----12864.Uv2(2KB)
----128643.OBJ(16KB)
----12864.M51(15KB)
----128643.LST(23KB)
----12864(13KB)
----12864.plg(236B)
----128643.c(15KB)
----12864.c(21KB)