12864液晶按键显示
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "REG51.H"
#include
#define uchar unsigned char
#define lcd P0
sbit K1 = P3^6; //对应按钮K1
sbit K2 = P3^7; //对应按钮K2
sbit cs1 = P2^5; //换位了cs1和cs2
sbit cs2 = P2^4;
sbit rw = P2^1;
sbit rs = P2^0;
sbit e= P2^2;
sbit busy=ACC^7; //按列取,且字符是倒着的,第二排是第一排的,
void Delay10ms(unsigned int c); //延时10ms
unsigned char Key_Scan();
void ClearScreen(unsigned char screen);
uchar code xing[32]={0x10,0x10,0xF0,0x1F,0x10,0xF0,0x40,0x3C,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00,
0x40,0x22,0x15,0x08,0x16,0x21,0x40,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x40,0x00
};
uchar code min[32]={0x00,0x20,0x20,0x10,0x08,0x14,0x67,0x84,0x44,0x24,0x14,0x0C,0x00,0x00,0x00,0x00,
0x04,0x04,0x04,0x02,0xFE,0x43,0x43,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00
};
//uchar code c[32]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
//};
uchar code d[32]={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 code shen[32]={0x10,0x60,0x02,0x8C,0x20,0x18,0x08,0x08,0x88,0x7F,0x88,0x08,0x28,0x18,0x08,0x00,
0x04,0x04,0x7E,0x01,0x80,0x40,0x30,0x0C,0x03,0x00,0x3F,0x40,0x40,0x40,0x70,0x00,
};
uchar code he[32]={0x80,0x44,0x34,0x8F,0xA4,0xC4,0xBC,0x80,0x80,0xBC,0xA4,0xA4,0x24,0x3C,0x00,0x00,
0x00,0x80,0x80,0x5F,0x40,0x20,0x10,0x0E,0x20,0x20,0x40,0x5F,0x80,0x00,0x00,0x00,
};
uchar code sen[32]={0x40,0x44,0x24,0x24,0x94,0x0C,0x04,0x7F,0x04,0x0C,0x94,0x24,0x24,0x44,0x40,0x00,
0x20,0x22,0x12,0x0A,0xFF,0x0A,0x12,0x20,0x12,0x0A,0xFF,0x06,0x0A,0x12,0x20,0x00,
};
uchar code ji[32]={0x08,0xA4,0xA3,0xF2,0xA6,0xAA,0x02,0x0A,0x24,0xF3,0x22,0x26,0xFA,0x22,0x02,0x00,
0x22,0x12,0x0A,0xFF,0x0A,0x32,0x02,0x01,0xFD,0x55,0x55,0x55,0x55,0xFD,0x01,0x00,
};
uchar code guan[32]={0x08,0x08,0x08,0x7F,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x7F,0x08,0x08,0x08,0x00,
0x00,0x80,0x80,0x9F,0x41,0x41,0x21,0x1D,0x01,0x21,0x21,0x5F,0x40,0x80,0x00,0x00,
};
uchar code fu[32]={0x08,0x09,0xCE,0xB8,0x08,0x00,0x02,0x7A,0x4A,0x4A,0x4A,0x4A,0x4A,0x7A,0x02,0x00,
0x02,0x01,0xFF,0x00,0x03,0x00,0xFF,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0xFF,0x00,
};
uchar code jian[32]={0x04,0x84,0xC4,0xB4,0x8C,0x10,0x54,0x54,0x54,0xFF,0x54,0x54,0x7C,0x10,0x10,0x00,
0x80,0x44,0x28,0x18,0x27,0x28,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x48,0x40,0x00,
};
uchar code zhao[32]={0x40,0x40,0x42,0xCC,0x00,0x00,0x82,0x62,0x1E,0x02,0x02,0x42,0x82,0x7E,0x00,0x00,
0x00,0x00,0x00,0x7F,0x20,0x11,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,
};
uchar code an[32]={0x80,0x90,0x8C,0x84,0x84,0x84,0xF5,0x86,0x84,0x84,0x84,0x84,0x94,0x8C,0x80,0x00,
0x00,0x80,0x80,0x84,0x46,0x49,0x28,0x10,0x10,0x2C,0x23,0x40,0x80,0x00,0x00,0x00,
};
uchar code chu[32]={0x00,0x00,0x7C,0x40,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,
0x40,0xFC,0x00,0x00,0x00,
0x00,0x7C,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0xFC,0x00,0x00,
};
uchar code sheng[32]={0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,
};
uchar code ri[32]={0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00,
};
//uchar code qi[32]={0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,
//0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,0x00,0x00,
//};
uchar code one[32]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
};
uchar code nine[32]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
};
uchar code two[32]={0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
};
uchar code nian[32]={0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x04,0x00,0x00,
0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
};
uchar code six[32]={0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
};
uchar code yue[32]={0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,
};
uchar code te[32]={0x40,0x3C,0x10,0xFF,0x10,0x10,0x40,0x48,0x48,0x48,0x7F,0x48,0xC8,0x48,0x40,0x00,
0x02,0x06,0x02,0xFF,0x01,0x01,0x00,0x02,0x0A,0x12,0x42,0x82,0x7F,0x02,0x02,0x00,
};
uchar code chang[32]={0x80,0x80,0x80,0x80,0xFF,0x80,0x80,0xA0,0x90,0x88,0x84,0x82,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0xFF,0x40,0x21,0x12,0x04,0x08,0x10,0x20,0x20,0x40,0x40,0x00,
};
uchar code da[32]={0x10,0x10,0x10,0xFF,0x10,0x90,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,
0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,
};
uchar code lan[32]={0x08,0x04,0xE3,0x02,0x06,0xFA,0x02,0x0A,0xF4,0x43,0xC2,0x46,0x4A,0x42,0x02,0x00,
0x40,0x40,0x7D,0x44,0x44,0x7D,0x44,0x45,0x44,0x7C,0x44,0x45,0x7C,0x40,0x40,0x00,
};
uchar code qiu[32]={0x04,0x84,0x84,0xFC,0x84,0x84,0x10,0x50,0x90,0x10,0xFF,0x90,0x11,0x16,0x90,0x00,
0x20,0x60,0x20,0x1F,0x10,0x10,0x10,0x08,0x45,0x82,0x7F,0x01,0x06,0x09,0x10,0x00,
};
//uchar code lian[32]={0x02,0xFE,0x92,0x92,0xFE,0x02,0x00,0x10,0x11,0x16,0xF0,0x14,0x13,0x10,0x00,0x00,
//0x10,0x1F,0x08,0x08,0xFF,0x04,0x81,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00,
//};
//uchar code xi[32]={0x00,0x00,0x22,0x32,0x2A,0xA6,0xA2,0x62,0x21,0x11,0x09,0x81,0x01,0x00,0x00,0x00,
//0x00,0x42,0x22,0x13,0x0B,0x42,0x82,0x7E,0x02,0x02,0x0A,0x12,0x23,0x46,0x00,0x00,
//};
uchar code dian[32]={0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,
};
uchar code hua[32]={0x40,0x40,0x42,0xCC,0x00,0x00,0x20,0x24,0x24,0x24,0xFE,0x22,0x23,0x22,0x20,0x00,
0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0xFE,0x42,0x42,0x43,0x42,0x42,0xFE,0x00,0x00,
};
uchar code three[32]={0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
};
uchar code five[32]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
};
uchar code four[32]={0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
};
uchar code seven[32]={0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
};
uchar code zero[32]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
};
uchar code eight[32]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
};
void lcd_mwcode(uchar i) //输入控制字,
{
rw=1;
rs=0;
lcd=0;
e=1;
do{ACC=lcd; //是否忙
e=0; }
while(busy);
rw=0;
lcd=i;
e=1;
e=0;
}
void lcd_mwdata(uchar i) //输入数据,
{
rw=1;
rs=0;
lcd=0;
e=1;
do{ACC=lcd;
e=0;}
while(busy);
rw=0;
rs=1;
lcd=i;
e=1;
e=0;}
void setpos(uchar row , uchar col){ //选择行,列,
lcd_mwcode(0xb8+row);
lcd_mwcode(0x40+col);
}
void lcd_init(void) //初始化
{
lcd_mwcode(0xc0);
lcd_mwcode(0x3f);
}
void disp1(uchar code *hz) //显示汉字上半区,
{
uchar i;
for(i=0;i<16;i++)
lcd_mwdata(*(hz+i));
}
void disp3(uchar code *hz) //显示数字上半区,
{
uchar i;
for(i=0;i<8;i++)
lcd_mwdata(*(hz+i));
}
void disp2(uchar code *hz) //显示汉字下半区 ,
{
uchar i;
for(i=16;i<32;i++)
lcd_mwdata(*(hz+i));
}
void disp4(uchar code *hz) //显示数字下半区 ,
{
uchar i;
for(i=8;i<16;i++)
lcd_mwdata(*(hz+i));
}
void select(uchar x)
{ switch(x)
{ case 1:cs1=0;cs2=1;break; //左屏,
case 2:cs1=1;cs2=0;break; //右屏,
case 0:cs1=0;cs2=0;}
}
void main()
{ unsigned char ledValue, keyNum;
ledValue = 0x01;
lcd_init(); //初始化
while (1)
{
keyNum = Key_Scan(); //扫描键盘
if (keyNum == 1) //如果键值返回1
{
ClearScreen(0);
select(1); //选择左屏
setpos(0,10); //姓名
disp1(&xing);
disp1(&min);
//disp1(&c);
setpos(1,10);
disp2(&xing);
disp2(&min);
// disp2(&c);
setpos(2,10); //籍贯
disp1(&ji);
disp1(&guan);
//disp1(&c);
setpos(3,10);
disp2(&ji);
disp2(&guan);
//disp2(&c);
setpos(4,10); //出生
disp1(&chu);
disp1(&sheng);
//disp1(&ri);
//disp1(&qi);
setpos(5,10);
disp2(&chu);
disp2(&sheng);
//disp2(&ri);
//disp2(&qi); //下一页
select(2); //选择右屏
setpos(0,10);
disp1(&shen);
disp1(&he);
disp1(&sen);
setpos(1,10);
disp2(&shen);
disp2(&he);
disp2(&sen);
setpos(2,0);
disp1(&fu);
disp1(&jian);
disp1(&zhao);
disp1(&an);
setpos(3,0);
disp2(&fu);
disp2(&jian);
disp2(&zhao);
disp2(&an);
setpos(4,0);
disp3(&on
e);
disp3(&nine);
disp3(&nine);
disp3(&two);
disp1(&nian);
setpos(5,0);
disp4(&one);
disp4(&nine);
disp4(&nine);
disp4(&two);
disp2(&nian);
setpos(6,0);
disp3(&eight);
disp1(&yue);
disp3(&two);
disp3(&three);
disp1(&ri);
setpos(7,0);
disp4(&eight);
disp2(&yue);
disp4(&two);
disp4(&three);
disp2(&ri); //下一页
}
else if (keyNum == 2)
{
ClearScreen(0);
select(1); //选择左屏
setpos(0,10);
disp1(&te);
disp1(&chang);
//disp1(&c);
setpos(1,10);
disp2(&te);
disp2(&chang);
//disp2(&c);
setpos(2,10);
//disp1(&lian);
//disp1(&xi);
disp1(&dian);
disp1(&hua);
setpos(3,10);
//disp2(&lian);
//disp2(&xi);
disp2(&dian);
disp2(&hua);
select(2); //选择右屏
setpos(0,0);
disp1(&da);
disp1(&lan);
disp1(&qiu);
setpos(1,0);
disp2(&da);
disp2(&lan);
disp2(&qiu);
setpos(2,0);
disp3(&one);
disp3(&seven);
disp3(&eight);
disp3(&zero);
disp3(&five);
disp3(&nine);
disp3(&seven);
disp3(&six);
setpos(3,0);
disp4(&one);
disp4(&seven);
disp4(&eight);
disp4(&zero);
disp4(&five);
disp4(&nine);
disp4(&seven);
disp4(&six);
setpos(4,0);
disp3(&five);
disp3(&six);
disp3(&eight);
setpos(5,0);
disp4(&five);
disp4(&six);
disp4(&eight);
}
}
}
unsigned char Key_Scan()
{
unsigned char keyValue = 0 , i; //保存键值
//--检测按键1--//
if (K1==0) //检测按键K1是否按下
{
Delay10ms(1); //消除抖动
if (K1==0) //再次检测按键是否按下
{
keyValue = 1;
i = 0;
while ((i<50) && (K1==0)) //检测按键是否松开
{
Delay10ms(1);
i++;
}
}
}
//--检测按键2--//
if (K2==0) //检测按键K1是否按下
{
Delay10ms(1); //消除抖动
if (K2==0) //再次检测按键是否按下
{
keyValue = 2;
i = 0;
while ((i<50) && (K2==0)) //检测按键是否松开
{
Delay10ms(1);
i++;
}
}
}
return keyValue; //将读取到键值的值返回
}
void ClearScreen(unsigned char screen)
{ unsigned char i,j;
select(screen);
for(i=0;i<8;i++){
setpos(i, i);
for(j=0;j<8;j++){
disp1(&d);
disp2(&d);
}
}
}
void Delay10ms(unsigned int c) //误差 0us
{
unsigned char a, b;
//--c已经在传递过来的时候已经赋值了,所以在for语句第一句就不用赋值了--//
for (;c>0;c--)
{
for (b=38;b>0;b--)
{
for (a=130;a>0;a--);
}
}
}