📄 fm12864.c
字号:
#include <absacc.h>
#include <intrins.h>
#include <reg51.h>
// LCD128*64 数据线
#define LCD12864DataPort P2
#define uchar unsigned char
#define uint unsigned char
// LCD128*64 I/O 信号管脚
sbit di = P1^0; // 数据\指令 选择
sbit rw = P1^2; // 读\写 选择
sbit en = P1^1; // 读\写使能
sbit cs1= P1^3; // 片选1,低有效(前64列)
sbit cs2= P1^4; // 片选2,低有效(后64列)
uchar time0_count; //time0计数器
uchar j=0;
char code HZcode[25][32]={
//长
{
0x80, 0x80, 0x80, 0x80, 0xff, 0xa0, 0xa0, 0x90, 0x90, 0x88, 0x84, 0x82, 0x80, 0x80, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x40, 0x21, 0x12, 0x04, 0x08, 0x10, 0x30, 0x60, 0x20, 0x00, 0x00,
},
//沙
{
0x00, 0x10, 0x21, 0x86, 0x60, 0x80, 0x60, 0x18, 0x00, 0xff, 0x00, 0x08, 0x10, 0x20, 0x40, 0x00,
0x04, 0x04, 0xfe, 0x01, 0x80, 0x80, 0x40, 0x40, 0x20, 0x23, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00,
},
//元
{
0x00, 0x20, 0x20, 0x22, 0x22, 0xe2, 0x22, 0x22, 0x22, 0xe2, 0x22, 0x22, 0x22, 0x20, 0x20, 0x00,
0x00, 0x40, 0x20, 0x10, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x3f, 0x40, 0x40, 0x40, 0x40, 0x70, 0x00,
},
{
0x08, 0x08, 0x08, 0x08, 0x08, 0xc8, 0x38, 0xff, 0x18, 0x68, 0x88, 0x08, 0x08, 0x08, 0x08, 0x00,
0x08, 0x08, 0x04, 0x02, 0x05, 0x04, 0x04, 0x7f, 0x04, 0x04, 0x04, 0x03, 0x06, 0x0c, 0x04, 0x00,
},
//科
{
0x10, 0x12, 0x92, 0x72, 0xfe, 0x51, 0x91, 0x00, 0x22, 0xcc, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x04, 0x02, 0x01, 0x00, 0xff, 0x00, 0x04, 0x04, 0x04, 0x02, 0x02, 0x02, 0xff, 0x01, 0x01, 0x00,
},
//技
{
0x08, 0x08, 0x88, 0xff, 0x48, 0x28, 0x00, 0xc8, 0x48, 0x48, 0x7f, 0x48, 0xc8, 0x48, 0x08, 0x00,
0x01, 0x41, 0x80, 0x7f, 0x00, 0x40, 0x40, 0x20, 0x13, 0x0c, 0x0c, 0x12, 0x21, 0x60, 0x20, 0x00,
},
//欢
{
0x14, 0x24, 0x44, 0x84, 0x64, 0x1c, 0x20, 0x18, 0x0f, 0xe8, 0x08, 0x08, 0x28, 0x18, 0x08, 0x00,
0x20, 0x10, 0x4c, 0x43, 0x43, 0x2c, 0x20, 0x10, 0x0c, 0x03, 0x06, 0x18, 0x30, 0x60, 0x20, 0x00,
},
//迎
{
0x40, 0x41, 0xce, 0x04, 0x00, 0xfc, 0x04, 0x02, 0x02, 0xfc, 0x04, 0x04, 0x04, 0xfc, 0x00, 0x00,
0x40, 0x20, 0x1f, 0x20, 0x40, 0x47, 0x42, 0x41, 0x40, 0x5f, 0x40, 0x42, 0x44, 0x43, 0x40, 0x00,
},
//你
{
0x80, 0x40, 0xf0, 0x2c, 0x43, 0x20, 0x98, 0x0f, 0x0a, 0xe8, 0x08, 0x88, 0x28, 0x1c, 0x08, 0x00,
0x00, 0x00, 0x7f, 0x00, 0x10, 0x0c, 0x03, 0x21, 0x40, 0x3f, 0x00, 0x00, 0x03, 0x1c, 0x08, 0x00,
},
//!
{
0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
//电
{
0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0x48, 0xff, 0x48, 0x48, 0x48, 0x48, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, 0x04, 0x04, 0x04, 0x04, 0x3f, 0x44, 0x44, 0x44, 0x44, 0x4f, 0x40, 0x70, 0x00,
},
//话
{
0x40, 0x41, 0x4e, 0xc4, 0x00, 0x20, 0x24, 0x24, 0x24, 0x24, 0xfc, 0x22, 0x22, 0x22, 0x20, 0x00,
0x00, 0x00, 0x00, 0x7f, 0x20, 0x10, 0x00, 0x7e, 0x22, 0x22, 0x23, 0x22, 0x22, 0x7e, 0x00, 0x00,
},
//作
{
0x80, 0x40, 0x20, 0xf8, 0x07, 0x22, 0x18, 0x0c, 0xfb, 0x48, 0x48, 0x48, 0x68, 0x48, 0x08, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x04, 0x04, 0x04, 0x04, 0x06, 0x04, 0x00,
},
//者
{
0x00, 0x20, 0x24, 0x24, 0x24, 0x24, 0xa4, 0xbf, 0x64, 0x24, 0x34, 0x28, 0x26, 0x24, 0x20, 0x00,
0x04, 0x04, 0x04, 0x02, 0x02, 0xff, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0xff, 0x00, 0x00, 0x00,
},
//杨
{
0x08, 0x08, 0xc8, 0xff, 0x48, 0x88, 0x0a, 0x42, 0x62, 0xd2, 0x4a, 0xc6, 0x42, 0xc0, 0x00, 0x00,
0x04, 0x03, 0x00, 0xff, 0x00, 0x01, 0x08, 0x24, 0x13, 0x08, 0x06, 0x41, 0x80, 0x7f, 0x00, 0x00,
},
//恢
{
0x70, 0x00, 0xff, 0x08, 0x30, 0x08, 0xc8, 0xbf, 0x08, 0xf8, 0x08, 0x08, 0xc8, 0x08, 0x08, 0x00,
0x00, 0x00, 0xff, 0x10, 0x48, 0x46, 0x21, 0x20, 0x19, 0x07, 0x06, 0x09, 0x30, 0x60, 0x20, 0x00,
},
//清
{
0x10, 0x61, 0x06, 0xe0, 0x18, 0x20, 0xaa, 0xaa, 0xaa, 0xbf, 0xaa, 0xaa, 0xaa, 0x2a, 0x00, 0x00,
0x04, 0x04, 0xff, 0x00, 0x00, 0x00, 0xff, 0x0a, 0x0a, 0x0a, 0x4a, 0x8a, 0x7f, 0x00, 0x00, 0x00,
},
{0xFE,0x02,0x32,0x4E,0x82,0x00,0xFE,0x4A,0xCA,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0xFF,0x00,0x02,0x04,0x03,0x00,0xFF,0x40,0x20,0x03,0x0C,0x12,0x21,0x60,0x20,0x00},
{0x00,0x00,0x80,0x40,0x30,0x0E,0x84,0x00,0x00,0x0E,0x10,0x60,0xC0,0x80,0x80,0x00,0x00,0x01,0x20,0x70,0x28,0x24,0x23,0x31,0x10,0x10,0x14,0x78,0x30,0x01,0x00,0x00},
{0x00,0x10,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x20,0x40,0x3F,0x00,0x00},
{0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00,0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00},
{0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00},
{0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00},
{0x80,0x40,0x20,0x98,0x87,0x82,0x80,0x80,0x83,0x84,0x98,0x30,0x60,0xC0,0x40,0x00,0x00,0x80,0x40,0x20,0x10,0x0F,0x00,0x00,0x20,0x40,0x3F,0x00,0x00,0x00,0x00,0x00}
};
char code Numcode[25][16]={{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},
{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},
/*w CHAR_77 */
{0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00},
/*: CHAR_3A */
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},
/*b CHAR_62 */
{0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00},
/*l CHAR_6C */
{0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
/*u CHAR_75 */
{0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20},
/*e CHAR_65 */
{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00},
/*s CHAR_73 */
{0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00},
/*t CHAR_74 */
{0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00},
/*d CHAR_64 */
{0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20},
/*c CHAR_63 */
{0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00},
/*o CHAR_6F */
{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},
/*m CHAR_6D */
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F},
{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},
};
void nop(void)
{
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
}
//状态检查
void CheckState(void)
{
uchar dat;
dat = 0x00;
di=0;
rw=1;
/*
do
{
P1=0xff;
en=1;
dat=P1;
en=0;
dat&=0x80; //仅当第7位为0时才可操作
}while(dat);*/
}
//写显示数据
//dat:显示数据
void WriteByte(uchar dat)
{
CheckState();
di=1;
rw=0;
LCD12864DataPort=dat;
en=1;
en=0;
}
/*-----------------------------------------------------------------------------------------------------*/
//向LCD发送命令
//command :命令
SendCommandToLCD(uchar command)
{
CheckState();
rw=0;
di=0;
LCD12864DataPort=command;
en=1;
en=0;
}
/*----------------------------------------------------------------------------------------------------*/
//设定行地址(页)--X 0-7
void SetLine(uchar line)
{
line &= 0x07; // 0<=line<=7
line |= 0xb8; //1011 1xxx
SendCommandToLCD(line);
}
//设定列地址--Y 0-63
void SetColumn(uchar column)
{
column &= 0x3f; // 0=<column<=63
column |= 0x40; //01xx xxxx
SendCommandToLCD(column);
}
//设定显示开始行--XX
void SetStartLine(uchar startline) //0--63
{
//startline &= 0x07;
startline |= 0xc0; //1100 0000
SendCommandToLCD(startline);
}
//开关显示
void SetOnOff(uchar onoff)
{
onoff|=0x3e; //0011 111x
SendCommandToLCD(onoff);
}
/*---------------------------------------------------------------------------------------------------*/
//选择屏幕
//screen: 0-全屏,1-左屏,2-右屏
void SelectScreen(uchar screen)
{ //北京显示器:负有效 cs1: 0--右; cs2: 0--左
switch(screen)
{
case 0:
cs1=0;//全屏
nop();
cs2=0;
nop();
break;
case 1:
cs1=1;//左屏
nop();
cs2=0;
nop();
break;
case 2:
cs1=0;//右屏
nop();
cs2=1;
nop();
break;
default:
break;
}
}
/*---------------------------------------------------------------------------------------------------*/
//清屏
//screen: 0-全屏,1-左屏,2-右
void ClearScreen(uchar screen)
{
uchar i,j;
SelectScreen(screen);
for(i=0;i<8;i++)
{
SetLine(i);
for(j=0;j<64;j++)
{
WriteByte(0x00);
}
}
}
/*--------------------------------------------------------------------------------------------------*/
//显示8*8点阵
//lin:行(0-7), column: 列(0-127)
//address : 字模区首地址
void Show8x8(uchar lin,uchar column,uchar *address)
{
uchar i;
// if(column>128) {return;}
if(column<64)
{
SelectScreen(2); //如果列数<64则从第2屏上开始写
SetLine(lin);
SetColumn(column);
for(i=0;i<8;i++)
{
if(column+i<64)
{
WriteByte(*(address+i));
}
else
{
SelectScreen(1);
SetLine(lin);
SetColumn(column-64+i);
WriteByte(*(address+i));
}
}
}
else
{
SelectScreen(1); //否则从第2屏上开始写
column-=64; //防止越界
SetLine(lin);
SetColumn(column);
for(i=0;i<8;i++)
{
if(column+i<64)
{
WriteByte(*(address+i));
}
else
{
SelectScreen(2);
SetLine(lin);
SetColumn(column-64+i);
WriteByte(*(address+i));
}
}
}
}
//显示数字8*16
void ShowNumber(uchar lin,uchar column,uchar num)
{
uchar *address;
address=&Numcode[num][0];
Show8x8(lin,column,address);
Show8x8(lin+1,column,address+8);
}
//显示汉字16*16
void ShowChina(uchar lin,uchar column,uchar num)
{
uchar *address;
// if(lin>7 || column>127){return;}
address = &HZcode[num][0];
Show8x8(lin,column,address);
Show8x8(lin,column+8,address+8);
Show8x8(lin+1,column,address+16);
Show8x8(lin+1,column+8,address+24);
}
void InitLCD(void) //初始化LCD
{
uchar i=2000; //延时
while(i--);
SetOnOff(1); //开显示
ClearScreen(1);//清屏
ClearScreen(2);
SetStartLine(0); //开始行:0
}
//time0初始化
void time0_init(void)
{
EA = 1;
ET0 = 1;
TMOD = 0x01;
PT0 = 1;
TH0 = 0x3C;
TL0 = 0xB0;
TR0 = 1;
}
void time0_interrupt(void)interrupt 1
{
TH0 = 0x3c;
TL0 = 0xb0;
time0_count++;
if(time0_count==40)
{
time0_count=0;
j=j-2;
SetOnOff(1); //开显示
ClearScreen(1);//清屏
ClearScreen(2);
SetStartLine(0); //开始行:0
ShowChina(j,0,0);
ShowChina(j,22,1);
ShowChina(j,44,2);
ShowChina(j,66,3);
ShowChina(j,86,4);
ShowChina(j,108,5);
ShowChina(j+18,26,6);
ShowChina(j+18,46,7);
ShowChina(j+18,66,8);
ShowChina(j+18,86,9);
ShowChina(j+36,0,10);
ShowChina(j+36,18,11);
ShowNumber(j+36,36,0);
ShowNumber(j+36,44,7);
ShowNumber(j+36,50,3);
ShowNumber(j+36,58,1);
ShowNumber(j+36,66,4);
ShowNumber(j+36,74,1);
ShowNumber(j+36,82,9);
ShowNumber(j+36,90,7);
ShowNumber(j+36,98,4);
ShowNumber(j+36,106,8);
ShowNumber(j+36,114,8);
// ShowNumber(j+36,122,8);
ShowNumber(j+54,0,11);
ShowNumber(j+54,8,11);
ShowNumber(j+54,16,11);
ShowNumber(j+54,24,12);
ShowNumber(j+54,32,13);
ShowNumber(j+54,40,14);
ShowNumber(j+54,48,15);
ShowNumber(j+54,56,16);
ShowNumber(j+54,64,17);
ShowNumber(j+54,72,18);
ShowNumber(j+54,80,19);
ShowNumber(j+54,88,12);
ShowNumber(j+54,96,20);
ShowNumber(j+54,104,21);
ShowNumber(j+54,112,22);
// ShowChina(j+72,0,12);
// ShowChina(j+72,20,13);
// ShowChina(j+72,50,14);
// ShowChina(j+72,70,15);
// ShowChina(j+72,90,16);
}
}
void main(void)
{
InitLCD();
time0_init();
while(1)
{
;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -