#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define DPORT P3 // 命令数据输出端口
sbit RS =P2^7 ;
sbit RW =P2^6 ;
sbit E =P2^5 ;
sbit CS2=P2^4 ;
sbit CS1=P2^3 ;
#define disp_start 0xc0 //显示起始行设置.
#define page_add 0xb8 //页面地址设置.(第 0 页)
#define col_add 0x40 //列地址设置. (第 0 列)
#define disp_on 0x3f //打开显示.
#define disp_off 0x3e //关闭显示.
/*--函数声明--*/
void Led_init(void);
void Lcd_clr(void);
void Wr_com(uchar);
void Wr_dat(uchar);
void Rstatue(void);
uchar Rdat(void);
void Display_ch(uchar,uchar,uchar*); // 仅仅只能显示 16*16 汉字
void Position(uchar,uchar);
void Draw_ph(uchar,uchar*); // 画 128*16 的图片 (占两页)
void Delay(uint);
/***********************************************************************************************/
/****************************** 主 函 数 *****************************************/
void main(void)
{
Delay(50);
Led_init(); // LCD初始化
Wr_com(disp_off);//关闭显示.
Lcd_clr(); // LCD清屏
Wr_com(disp_on); //打开显示.
Delay(1000);
// Wr_com(disp_off);//关闭显示.
Draw_ph(0,XTCSH);// 0 表示 页(<7); XTCSH 图片首地址 (128*16)
// Wr_com(disp_on); //打开显示.
Delay(6000);
Lcd_clr(); // LCD清屏
Wr_com(disp_off); //关闭显示.
Draw_ph(2,ZZR);
Display_ch(4,65,WANG); // 5 表示 页(<8); 65 表示 列(<128)[相邻两个汉字列差为 16] ;WANG 显示汉字首地址
Display_ch(4,81,XUE);
Display_ch(4,97,FAN);
Draw_ph(6,NYR);
Wr_com(disp_on); //打开显示.
while(1);
}
/**********************************************************************************************/
/*---------------------- LCD12864 显示部分 (控制芯片 KS0108 )---------------------------*/
/**********************************************************************************************/
/*----------------LCD初始化-------------------------------------*/
void Led_init(void)
{
P2=0;
Wr_com(disp_start); //显示起始行设置.
Wr_com(page_add); //页面地址设置.
Wr_com(col_add); //列地址设置.
Wr_com(disp_on); //打开显示.
}
/*---------------------LCD清屏---------------------------------*/
void Lcd_clr(void)
{
uchar page,col;
CS1=0;
CS2=0;
for (page=0;page<8;page++)
{
Wr_com(page_add | page);
Wr_com(col_add);
for (col=0;col<64;col++) Wr_dat(0x00); //列地址自动加一.
}
}
/*---------------------写命令----------------------------------*/
void Wr_com(uchar c)
{
Rstatue();
RS=0;
RW=0;
DPORT=c; // "写" (下降沿有效)
E=1;
E=0;
}
/*---------------------写数据----------------------------------*/
void Wr_dat(uchar c)
{
Rstatue();
RS=1;
RW=0;
DPORT=c; // "写" (下降沿有效)
E=1;
E=0;
}
/*----------------------读状态---------------------------------*/
void Rstatue(void)
{
uchar da
DPORT=0xff;
RS=0;
RW=1;
while(1) // 有必要让 E 的上升沿在循环体中
{
E=0;
temp=(DPORT&0x90); // "读" (上升沿有效)
E=1;
if(temp==0) break;
}
E=0;
}
/*-----------------------读数据--------------------------------*/
/*uchar Rdat(void)
{
uchar da
Rstatue();
RS=1;
RW=1;
temp=DPORT; // "读" (上升沿有效)
E=0;
E=1;
return temp;
}
/*----------------------单个显示汉字程序( 16*16 )----------------------------*/
void Display_ch(uchar page,uchar col,uchar *p)
{
uchar i,j,X,Y;
X=page;
Y=col;
CS1=0;
CS2=1;
for(j=0;j<2;j++)
{
for(i=0;i<16;i++)
{
if(Y>63) // 到了右便半屏幕
{
Y=Y-64 ;
CS1=1 ;
CS2=0 ;
}
if(i<1||Y!=0) Position(X,Y);
Wr_dat(*p); // 列 自动加 1
Y++;
p++;
}
X++;
Y=col;
}
CS1=0;
CS2=0;
}
/*---------------------定位显示坐标---------------------*/
void Position(uchar page,uchar col)
{
uchar X,Y; // X 表示行, Y 表示列
X= page | page_add ;
Y= col | col_add ;
Wr_com(X) ;
Wr_com(Y) ;
}
/*------------------ 画图程序(128*16 ; 二页) -------------------*/
void Draw_ph(uchar page,uchar *p)
{
uchar i,j;
uchar temp=page;
for(j=0;j<2;j++)
{
CS1=0; // 左半屏幕
CS2=1;
Wr_com(page_add|temp);
Wr_com(col_add);
for(i=0;i<64;i++)
{
Wr_dat(*p); // 列 自动加 1
p++;
}
CS1=1; // 右半屏幕
CS2=0;
Wr_com(page_add|temp);
Wr_com(col_add);
for(i=0;i<64;i++)
{
Wr_dat(*p); // 列 自动加 1
p++;
}
temp++;
}
CS1=0;
CS2=0;
}
/*---------------------延时程序-------------------------*/
void Delay(uint delay)
{
uchar da
while(delay)
{
for(i=0;i<125;i++) {;}
delay--;
}
}
/**********************************************************************************************/
/***************************************************************************************************************/
/* 汉 字 字 模(下面代码保存为Zhiku.h文件)
/***************************************************************************************************************/
#define uchar unsigned char
// " 制作人: "
uchar co
0x80,0x40,0x20,0xF8,0x07,0x22,0x18,0x0C,0xFB,0x48,0x48,0x48,0x68,0x48,0x08,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //
0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,
0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xFF,0x04,0x04,0x04,0x04,0x06,0x04,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x01,0x06,0x0C,0x18,0x30,0x60,0x20,0x00,
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
// 系统初始化
uchar co
0x20,0x30,0x2C,0xA3,0x60,0x10,0x84,0xC4,0xA4,0x9D,0x86,0x84,0xA4,0xC4,0x84,0x00,
0x00,0x08,0x88,0xC9,0x2E,0x98,0x48,0x00,0x08,0x08,0xF8,0x08,0x08,0xFC,0x08,0x00,
0x10,0x90,0x70,0x1F,0x12,0xF0,0x00,0x20,0x70,0x28,0x27,0x22,0x28,0x70,0x20,0x00,
0x80,0x40,0x20,0xF8,0x07,0x02,0x00,0x00,0xFF,0xC0,0x60,0x30,0x1C,0x08,0x00,0x00,
0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
0x00,0x40,0x21,0x13,0x09,0x05,0x41,0x81,0x7F,0x01,0x05,0x09,0x13,0x62,0x00,0x00,
0x20,0x22,0x23,0x12,0x12,0x92,0x40,0x30,0x0F,0x00,0x00,0x3F,0x40,0x41,0x70,0x00,
0x02,0x01,0x00,0x7F,0x01,0x02,0x44,0x20,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,
0x40,0x21,0x12,0x0C,0x06,0x09,0x30,0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,
0x00,0x00,0x00,0x7F,0x00,0x04,0x02,0x01,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,0x00,
0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };
// 2008.08.16
uchar co
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x88,0x88,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,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00 };
// " 王 "
uchar co
0x40,0x40,0x41,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x41,0x61,0x40,0x00 };
// " 雪 "
uchar co
0x00,0x00,0x42,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0xFE,0x00,0x00,0x00 };
// " 凡 "
uchar co
0x00,0x40,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00 };
/**********************************************************************************************/
上一篇:AT89S5X的ISP下载线制作
下一篇:单片机通讯程序
推荐阅读最新更新时间:2024-03-16 15:04