5110 超声测距.docx
《5110 超声测距.docx》由会员分享,可在线阅读,更多相关《5110 超声测距.docx(18页珍藏版)》请在冰豆网上搜索。
5110超声测距
诺基亚5110液晶屏(84*48)与超声波测距模块搭配制作的基于51单片机的超声波测距仪
5110(84*48)液晶屏
超声波测距模块
液晶屏显示实拍
当超声模块贴在桌面上阻挡住超声信号反射时,显示距离---cm
顺便秀一下开发板
程序代码如下:
#include"reg51.h"
#defineN20//宽
#defineG24//高
#defineM60//字符十六进制数个数
#include"intrins.h"
#defineucharunsignedchar
#defineuintunsignedint
sbitTT=P2^5;//发射
sbitRR=P2^6;//接收
sbitsce=P2^0;//片选
sbitres=P2^1;//复位,0复位
sbitdc=P2^2;//1写数据,0写指令
sbitsdin=P2^3;//数据
sbitsclk=P2^4;//时钟
voidinit();//初始化
voiddis();//5110显示
voidbyte(uchardt,bitd_c);//写一字节(数据,数据|命令)
voidXY(ucharX,ucharY);//坐标
voidclear();//清屏
voidhan_zi(unsignedcharrow,unsignedcharpage,unsignedcharc);//row:
列page:
页dd:
字符
voiddelayms(unsignedintii);//1ms延时函数
voidshu(unsignedcharrow,unsignedcharpage,unsignedcharc);//row:
列page:
页dd:
字符
ucharss[3];//显示值
voidjs();//计算
uchartimer=0;
bitflag;
ucharcodeshuzi[]={
/*--文字:
0--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0xC0,0xF0,0x08,0x08,0x08,0xF0,0x80,0x00,0x00,0x00,0x1F,0x7F,0x80,0x80,
0x80,0x7F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
1--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x10,0x10,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0xFF,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
2--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x30,0x08,0x08,0x08,0xF8,0xE0,0x00,0x00,0x00,0x00,0xC0,0xE0,0x98,0x8C,
0x83,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
3--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x00,0x10,0x08,0x08,0x98,0x70,0x00,0x00,0x00,0x00,0x80,0xC0,0x82,0x82,
0x83,0x7E,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
4--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x00,0x80,0x60,0x10,0xF8,0x00,0x00,0x00,0x00,0x08,0x0E,0x09,0x08,0x08,
0xFF,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
5--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0xC0,0xB0,0x88,0x88,0x08,0x08,0x00,0x00,0x00,0x00,0x80,0x80,0x81,0x81,
0x43,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
6--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x80,0xE0,0x30,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x7F,0xC2,0x81,0x81,
0x81,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
7--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x18,0x08,0x08,0x08,0xC8,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x1C,
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
8--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0xF0,0x88,0x08,0x08,0x88,0xF0,0x00,0x00,0x00,0x00,0x78,0x85,0x83,0x87,
0x8D,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
9--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0xF0,0x08,0x08,0x08,0x18,0xE0,0x00,0x00,0x00,0x00,0x03,0x84,0x84,0x64,
0x3C,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
---*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
c--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x3C,0xFF,0xC0,0x80,0x80,
0x81,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
m--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x01,0xFF,0x01,0x00,0xFF,0xFF,
0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=10x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=10x24--*/
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,
};
ucharcodehanzi[]={/*--文字:
超--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=20x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=20x24--*/
0x00,0x00,0x00,0x00,0x20,0x21,0xFF,0x9E,0x90,0x80,0x00,0xC8,0x38,0x04,0xC4,0x7C,
0x3C,0x00,0x00,0x00,0x00,0x41,0x61,0x31,0x1D,0x11,0x1F,0x3E,0x64,0x44,0xC1,0x9E,
0x92,0x92,0x92,0x1E,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
/*--文字:
声--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=20x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=20x24--*/
0x00,0x00,0x00,0x00,0x00,0x08,0x48,0x48,0x48,0x49,0x7F,0x24,0x24,0xA4,0x84,0x04,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x7F,0x1F,0x09,0x09,0x09,0x0F,0x09,
0x09,0x0F,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x02,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:
测--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=20x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=20x24--*/
0x00,0x40,0x80,0x0C,0x18,0x00,0xF0,0x10,0x08,0xC8,0x08,0xF8,0x00,0x00,0xE0,0x00,
0x0E,0xFC,0x00,0x00,0x00,0x00,0x61,0x38,0x0E,0x80,0x4F,0x20,0x18,0x1F,0x20,0x6F,
0x00,0x00,0x47,0x80,0xC0,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
/*--文字:
距--*/
/*--楷体15;此字体下对应的点阵为:
宽x高=20x20--*/
/*--高度不是8的倍数,现调整为:
宽度x高度=20x24--*/
0x00,0x00,0x08,0x78,0x48,0xC4,0x44,0x3C,0x00,0x00,0xF8,0x88,0x88,0x4C,0x44,0xC4,
0xC4,0x00,0x00,0x00,0x80,0x80,0xFE,0x40,0x40,0x3F,0x22,0x12,0x12,0x80,0xFF,0x84,
0x84,0xC4,0x44,0x47,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
main()
{TT=0;
RR=0;
init();
clear();
while
(1)
{
while(!
RR);
TR0=1;
while(RR);
TR0=0;
js();
dis();
}
}
voidinit()//初始化
{TMOD=0x11;
TH0=0x00;
TL0=0x00;
TH1=0x3c;
TL1=0xb0;//50ms
TR1=1;
EA=1;
ET1=1;
ET0=1;
res=0;
delayms(10);
res=1;
byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
byte(0xC6,0);//设定液晶偏置电压
byte(0x06,0);//温度校正
byte(0x13,0);;//1:
48
byte(0x20,0);//使用基本指令
byte(0x0C,0);//设定显示模式,正常显示
}
voiddis()//5110显示
{han_zi(0,0,0);
han_zi(1,0,1);
han_zi(2,0,2);
han_zi(3,0,3);
shu(0,1,13);
shu(1,1,ss[2]);
shu(2,1,ss[1]);
shu(3,1,ss[0]);
shu(4,1,13);
shu(5,1,11);
shu(6,1,12);
}
voidbyte(uchardt,bitd_c)//写一字节(数据,数据|命令)
{uchari;
sce=0;
dc=d_c;
for(i=0;i<8;i++)
{if(0x80&dt)
sdin=1;
else
sdin=0;
dt<<=1;
sclk=0;
sclk=1;
}
dc=1;
sce=1;
sdin=1;
}
voidXY(ucharX,ucharY)//坐标
{byte(0x40|Y,0);//column
byte(0x80|X,0);//row
}
voidclear()//清屏
{ucharj,k;
XY(0,0);
for(j=0;j<6;j++)
{for(k=0;k<84;k++)
{byte(0x00,1);
}
}
}
voidhan_zi(unsignedcharrow,unsignedcharpage,unsignedcharc)//row:
列page:
页dd:
字符
{
uchari;
XY(row*N,(G/8)*page);//列,页
for(i=0;i{
byte(hanzi[c*M+i],1);
}
XY(row*N,(G/8)*page+1);//列,页
for(i=N;i<2*N;i++)
{
byte(hanzi[c*M+i],1);
}
XY(row*N,(G/8)*page+2);//列,页
for(i=2*N;i<3*N;i++)
{
byte(hanzi[c*M+i],1);
}
}
voidshu(unsignedcharrow,unsignedcharpage,unsignedcharc)//row:
列page:
页dd:
字符
{
unsignedchari;
XY(row*10,3*page);//列,页
for(i=0;i<10;i++)
{
byte(shuzi[c*30+i],1);
}
XY(row*10,3*page+1);//列,页
for(i=10;i<20;i++)
{
byte(shuzi[c*30+i],1);
}
XY(row*10,3*page+2);//列,页
for(i=20;i<30;i++)
{
byte(shuzi[c*30+i],1);
}
}
voiddelayms(unsignedintii)//1ms延时函数
{
unsignedinti,x;
for(x=0;x{
for(i=0;i<100;i++);
}
}
voidjs()//计算
{uinttime;
unsignedlongs;
time=TH0*256+TL0;
TH0=0x00;
TL0=0x00;
s=(time*1.7)/100;
if((s>800)||flag)
{ss[0]=10;
ss[1]=10;
ss[2]=10;
flag=0;
}
else
{ss[2]=s%1000/100;
ss[1]=s%1000%100/10;
ss[0]=s%1000%10%10;
}
}
voidzd3()interrupt3//T1中断
{
TH1=0x3c;
TL1=0xb0;
timer++;
if(timer>=10)
{
timer=0;
TT=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
TT=0;
}
}
voidTime0()interrupt1
{flag=1;
}