nokia5110液晶显示温度程序.doc_第1页
nokia5110液晶显示温度程序.doc_第2页
nokia5110液晶显示温度程序.doc_第3页
nokia5110液晶显示温度程序.doc_第4页
nokia5110液晶显示温度程序.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

温度显示程序:#include#define uchar unsigned char#define uint unsigned intsbit ds=P34;uint temp;float f_temp;sbit sce = P13; /片选sbit res = P14; /复位,0复位sbit dc = P12; /1写数据,0写指令sbit sdin = P11; /数据sbit sclk = P10; /时钟unsigned char code shuzi=/00xF8,0x04,0x04,0x04,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,/10x00,0x08,0xFC,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,/0x18,0x84,0x44,0x44,0x38,0x00,0x03,0x02,0x02,0x02,0x02,0x00,/30x88,0x04,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,/40xC0,0xB0,0x88,0xFC,0x80,0x00,0x00,0x00,0x00,0x03,0x00,0x00,/50x3C,0x14,0x14,0x14,0xE4,0x00,0x01,0x02,0x02,0x02,0x01,0x00,/60xF8,0x24,0x24,0x24,0xC8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,/70x04,0x04,0x04,0xE4,0x1C,0x00,0x00,0x00,0x03,0x00,0x00,0x00,/80xD8,0x24,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,/90x38,0x44,0x44,0x44,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,/0x00,0x00,0x04,0x0A,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/C0xF8,0x04,0x04,0x04,0x98,0x00,0x01,0x02,0x02,0x02,0x01,0x00,/.0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,/:0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,/T0x04,0x04,0xFC,0x04,0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00;unsigned char code hanzi=0x22,0x44,0x00,0xC0,0x5F,0xD5,0x55,0xD5,0x5F,0xC0,0x00,0x00,0x04,0x02,0x09,0x0F,0x08,0x0F,0x08,0x0F,0x08,0x0F,0x08,0x00,/*温,0*/0x00,0xFE,0x0A,0x8A,0xBE,0xAA,0xAB,0xAA,0xBE,0x8A,0x0A,0x00,0x08,0x07,0x00,0x08,0x09,0x0A,0x04,0x04,0x0A,0x09,0x08,0x00,/*度,1*/0x11,0x22,0x80,0x3E,0x2A,0xEA,0x2A,0xEA,0x2A,0x3E,0x80,0x00,0x04,0x02,0x08,0x09,0x08,0x0F,0x08,0x0F,0x08,0x09,0x08,0x00,/*湿,2*/0x00,0xFE,0x0A,0x8A,0xBE,0xAA,0xAB,0xAA,0xBE,0x8A,0x0A,0x00,0x08,0x07,0x00,0x08,0x09,0x0A,0x04,0x04,0x0A,0x09,0x08,0x00,/*度,3*/0x20,0x22,0x24,0xE8,0x20,0x3F,0x20,0xE8,0x24,0x22,0x20,0x00,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x07,0x08,0x08,0x0E,0x00,/*光,4*/0xF2,0x92,0x9E,0x00,0xE0,0x2F,0x29,0xF9,0x29,0x2F,0xE0,0x00,0x08,0x08,0x07,0x00,0x09,0x09,0x09,0x0F,0x09,0x0D,0x09,0x00,/*强,5*/;void delayus(uint z) /微妙级延时uint y;for(y=z;y0;y-);void delayms(uint z) /毫秒级延时uint x,y;for(y=z;y0;y-) for(x=1400;x0;x-);void LCD_write_byte(unsigned char dt, unsigned char command) /写字节unsigned char i;sce=0; /5110片选有效,允许输入数据dc=command; /0写指令,1写数据for(i=0;i8;i+) /传送8bit数据 if(dt&0x80) sdin=1; else sdin=0; dt=dt1; sclk=0; sclk=1; dc=1; sce=1; /禁止5110sdin=1;void LCD_init(void) /初始化(command=0,写指令) res=0; delayms(1); res=1; LCD_write_byte(0x21,0);/初始化Lcd,功能设定使用扩充指令 LCD_write_byte(0xa7,0);/设定液晶偏置电压(5v),5110接5V时偏置电压改为(0xa7,0),接3.3V时改为(0xc0,0) LCD_write_byte(0x20,0);/使用基本指令 LCD_write_byte(0x0C,0);/设定显示模式,正常显示 void LCD_set_XY(unsigned char X, unsigned char Y) /设置LCD坐标,X:0-83 Y:0-5LCD_write_byte(0x40 | Y, 0);/ column /列LCD_write_byte(0x80 | X, 0);/ row /行void LCD_clear(void) /LCD清屏函数 unsigned char t; unsigned char k; LCD_set_XY(0,0); /设置RAM起始地址 for(t=0;t6;t+) for(k=0;k84;k+) LCD_write_byte(0x00,1); /写数据 void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) /row:列 page:页 dd:字符,page范围为0-5, unsigned char i; LCD_set_XY(row*6, page);/ 列,页 for(i=0; i6;i+) LCD_write_byte(shuzic*12+i,1); LCD_set_XY(row*6, page+1);/ 列,页 for(i=6; i12;i+) LCD_write_byte(shuzic*12+i,1); void LCD_write_zi(unsigned char row, unsigned char page,unsigned char c) unsigned char i; LCD_set_XY(row*6, page);/ 列,页 for(i=0; i12;i+) LCD_write_byte(hanzic*24+i,1); LCD_set_XY(row*6, page+1);/ 列,页 for(i=12; i24;i+) LCD_write_byte(hanzic*24+i,1); void dsreset(void) /温度初始化函数 ds=0; delayus(103); ds=1; delayus(4);bit tempreadbit(void) /读取一个字节的温度 bit dat; ds=0; delayus(1); ds=1; delayus(2); dat=ds; delayus(8); return(dat); uchar tempread(void) /8字节读取 uchar i,j,dat; dat=0; for(i=1;i=8;i+) j=tempreadbit(); dat=(j1); return(dat);void tempwritebyte(uchar dat) /8字节写温度 uchar j; bit testb; for(j=1;j1; /右移 if(testb) ds=0; delayus(2); ds=1; delayus(8); else ds=0; delayus(8); ds=1; delayus(2); void tempchange(void) dsreset(); /温度复位 delayms(1); tempwritebyte(0xcc); / 跳过读序号列号的操作 tempwritebyte(0x44); /启动温度转换 uint get_temp() /获取温度函数 uchar a,b; dsreset(); /温度复位 delayms(1); tempwritebyte(0xcc); tempwritebyte(0xbe); /读取温度寄存器 a=tempread(); /读低八位 b=tempread(); /读高八位 temp=b; temp=8; temp=temp|a; /两字节合成一个整型变量 f_temp=temp*0.0625; /得到真实十进制温度值,因为DS18B20可以精确到0.0625度,所以读回数据的最低位代表的是0.0625度 temp=f_temp*10+0.5; /放大十倍,这样做的目的将小数点后第一位也转换为可显示数字,同时进行一个四舍五入操作。 return(temp); void dis_temp(uint t)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论