B站搜索“逗比小憨憨”
//更多教程:B站搜索“逗比小憨憨”
#include
#include"hz.h"
#define LcdDataPort P1 //数据端口
typedef unsigned char uchar;
sbit E = P2^0; //指令数据控制
sbit RW = P2^1; //读写控制
sbit RS = P2^2; //指令数据选择
sbit CS2 = P2^3; //右屏幕选择
sbit CS1 = P2^4; //左屏幕选择,低电平有效
sbit Reset = P2^5; //复位
sbit busy = P1^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(); //复位
void CheckState(void)
{
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(void)
{
Reset = 0;
LcdDelay(2);
Reset = 1;
LcdDelay(2);
RS0 = 0;
LcdDelay(2);
RS1 = 0;
LcdDelay(2);
SetOnOff(1);
}
void InitLcd(void)
{
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 ++));
}
void main(void)
{
uchar i,line,colum ;
uchar *address ;
InitLcd();
while(1)
{
colum = 16;
line = 0;
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 = 2;
colum = 16;
for(i = 1;i <6; i ++)
{
if(i < 4)
SelectScreen(0);
else
SelectScreen(1);
Show1616(line,colum ,address);
colum += 16;
if(colum >63)
colum = 0;
address += 32;
}
line = 4;
colum = 16;
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;
}
line = 6;
colum = 16;
for(i = 1;i <6; 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);
}
}
// 液(0) 晶(1) 显(2) 示(3) 程(4) 序(5) 逗(6) 比(7) 小(8) 憨(9) 憨(10) 点(11) 赞(12) 投(13) 币(14) 收(15) 藏(16) 记(17) 得(18) 关(19) 注(20) 哟(21)
#ifndef __HZ_H
#define __HZ_H
const unsigned char code HZ_tab[]={
0x10,0x60,0x02,0x8C,0x00,0x84,0xE4,0x1C,0x05,0xC6,0xBC,0x24,0x24,0xE4,0x04,0x00,
0x04,0x04,0x7E,0x01,0x00,0x00,0xFF,0x82,0x41,0x26,0x18,0x29,0x46,0x81,0x80,0x00,/*"液",0*/
0x00,0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,/*"晶",1*/
0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x00,
0x40,0x42,0x44,0x58,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x50,0x48,0x46,0x40,0x00,/*"显",2*/
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xC2,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,
0x20,0x10,0x08,0x06,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x02,0x04,0x08,0x30,0x00,/*"示",3*/
0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x3E,0x22,0x22,0x22,0x22,0x22,0x3E,0x00,0x00,
0x08,0x06,0x01,0xFF,0x01,0x06,0x40,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x41,0x00,/*"程",4*/
0x00,0x00,0xFC,0x04,0x04,0x04,0x14,0x15,0x56,0x94,0x54,0x34,0x14,0x04,0x04,0x00,
0x40,0x30,0x0F,0x00,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x05,0x03,0x00,/*"序",5*/
0x40,0x40,0x42,0xCC,0x00,0x02,0xF2,0x92,0x92,0x92,0x92,0x92,0xF2,0x02,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x48,0x4A,0x4C,0x48,0x48,0x48,0x4C,0x4A,0x48,0x40,0x00,/*"逗",6*/
0x00,0x00,0xFE,0x40,0x40,0x40,0x40,0x00,0xFF,0x80,0x40,0x20,0x10,0x08,0x00,0x00,
0x00,0x00,0x7F,0x20,0x20,0x10,0x10,0x00,0x3F,0x40,0x40,0x40,0x40,0x40,0x78,0x00,/*"比",7*/
0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x20,0x40,0x80,0x00,0x00,
0x08,0x04,0x03,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x01,0x0E,0x00,/*"小",8*/
0x04,0x05,0xFD,0x55,0x55,0x57,0xFC,0x84,0x90,0x08,0x77,0x84,0x64,0x1C,0x04,0x00,
0x01,0x43,0x31,0x01,0x71,0x81,0x87,0x88,0xB4,0x82,0xE1,0x00,0x11,0x62,0x04,0x00,/*"憨",9*/
0x04,0x05,0xFD,0x55,0x55,0x57,0xFC,0x84,0x90,0x08,0x77,0x84,0x64,0x1C,0x04,0x00,
0x01,0x43,0x31,0x01,0x71,0x81,0x87,0x88,0xB4,0x82,0xE1,0x00,0x11,0x62,0x04,0x00,/*"憨",10*/
0x00,0x00,0xC0,0x40,0x40,0x40,0x7F,0x48,0x48,0x48,0x48,0xC8,0x08,0x08,0x00,0x00,
0x80,0x40,0x37,0x04,0x04,0x14,0x64,0x04,0x14,0x64,0x04,0x07,0x10,0xE0,0x00,0x00,/*"点",11*/
0x00,0x98,0x56,0x34,0x1F,0xF4,0x94,0x40,0x98,0x56,0x34,0x1F,0xF4,0x14,0x90,0x00,
0x01,0x00,0x80,0x9E,0x42,0x42,0x22,0x1B,0x22,0x22,0x42,0x5E,0x80,0x01,0x01,0x00,/*"赞",12*/
0x10,0x10,0x10,0xFF,0x10,0x90,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x00,
0x04,0x44,0x82,0x7F,0x01,0x00,0x80,0x80,0x43,0x2C,0x10,0x28,0x44,0x83,0x80,0x00,/*"投",13*/
0x00,0x04,0xE4,0x24,0x24,0x24,0x24,0xFE,0x22,0x22,0x22,0x22,0xE3,0x02,0x00,0x00,
0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x08,0x10,0x0F,0x00,0x00,0x00,/*"币",14*/
0x00,0xFC,0x00,0x00,0xFF,0x00,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,
0x00,0x0F,0x04,0x02,0xFF,0x00,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,/*"收",15*/
0x02,0xE2,0x82,0xF2,0x12,0xD7,0x52,0xD2,0x52,0x17,0xFA,0x12,0x16,0x9A,0x12,0x00,
0x12,0x8E,0x62,0x1F,0x00,0x3F,0x25,0x3D,0xA7,0x40,0x27,0x18,0x26,0x41,0xF0,0x00,/*"藏",16*/
0x40,0x40,0x42,0xCC,0x00,0x00,0x00,0x84,0x84,0x84,0x84,0x84,0xFC,0x00,0x00,0x00,
0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0x3F,0x40,0x40,0x40,0x40,0x41,0x40,0x70,0x00,/*"记",17*/
0x00,0x10,0x88,0xC4,0x33,0x00,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x80,0x00,0x00,
0x02,0x01,0x00,0xFF,0x00,0x02,0x0A,0x12,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x00,/*"得",18*/
0x00,0x00,0x10,0x11,0x16,0x10,0x10,0xF0,0x10,0x10,0x14,0x13,0x10,0x00,0x00,0x00,
0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x41,0x41,0x81,0x81,0x00,/*"关",19*/
0x10,0x60,0x02,0x8C,0x00,0x08,0x08,0x08,0x09,0xFA,0x08,0x08,0x08,0x08,0x00,0x00,
0x04,0x04,0x7E,0x01,0x40,0x40,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,/*"注",20*/
0xFC,0x04,0x04,0xFC,0x20,0x38,0xE7,0x30,0x40,0x30,0x8F,0x08,0x08,0xF8,0x00,0x00,
0x0F,0x04,0x04,0x0F,0x22,0x67,0x22,0x12,0x12,0x00,0x40,0x83,0x40,0x3F,0x00,0x00,/*"哟",21*/
};
#endif