1、5110 超声测距诺基亚5110液晶屏(84*48)与超声波测距模块搭配制作的基于51单片机的超声波测距仪5110(84*48)液晶屏超声波测距模块液晶屏显示实拍当超声模块贴在桌面上阻挡住超声信号反射时,显示距离-cm顺便秀一下开发板程序代码如下:#include reg51.h#define N 20 /宽#define G 24 /高#define M 60 /字符十六进制数个数#include intrins.h#define uchar unsigned char#define uint unsigned intsbit TT=P25; /发射sbit RR=P26; /接收sbit
2、sce = P20; /片选sbit res = P21; /复位,0复位sbit dc = P22; /1写数据,0写指令sbit sdin = P23; /数据sbit sclk = P24; /时钟void init(); /初始化void dis(); /5110显示void byte(uchar dt,bit d_c); /写一字节 (数据,数据|命令)void XY(uchar X,uchar Y); /坐标void clear(); /清屏void han_zi(unsigned char row, unsigned char page,unsigned char c); /ro
3、w:列 page:页 dd:字符void delayms(unsigned int ii);/1ms延时函数void shu(unsigned char row, unsigned char page,unsigned char c); /row:列 page:页 dd:字符uchar ss3; /显示值void js(); /计算uchar timer=0;bit flag;uchar code shuzi=/*- 文字: 0 -*/*- 楷体15; 此字体下对应的点阵为:宽x高=10x20 -*/*- 高度不是8的倍数,现调整为:宽度x高度=10x24 -*/0x00,0x00,0xC0,
4、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,0x
5、00,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
6、 -*/*- 楷体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 -*/0x0
7、0,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,
8、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,0x
9、00,/*- 文字: 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高度=
10、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,0x0
11、3,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,
12、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的倍数
13、,现调整为:宽度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,0x0
14、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,;uchar code hanzi=/*- 文字: 超 -*/*- 楷体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,0x
15、41,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
16、,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; 此字体下对应的
17、点阵为:宽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,0
18、x00,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,0x4
19、4,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(); void init() /初始化 TMOD=0x11; TH0=0x00; TL0=0x00; TH1=0x3c; TL1=0xb0; /50ms TR
20、1=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);/设定显示模式,正常显示 void dis() /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,ss2); shu
21、(2,1,ss1); shu(3,1,ss0); shu(4,1,13); shu(5,1,11); shu(6,1,12); void byte(uchar dt,bit d_c) /写一字节 (数据,数据|命令) uchar i; sce=0; dc=d_c; for(i=0;i8;i+) if(0x80&dt) sdin=1; else sdin=0; dt=1; sclk=0; sclk=1; dc=1; sce=1; sdin=1;void XY(uchar X,uchar Y) /坐标 byte(0x40 | Y, 0);/ column byte(0x80 | X, 0);/ r
22、owvoid clear() /清屏 uchar j,k; XY(0,0); for(j=0;j6;j+) for(k=0;k84;k+) byte(0x00,1); void han_zi(unsigned char row, unsigned char page,unsigned char c) /row:列 page:页 dd:字符 uchar i; XY(row*N, (G/8)*page);/ 列,页 for(i=0; iN;i+) byte(hanzic*M+i,1); XY(row*N, (G/8)*page+1);/ 列,页 for(i=N; i2*N;i+) byte(han
23、zic*M+i,1); XY(row*N, (G/8)*page+2);/ 列,页 for(i=2*N; i3*N;i+) byte(hanzic*M+i,1); void shu(unsigned char row, unsigned char page,unsigned char c) /row:列 page:页 dd:字符 unsigned char i; XY(row*10, 3*page);/ 列,页 for(i=0; i10;i+) byte(shuzic*30+i,1); XY(row*10, 3*page+1);/ 列,页 for(i=10; i20;i+) byte(shuz
24、ic*30+i,1); XY(row*10, 3*page+2);/ 列,页 for(i=20; i30;i+) byte(shuzic*30+i,1); void delayms(unsigned int ii)/1ms延时函数 unsigned int i,x; for (x=0;xii;x+) for (i=0;i800)|flag) ss0=10; ss1=10; ss2=10; flag=0; else ss2=s%1000/100; ss1=s%1000%100/10; ss0=s%1000%10%10; void zd3()interrupt 3 /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; void Time0()interrupt 1 flag=1;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1