仿真图:
(附文件)
程序源码:
#include<reg51.h>
#include<intrins.h>
sbit E=P3^0;
sbit RW=P3^1;
sbit DI=P3^2;
sbit CS2=P3^3;
sbit CS1=P3^4;
#define uchar unsigned char
#define uint unsigned int
unsigned char cons,cont;
//uchar code
//l[]=
//{0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0xF0,0x10,0x11,0x16,0xD0,0x10,0x10,
//0x00,0x80,0x40,0x20,0x18,0x06,0x41,0x20,0x10,0x3F,0x44,0x42,0x41,0x40,0x40,0x78},
//c[]=
//{0x00,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},
//dian[]=
//{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},
//qi[]=
//{0x20,0x10,0x4C,0x47,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0xD4,0x04,0x04,0x00,0x00,
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00},
//ban[]=
//{0x84,0x84,0xFC,0x84,0x84,0x00,0xF8,0x00,0xFF,0x00,0x84,0x84,0xFC,0x84,0x84,0x00,
//0x10,0x30,0x1F,0x08,0x88,0x42,0x21,0x18,0x07,0x00,0x20,0x20,0x3F,0x20,0x20,0x00};
uchar code
shuzi[16][32]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"0",0*/
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"1",1*/
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"2",2*/
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"3",3*/
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"4",4*/
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"5",5*/
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"6",6*/
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"7",7*/
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"8",8*/
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"9",9*/
{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"a",
0*/
{0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"b",
1*/
{0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"c",
2*/
{0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"d",
3*/
{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"e",
4*/
{0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};/*"f"
,5*/
unsigned char i;
void delay(uint x)//ÑÓʱ
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void keycan(void)
{
for(i=0;i<4;i++)
switch(i)
{
case 0:
P1=0x7f;
delay(5);
switch(P1|0xf0)
{
case 0xfe:cont=0;break;
case 0xfd:cont=1;break;
case 0xfb:cont=2;break;
case 0xf7:cont=3;break;
default:break;
}
case 1:
P1=0xbf;
delay(5);
switch(P1|0xf0)
{
case 0xfe:cont=4;break;
case 0xfd:cont=5;break;
case 0xfb:cont=6;break;
case 0xf7:cont=7;break;
default:break;
}
case 2:
P1=0xdf;
delay(5);
switch(P1|0xf0)
{
case 0xfe:cont=8;break;
case 0xfd:cont=9;break;
case 0xfb:cont=10;break;
case 0xf7:cont=11;break;
default:break;
}
case 3:
P1=0xef;
delay(5);
switch(P1|0xf0)
{
case 0xfe:cont=12;break;
case 0xfd:cont=13;break;
case 0xfb:cont=14;break;
case 0xf7:cont=15;break;
default:break;
}
default:break;
}
} void readbusy(void) /* ÅжÏ×î¸ßλÊÇ·ñΪ 1£¬Îª 0 ²Å¶ÁдÊý¾Ý */
{
P0=0x00;
cons=P0;
DI=0;
RW=1;
E=1;
while(cons&0x80);
E=0;
}
void Select(uchar i)
{
switch(i)
{
case 0:CS1=0;CS2=0;break;
case 1:CS1=0;CS2=1;break;
case 2:CS1=1;CS2=0;break;
default:break;
}
}
void xieminling(uchar value)
{
readbusy();/* ÿ´Î¶Áд¶¼ÒªÃ¦ÅÐ¶Ï */
DI=0;
RW=0;
P0=value;
E=1;
_nop_();
_nop_();
E=0;
}
void Setonoff(uchar onoff)
{
onoff=0x3e|onoff;
xieminling(onoff);
}
void xieshuju(uchar dat)
{
readbusy();
DI=1;
RW=0;
P0=dat;
E=1;
_nop_();
_nop_();
E=0;
}
void Setpage(uchar page)/* ÉèÖÃÒ³ */
{
page=0xb8|page;
xieminling(page);
}
void Setline(uchar line) /* ÉèÖÃÁÐ */
{
line=0x40|line;
xieminling(line);
}
void qingping(uchar screen) /* ÇåÆÁ*/
{
uchar i,j;
Select(screen);
for(i=0;i<8;i++)
{
Setline(0);
Setpage(i);
for(j=0;j<64;j++)
{
xieshuju(0x00);
}
}
}
void chushihua(void)
{
Select(0);
Setonoff(0);
Select(0);
Setonoff(1);
Select(0);
qingping(0);
}
void xianshi(uchar ss,uchar lie,uchar page1,uchar *p)
{
uchar i;
Select(ss);
Setpage(page1);
Setline(lie);
for(i=0;i<16;i++)
{
xieshuju(p[i]);
}
Setpage(page1+1);
Setline(lie);
for(i=0;i<16;i++)
{xieshuju(p[i+16]);
}
}
void main()
{
//xianshi(2,0,2,l);
//xianshi(2,16*2,2,c);
//xianshi(1,0,2,dian);
//xianshi(1,16,2,qi);
//xianshi(1,16*2,2,shuzi[1]);
//xianshi(1,16*3,2,ban);
//xianshi(2,0,4,shuzi[2]);
//xianshi(2,8,4,shuzi[0]);
//xianshi(2,16,4,shuzi[1]);
//xianshi(2,16+8,4,shuzi[1]);
//xianshi(2,16*2,4,shuzi[0]);
//xianshi(2,16*2+8,4,shuzi[2]);
//xianshi(2,16*3,4,shuzi[4]);
//xianshi(1,0,4,shuzi[1]);
//xianshi(1,8,4,shuzi[0]);
//xianshi(1,8+8,4,shuzi[9]);
while(1)
{
chushihua();
keycan();
xianshi(2,0,0,shuzi[cont]);
delay();
}
}
.
链接:https://pan.baidu.com/s/1_zz0vTJlj3Le0yGRxVwBUA
提取码:41iu
.
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/38872.html