是用点阵式LED还是用LCD的?
这是液晶12864的显示程序
#include <reg51.h>
sbit RS=P2^2; // 数据\指令 选择
sbit RW=P2^1; // 读\写 选择
sbit E=P2^0; // 读\写使能
sbit CS1=P2^4; // 片选1
sbit CS2=P2^3; // 片选2
unsigned int number=0,mstcnt=0; //number 控制显示的字符个数,mstcnt用于延时控制
unsigned char code ziku[]=
{
/* 此方法显示的汉字为下半列排,即先分为上下两半,然后先取上半部分的点阵数据,且点阵对应的数为从下看到上 D7~D0
/*-- 文字: 我 -- 采用下半列排的方式,送数的方式:它是显8*16后接着换下一页显下半8*16
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
/*-- 文字: 欢 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
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,
/*-- 文字: 迎 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
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,
/*-- 文字: 大 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00,
/*-- 文字: 家 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x18,0x04,0x14,0x94,0x94,0xD5,0xB6,0x14,0x14,0x94,0x04,0x14,0x0C,0x04,0x00,
0x00,0x29,0x29,0x15,0x14,0x4A,0x89,0x44,0x3F,0x06,0x09,0x09,0x10,0x30,0x10,0x00,
/*-- 文字: 点 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0xE0,0x20,0x20,0x20,0x3F,0x24,0x24,0x24,0xF4,0x24,0x00,0x00,0x00,
0x00,0x40,0x30,0x07,0x12,0x62,0x02,0x0A,0x12,0x62,0x02,0x0F,0x10,0x60,0x00,0x00,
/*-- 文字: 击 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x80,0x88,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0x88,0xC0,0x80,0x00,
0x00,0x00,0x00,0x7E,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x7E,0x00,0x00,0x00,
/*-- 文字: 我 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x20,0x22,0x22,0xFE,0x21,0x21,0x20,0x20,0xFF,0x20,0x22,0xAC,0x20,0x20,0x00,
0x04,0x04,0x42,0x82,0x7F,0x01,0x01,0x10,0x10,0x08,0x07,0x1A,0x21,0x40,0xF0,0x00,
/*-- 文字: 的 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0xF8,0x8C,0x8B,0x88,0xF8,0x40,0x30,0x8F,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,
0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x03,0x26,0x40,0x20,0x1F,0x00,0x00,
/*-- 文字: 博 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x20,0xFF,0x20,0x20,0x04,0xF4,0x54,0x54,0xFF,0x54,0x55,0xF6,0x04,0x00,0x00,
0x00,0x00,0xFF,0x00,0x04,0x04,0x0F,0x35,0x15,0x47,0x85,0x7F,0x07,0x04,0x04,0x00,
/*-- 文字: 客 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x18,0x04,0x84,0x44,0x7C,0xA5,0x26,0x24,0xA4,0x64,0x24,0x14,0x0C,0x04,0x00,
0x08,0x08,0x05,0x04,0xFC,0x46,0x46,0x45,0x45,0x46,0x46,0xFE,0x04,0x0C,0x04,0x00,
/*-- 文字: 谢 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x42,0xCC,0x04,0x00,0xFC,0x56,0x55,0xFC,0x50,0x90,0x10,0xFF,0x10,0x10,0x00,
0x00,0x00,0x3F,0x50,0x29,0x11,0x4D,0x83,0x7F,0x00,0x41,0x80,0x7F,0x00,0x00,0x00,
/*-- 文字: 谢 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x42,0xCC,0x04,0x00,0xFC,0x56,0x55,0xFC,0x50,0x90,0x10,0xFF,0x10,0x10,0x00,
0x00,0x00,0x3F,0x50,0x29,0x11,0x4D,0x83,0x7F,0x00,0x41,0x80,0x7F,0x00,0x00,0x00,
/*-- 文字: 使 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x20,0xF0,0x1C,0x07,0xF2,0x94,0x94,0x94,0xFF,0x94,0x94,0x94,0xF4,0x04,0x00,
0x00,0x00,0x7F,0x00,0x40,0x41,0x22,0x14,0x0C,0x13,0x10,0x30,0x20,0x61,0x20,0x00,
/*-- 文字: 用 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,
0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,
};
checkstate() //状态检测(检查Busy)
{
unsigned char dat;
RS=0; //表示DB7~DBO为显示指令数据
RW=1; //数据被读到DB7~DBO
do
{
P1=0x00;
E=1; //E信号下降沿锁存DB7~DBO
dat=P1; //读入P1的值
E=0; //锁存
dat=0x80 & dat; //仅当第7位为0时才可操作(判别busy信号)为0时不忙
//BUSY:1内部在工作,0正常状态
}while(!(dat==0x00));
}
void writecommand(unsigned char command) //写命令
{
checkstate(); //检查Busy
RW=0;
P1=command;
E=1;
E=0;
}
void writedate(unsigned char date) //写数据
{
checkstate();
RS=1;
RW=0;
P1=date;
E=1;
E=0;
}
void cleanscreen() //清屏
{
unsigned char page,i;
for(page=0xb8;page<0xc0;page++) //共八页
{
writecommand(page); ///思路基本一样,从第一页写到最后一页
writecommand(0x40); ///数据指针 第一列开始
for(i=0;i<64;i++) ///0~63列
writedate(0x00);
}
}
void choosescreen(unsigned char NO) //选择屏幕 两屏
{
switch (NO)
{
case 0:
CS1=0;
CS2=0;
break; //不选,不显示
case 1:
CS1=0;
CS2=1;
break;
case 2:
CS1=1;
CS2=0;
break;
default:
break;
}
}
void lce_init(void)//初始化
{
writecommand(0xc0); //设置显示起始行
writecommand(0x3f);//显示开关控制
}
void display(unsigned char count) //显示
{
unsigned int i,m,page=0xb8; //0xb8设置设置页地址为第0页
choosescreen(1);
writecommand(0xb8);选择页面
writecommand(0x40);起始列
for(i=0;i<count*16;i++)
{
if(i!=0&&i%16==0)
m++;
switch (i) //控制显示的页指针与列指针
{
case 64: //显示的列累计求和 得所有左右屏四列的开始为 0.64 128.192 256.320 384.448
choosescreen(2); //右屏
writecommand(page); //字的上半部分 此显示方法与直接控制页显示类似,不过改进之处在于可逐字显示
writecommand(0x40); //设置起始列
break;
case 128:
choosescreen(1); //左屏
writecommand(page+2);
writecommand(0x40);
break;
case 192:
choosescreen(2);
writecommand(page+2);
writecommand(0x40);
break;
case 256:
choosescreen(1);
writecommand(page+4);
writecommand(0x40);
break;
case 320:
choosescreen(2);
writecommand(page+4);
writecommand(0x40);
break;
case 384:
choosescreen(1);
writecommand(page+6);
writecommand(0x40);
break;
case 448:
choosescreen(2);
writecommand(page+6);
writecommand(0x40);
break;
default:
break;
}
writedate(*(ziku+i+m*16));
}
choosescreen(1);
page=0xb9;
writecommand(page);
writecommand(0x40);
m=0;
/*
writecmd1(m); //上下循环显示
if(m==0xff)
{
m=0xc0;
}
m++;
writecmd2(n);
if(n==0xff)
{
n=0xc0;
}
n++;
*/
for(i=0;i<count*16;i++)
{
if(i!=0&&i%16==0)
m++;
switch (i) //控制显示的页指针与列指针
{
case 64: //显示的列累计求和
choosescreen(2); //右屏
writecommand(page); //字的下半部分
writecommand(0x40);
break;
case 128:
choosescreen(1); //左屏
writecommand(page+2);
writecommand(0x40);
break;
case 192:
choosescreen(2);
writecommand(page+2);
writecommand(0x40);
break;
case 256:
choosescreen(1);
writecommand(page+4);
writecommand(0x40);
break;
case 320:
choosescreen(2);
writecommand(page+4);
writecommand(0x40);
break;
case 384:
choosescreen(1);
writecommand(page+6);
writecommand(0x40);
break;
case 448:
choosescreen(2);
writecommand(page+6);
writecommand(0x40);
break;
default:
break;
}
writedate(*(ziku+i+m*16+16));
}
m=0;
}
void t0(void) interrupt 1 using 0
{
mstcnt++;
if(mstcnt==2000)
{
mstcnt=0;
number++;
}
}
main()
{
TMOD=0x02;
TH0=0x06; //// 6650us定时中断
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
E=1;
choosescreen(0);
cleanscreen();
lce_init();
while(1)
{
display(number);
if(number==33)
{
number=0;
choosescreen(0);
cleanscreen();
}
}
}
追问LED