12864液晶不带字库的用C语言和51单片机编程
展开全部
以下是源代码
/*******************************main.h******************************/
#ifndef _MAIN_H
#define _MAIN_H
#include <reg52.h>
#define LcdDataPort P2 //数据端口
#ifndef UCHAR_DEF
#define UCHAR_DEF
typedef unsigned char uchar;
#endif
sbit Reset = P3^0; //复位
sbit RS = P3^1; //指令数据选择
sbit E = P3^2; //指令数据控制
sbit CS1 = P3^4; //左屏幕选择,低电平有效
sbit CS2 = P3^5; //右屏幕选择
sbit RW = P3^3; //读写控制
sbit busy = P2^7; //忙标志
void SetOnOff(uchar onoff); //开关显示
void SelectScreen(uchar screen);//选择屏幕
void ClearScreen(uchar screen); //清屏
void Show1616(uchar lin,uchar colum,uchar *address);//显示一个汉字
void CheckState(); //判断状态
void LcdDelay(unsigned int time); //延时
void WriteData(uchar dat); //写数据
void SendCommand(uchar command); //写指令
void SetLine(uchar line); //置行地址
void SetColum(uchar colum);//置列地址
void SetStartLine(uchar startline);//置显示起始行
void InitLcd(); //初始化
void ResetLcd(); //复位
#endif
/*********************************************************************/
/***********************************lcd.c****************************************/
#include "main.h"
void CheckState()
{
E = 1;
RS = 0;
RW = 1;
LcdDataPort = 0xff;
while(!busy);
}
void LcdDelay(unsigned int time)
{
while(time --);
}
void WriteData(uchar dat)
{
CheckState();
E = 1;
RS = 1;
RW = 0;
LcdDataPort = dat;
E = 0;
}
void SendCommand(uchar command)
{
CheckState();
E = 1;
RW = 0;
RS = 0;
LcdDataPort = command;
E = 0;
}
void SelectScreen(uchar screen) //0-全屏,1—左屏,2-右屏
{
switch(screen)
{
case 0 :
CS1 = 0;
LcdDelay(2);
CS2 = 1;
LcdDelay(2);
break;
case 1 :
CS1 = 1;
LcdDelay(2);
CS2 = 0;
LcdDelay(2);
break;
case 2 :
CS1 = 0;
LcdDelay(2);
CS2 = 0;
LcdDelay(2);
break;
}
}
void ClearScreen(uchar screen) // screen 0-全屏,1—左屏,2-右屏
{
uchar i,j;
SelectScreen(screen);
for(i = 0;i < 8;i ++)
{
SetLine(i);
SetColum(0);
for(j = 0;j < 64; j ++)
WriteData(0);
}
}
void SetLine(uchar line) //line -> 0 : 7
{
line = line & 0x07;
line = line | 0xb8; //1011 1xxx
SendCommand(line);
}
void SetColum(uchar colum) //colum -> 0 :63
{
colum = colum & 0x3f;
colum = colum | 0x40; //01xx xxxx
SendCommand(colum);
}
void SetStartLine(uchar startline) //startline -> 0 : 63
{
startline = startline & 0x3f;
startline = startline | 0xc0; //11xxxxxx
SendCommand(startline);
}
void SetOnOff(uchar onoff) //1-开显示 0-关
{
if(onoff == 1)
SendCommand(0x3f); //0011 111x
else
SendCommand(0x3e);
}
void ResetLcd()
{
Reset = 0;
LcdDelay(2);
Reset = 1;
LcdDelay(2);
RS0 = 0;
LcdDelay(2);
RS1 = 0;
LcdDelay(2);
SetOnOff(1);
}
void InitLcd()
{
ResetLcd();
SetOnOff(0);
ClearScreen(2);
SetLine(0);
SetColum(0);
SetStartLine(0);
SetOnOff(1);
}
void Show1616(uchar lin,uchar colum,uchar *address)
{
uchar i;
SetLine(lin);
SetColum(colum);
for(i = 0;i < 16;i ++)
WriteData(*(address ++));
SetLine(lin + 1);
SetColum(colum);
for(i = 0;i < 16;i ++)
WriteData(*(address ++));
}
/*******************************************************************************/
/********************************main.c***********************************************/
#include <reg52.h>
#include "main.h"
const uchar code HZ_tab[] = {
0x10,0x21,0x62,0x06,0x82,0xE2,0x22,0x22,
0x22,0xF2,0x22,0x02,0xFE,0x03,0x02,0x00, //河
0x04,0x04,0xFE,0x01,0x00,0x0F,0x04,0x04,
0x04,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00,
0x04,0xE4,0x24,0x24,0x64,0xA4,0x24,0x3F,
0x24,0xA4,0x64,0x24,0x24,0xF6,0x24,0x00, //南
0x00,0xFF,0x00,0x09,0x09,0x09,0x09,0x7F,
0x09,0x09,0x09,0x49,0x80,0x7F,0x00,0x00,
0x24,0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,
0x24,0x48,0x00,0xFF,0x00,0x80,0x00,0x00, //科
0x10,0x08,0x06,0x01,0xFF,0x00,0x01,0x02,
0x02,0x02,0x02,0xFF,0x01,0x01,0x01,0x00,
0x10,0x10,0x10,0xFF,0x10,0x10,0x88,0x88,
0x88,0xFF,0x88,0x88,0x8C,0x08,0x00,0x00, //技
0x04,0x44,0x82,0x7F,0x01,0x80,0x81,0x46,
0x28,0x10,0x28,0x26,0x41,0xC0,0x40,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,
0xA0,0x20,0x20,0x20,0x20,0x30,0x20,0x00, //大
0x00,0x40,0x40,0x20,0x10,0x0C,0x03,0x00,
0x01,0x06,0x08,0x10,0x20,0x60,0x20,0x00,
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,
0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00, //学
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,
0x06,0x05,0x04,0x04,0x04,0x06,0x04,0x00,
0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,
0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00, //电
0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,
0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00,
0x80,0x80,0x82,0x82,0x82,0x82,0x82,0xE2,
0xA2,0x92,0x8A,0x86,0x80,0xC0,0x80,0x00, //子
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x40,0x20,0xF8,0x07,0x24,0x24,0x24,
0x25,0x26,0x24,0x24,0xB4,0x26,0x04,0x00, //信
0x00,0x00,0x00,0xFF,0x00,0x01,0xFD,0x45,
0x45,0x45,0x45,0x45,0xFD,0x01,0x00,0x00,
0x00,0x00,0x00,0xFC,0xA4,0xA6,0xA5,0xA4,
0xA4,0xA4,0xA4,0xFE,0x04,0x00,0x00,0x00, //息
0x40,0x30,0x00,0x77,0x84,0x84,0x8C,0x94,
0xB4,0x84,0x84,0xE7,0x00,0x10,0x60,0x00,
0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,
0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00, //工
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,
0x20,0x20,0x20,0x20,0x20,0x30,0x20,0x00,
0x24,0x24,0xA4,0xFE,0xA3,0x22,0x20,0x7E,
0x42,0x42,0x42,0x42,0x42,0x7F,0x02,0x00, //程
0x08,0x06,0x01,0xFF,0x00,0x43,0x41,0x49,
0x49,0x49,0x7F,0x49,0x4D,0x69,0x41,0x00,
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,
0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00, //学
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,
0x06,0x05,0x04,0x04,0x04,0x06,0x04,0x00,
0x00,0xFE,0x22,0x5A,0x96,0x0C,0x24,0x24,
0x25,0x26,0x24,0x34,0xA4,0x14,0x0C,0x00, // 院
0x00,0xFF,0x04,0x08,0x87,0x81,0x41,0x31,
0x0F,0x01,0x3F,0x41,0x41,0x41,0x70,0x00
};
void main()
{
uchar i,line,colum ;
uchar *address ;
InitLcd();
while(1)
{
colum = 16;
line = 1;
address = HZ_tab;
SetOnOff(0); //关显示
for(i = 1;i < 7;i ++)
{
if(i < 4)
SelectScreen(0);
else
SelectScreen(1);
Show1616(line,colum ,address);
colum += 16;
if(colum >63)
colum = 0;
address += 32; //向DDRAM中写入数据
}
line = 5;
colum = 0;
for(i = 0;i <8; i ++)
{
if(i < 4)
SelectScreen(0);
else
SelectScreen(1);
Show1616(line,colum ,address);
colum += 16;
if(colum >63)
colum = 0;
address += 32;
}
SelectScreen(2);
SetOnOff(1); // 开显示
for(i = 0;i < 50;i ++) //延时
LcdDelay(30000);
}
}
/********************************************************************************/
/*******************************main.h******************************/
#ifndef _MAIN_H
#define _MAIN_H
#include <reg52.h>
#define LcdDataPort P2 //数据端口
#ifndef UCHAR_DEF
#define UCHAR_DEF
typedef unsigned char uchar;
#endif
sbit Reset = P3^0; //复位
sbit RS = P3^1; //指令数据选择
sbit E = P3^2; //指令数据控制
sbit CS1 = P3^4; //左屏幕选择,低电平有效
sbit CS2 = P3^5; //右屏幕选择
sbit RW = P3^3; //读写控制
sbit busy = P2^7; //忙标志
void SetOnOff(uchar onoff); //开关显示
void SelectScreen(uchar screen);//选择屏幕
void ClearScreen(uchar screen); //清屏
void Show1616(uchar lin,uchar colum,uchar *address);//显示一个汉字
void CheckState(); //判断状态
void LcdDelay(unsigned int time); //延时
void WriteData(uchar dat); //写数据
void SendCommand(uchar command); //写指令
void SetLine(uchar line); //置行地址
void SetColum(uchar colum);//置列地址
void SetStartLine(uchar startline);//置显示起始行
void InitLcd(); //初始化
void ResetLcd(); //复位
#endif
/*********************************************************************/
/***********************************lcd.c****************************************/
#include "main.h"
void CheckState()
{
E = 1;
RS = 0;
RW = 1;
LcdDataPort = 0xff;
while(!busy);
}
void LcdDelay(unsigned int time)
{
while(time --);
}
void WriteData(uchar dat)
{
CheckState();
E = 1;
RS = 1;
RW = 0;
LcdDataPort = dat;
E = 0;
}
void SendCommand(uchar command)
{
CheckState();
E = 1;
RW = 0;
RS = 0;
LcdDataPort = command;
E = 0;
}
void SelectScreen(uchar screen) //0-全屏,1—左屏,2-右屏
{
switch(screen)
{
case 0 :
CS1 = 0;
LcdDelay(2);
CS2 = 1;
LcdDelay(2);
break;
case 1 :
CS1 = 1;
LcdDelay(2);
CS2 = 0;
LcdDelay(2);
break;
case 2 :
CS1 = 0;
LcdDelay(2);
CS2 = 0;
LcdDelay(2);
break;
}
}
void ClearScreen(uchar screen) // screen 0-全屏,1—左屏,2-右屏
{
uchar i,j;
SelectScreen(screen);
for(i = 0;i < 8;i ++)
{
SetLine(i);
SetColum(0);
for(j = 0;j < 64; j ++)
WriteData(0);
}
}
void SetLine(uchar line) //line -> 0 : 7
{
line = line & 0x07;
line = line | 0xb8; //1011 1xxx
SendCommand(line);
}
void SetColum(uchar colum) //colum -> 0 :63
{
colum = colum & 0x3f;
colum = colum | 0x40; //01xx xxxx
SendCommand(colum);
}
void SetStartLine(uchar startline) //startline -> 0 : 63
{
startline = startline & 0x3f;
startline = startline | 0xc0; //11xxxxxx
SendCommand(startline);
}
void SetOnOff(uchar onoff) //1-开显示 0-关
{
if(onoff == 1)
SendCommand(0x3f); //0011 111x
else
SendCommand(0x3e);
}
void ResetLcd()
{
Reset = 0;
LcdDelay(2);
Reset = 1;
LcdDelay(2);
RS0 = 0;
LcdDelay(2);
RS1 = 0;
LcdDelay(2);
SetOnOff(1);
}
void InitLcd()
{
ResetLcd();
SetOnOff(0);
ClearScreen(2);
SetLine(0);
SetColum(0);
SetStartLine(0);
SetOnOff(1);
}
void Show1616(uchar lin,uchar colum,uchar *address)
{
uchar i;
SetLine(lin);
SetColum(colum);
for(i = 0;i < 16;i ++)
WriteData(*(address ++));
SetLine(lin + 1);
SetColum(colum);
for(i = 0;i < 16;i ++)
WriteData(*(address ++));
}
/*******************************************************************************/
/********************************main.c***********************************************/
#include <reg52.h>
#include "main.h"
const uchar code HZ_tab[] = {
0x10,0x21,0x62,0x06,0x82,0xE2,0x22,0x22,
0x22,0xF2,0x22,0x02,0xFE,0x03,0x02,0x00, //河
0x04,0x04,0xFE,0x01,0x00,0x0F,0x04,0x04,
0x04,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00,
0x04,0xE4,0x24,0x24,0x64,0xA4,0x24,0x3F,
0x24,0xA4,0x64,0x24,0x24,0xF6,0x24,0x00, //南
0x00,0xFF,0x00,0x09,0x09,0x09,0x09,0x7F,
0x09,0x09,0x09,0x49,0x80,0x7F,0x00,0x00,
0x24,0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,
0x24,0x48,0x00,0xFF,0x00,0x80,0x00,0x00, //科
0x10,0x08,0x06,0x01,0xFF,0x00,0x01,0x02,
0x02,0x02,0x02,0xFF,0x01,0x01,0x01,0x00,
0x10,0x10,0x10,0xFF,0x10,0x10,0x88,0x88,
0x88,0xFF,0x88,0x88,0x8C,0x08,0x00,0x00, //技
0x04,0x44,0x82,0x7F,0x01,0x80,0x81,0x46,
0x28,0x10,0x28,0x26,0x41,0xC0,0x40,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,
0xA0,0x20,0x20,0x20,0x20,0x30,0x20,0x00, //大
0x00,0x40,0x40,0x20,0x10,0x0C,0x03,0x00,
0x01,0x06,0x08,0x10,0x20,0x60,0x20,0x00,
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,
0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00, //学
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,
0x06,0x05,0x04,0x04,0x04,0x06,0x04,0x00,
0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,
0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00, //电
0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,
0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00,
0x80,0x80,0x82,0x82,0x82,0x82,0x82,0xE2,
0xA2,0x92,0x8A,0x86,0x80,0xC0,0x80,0x00, //子
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x40,0x20,0xF8,0x07,0x24,0x24,0x24,
0x25,0x26,0x24,0x24,0xB4,0x26,0x04,0x00, //信
0x00,0x00,0x00,0xFF,0x00,0x01,0xFD,0x45,
0x45,0x45,0x45,0x45,0xFD,0x01,0x00,0x00,
0x00,0x00,0x00,0xFC,0xA4,0xA6,0xA5,0xA4,
0xA4,0xA4,0xA4,0xFE,0x04,0x00,0x00,0x00, //息
0x40,0x30,0x00,0x77,0x84,0x84,0x8C,0x94,
0xB4,0x84,0x84,0xE7,0x00,0x10,0x60,0x00,
0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,
0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00, //工
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,
0x20,0x20,0x20,0x20,0x20,0x30,0x20,0x00,
0x24,0x24,0xA4,0xFE,0xA3,0x22,0x20,0x7E,
0x42,0x42,0x42,0x42,0x42,0x7F,0x02,0x00, //程
0x08,0x06,0x01,0xFF,0x00,0x43,0x41,0x49,
0x49,0x49,0x7F,0x49,0x4D,0x69,0x41,0x00,
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,
0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00, //学
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,
0x06,0x05,0x04,0x04,0x04,0x06,0x04,0x00,
0x00,0xFE,0x22,0x5A,0x96,0x0C,0x24,0x24,
0x25,0x26,0x24,0x34,0xA4,0x14,0x0C,0x00, // 院
0x00,0xFF,0x04,0x08,0x87,0x81,0x41,0x31,
0x0F,0x01,0x3F,0x41,0x41,0x41,0x70,0x00
};
void main()
{
uchar i,line,colum ;
uchar *address ;
InitLcd();
while(1)
{
colum = 16;
line = 1;
address = HZ_tab;
SetOnOff(0); //关显示
for(i = 1;i < 7;i ++)
{
if(i < 4)
SelectScreen(0);
else
SelectScreen(1);
Show1616(line,colum ,address);
colum += 16;
if(colum >63)
colum = 0;
address += 32; //向DDRAM中写入数据
}
line = 5;
colum = 0;
for(i = 0;i <8; i ++)
{
if(i < 4)
SelectScreen(0);
else
SelectScreen(1);
Show1616(line,colum ,address);
colum += 16;
if(colum >63)
colum = 0;
address += 32;
}
SelectScreen(2);
SetOnOff(1); // 开显示
for(i = 0;i < 50;i ++) //延时
LcdDelay(30000);
}
}
/********************************************************************************/
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询