矿石收音机论坛

 找回密码
 加入会员

QQ登录

只需一步,快速开始

搜索
查看: 10161|回复: 21

18B20温度计

[复制链接]
     
发表于 2010-3-21 10:45:22 | 显示全部楼层 |阅读模式
     
发表于 2010-3-21 12:18:31 | 显示全部楼层
温度计做的太好了。帮顶。
回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2010-3-21 14:51:35 | 显示全部楼层

回复 2# 浪漫人生 的帖子

谢谢!帮顶!5110这LCD屏不错
回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2010-3-21 15:03:17 | 显示全部楼层
开背光的效果
图片 001.jpg
图片 002.jpg
图片 003.jpg
回复 支持 反对

使用道具 举报

发表于 2010-3-21 21:37:24 | 显示全部楼层
这么好的屏,只做个温度计,浪费啊!
回复 支持 反对

使用道具 举报

发表于 2010-3-22 10:20:43 | 显示全部楼层
原帖由 看看就行 于 2010-3-21 21:37 发表
这么好的屏,只做个温度计,浪费啊!

是啊,应该做手机的
回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2010-3-22 14:37:05 | 显示全部楼层
是手机屏不过才15块和1062价差不多
回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2010-3-23 13:43:10 | 显示全部楼层
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DQ=P1^1;
uint temp;
float f_temp;
uchar flag ;
sbit    sce = P2^0;  //片选
sbit    res = P2^1;  //复位,0复位
sbit    dc  = P2^2;  //1写数据,0写指令
sbit    sdin = P2^3;  //数据
sbit    sclk = P2^4;  //时钟

unsigned char code hanzi[]=
{
0x88,0x84,0xFE,0xAB,0xAA,0xFF,0xAA,0xAA,0xAA,0xAA,0x80,0x00,0x04,0x04,0x02,0x01,
0x00,0x07,0x00,0x01,0x02,0x04,0x04,0x00,//集0
0x0C,0x14,0x14,0x14,0x15,0xF6,0x14,0x14,0x14,0x14,0x0C,0x00,0x00,0x00,0x00,0x04,
0x04,0x07,0x00,0x00,0x00,0x00,0x00,0x00,//宁1
0xFC,0x00,0xFF,0x00,0xF9,0x09,0x09,0xFF,0x09,0x09,0xF9,0x00,0x04,0x02,0x01,0x00,
0x01,0x00,0x00,0x07,0x00,0x01,0x01,0x00,//师2
0x22,0x4A,0x92,0x67,0x02,0xF2,0x12,0x97,0x92,0xF2,0x02,0x00,0x01,0x07,0x00,0x00,
0x00,0x07,0x04,0x04,0x04,0x04,0x07,0x00,//范3
0x9C,0x84,0x95,0x96,0x95,0xD6,0xB4,0x94,0x87,0x94,0x8C,0x00,0x00,0x00,0x00,0x04,
0x04,0x07,0x00,0x00,0x00,0x00,0x00,0x00,//学4
0xFF,0x81,0x8D,0xF3,0x26,0x2A,0xEA,0x2B,0xEA,0x2A,0x26,0x00,0x07,0x00,0x00,0x04,
0x04,0x02,0x01,0x00,0x07,0x04,0x07,0x00,//院5
0x00,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x23,0x22,0x00,0x00,0x04,0x04,0x04,0x04,
0x04,0x07,0x04,0x04,0x04,0x04,0x04,0x00,//王6
0x08,0x30,0xC0,0x00,0xFF,0x00,0x00,0xFF,0x40,0x20,0x18,0x00,0x04,0x04,0x04,0x04,
0x07,0x04,0x04,0x07,0x04,0x04,0x04,0x00,//业7
0x00,0xFF,0x49,0xFF,0x10,0x4E,0x48,0xFF,0x48,0x48,0x48,0x00,0x06,0x01,0x04,0x07,
0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x00,//胜8
0x18,0xD6,0x54,0xFF,0x54,0x56,0xD4,0x00,0xFC,0x00,0xFF,0x00,0x00,0x03,0x00,0x07,
0x00,0x02,0x03,0x00,0x04,0x04,0x07,0x00,//制9
0x10,0xF1,0x02,0x10,0xD8,0x56,0x54,0x5F,0x54,0xD4,0x10,0x00,0x06,0x01,0x02,0x02,
0x05,0x05,0x05,0x05,0x05,0x05,0x04,0x00,//造10
};

unsigned char code shuzi[]={
0xF8,0x04,0x04,0x04,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,//0
0x00,0x08,0xFC,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,//1
0x18,0x84,0x44,0x44,0x38,0x00,0x03,0x02,0x02,0x02,0x02,0x00,//2
0x88,0x04,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,//3
0xC0,0xB0,0x88,0xFC,0x80,0x00,0x00,0x00,0x00,0x03,0x00,0x00,//4
0x3C,0x14,0x14,0x14,0xE4,0x00,0x01,0x02,0x02,0x02,0x01,0x00,//5
0xF8,0x24,0x24,0x24,0xC8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,//6
0x04,0x04,0x04,0xE4,0x1C,0x00,0x00,0x00,0x03,0x00,0x00,0x00,//7
0xD8,0x24,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,//8
0x38,0x44,0x44,0x44,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,//9
0x00,0x00,0x04,0x0A,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'
0xF8,0x04,0x04,0x04,0x98,0x00,0x01,0x02,0x02,0x02,0x01,0x00,//C
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,//.
0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,//:
0x04,0x04,0xFC,0x04,0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00,//T
0x20,0x20,0xFC,0x20,0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00,//空格,+
0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//-
};

void delayms(uint z)
{
uint x,y;
for(y=z;y>0;y--)
  for(x=1400;x>0;x--);
}
void LCD_write_byte(unsigned char dt, unsigned char command)
{
unsigned char i;
sce=0;
dc=command;
for(i=0;i<8;i++)
{
  if(dt&0x80)
   sdin=1;
  else
   sdin=0;
  dt=dt<<1;  
  sclk=0;   
  sclk=1;
}
dc=1;
sce=1;
sdin=1;
}

void LCD_init(void)
{
res=0;   
   delayms(1);
   res=1;
LCD_write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xd0,0);//设定液晶偏置电压
LCD_write_byte(0x20,0);//使用基本指令
LCD_write_byte(0x0C,0);//设定显示模式,正常显示
}

void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);// column
LCD_write_byte(0x80 | X, 0);// row
}
void LCD_clear(void)
{
unsigned char t;
unsigned char k;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
  for(k=0;k<84;k++)
  {
   LCD_write_byte(0x00,1);
   
  }
}
}

void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
unsigned char i;   

LCD_set_XY(row*6, page);// 列,页
for(i=0; i<6;i++)
{
  LCD_write_byte(shuzi[c*12+i],1);
}

    LCD_set_XY(row*6, page+1);// 列,页
for(i=6; i<12;i++)
{
  LCD_write_byte(shuzi[c*12+i],1);
}   
}

/*---------------------------------------------
LCD_write_hanzi: 显示12(宽)*16(高)点阵列汉字等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
        unsigned char i;         
       
        LCD_set_XY(row*6, page);// 列,页
        for(i=0; i<12;i++)
        {
                LCD_write_byte(hanzi[c*24+i],1);
        }
       
    LCD_set_XY(row*6, page+1);// 列,页
        for(i=12; i<24;i++)
        {
                LCD_write_byte(hanzi[c*24+i],1);
        }       
}
/*************************************************************************************/
void delay(unsigned int i)//延时函数
{
while(i--);
}
/***************************************************************************************/
/***************************************************************************************/
//18b20初始化函数
uchar Init_DS18B20(void)
{
unsigned char x=0;
DQ = 1;     //DQ复位
delay(8);   //稍做延时
DQ = 0;     //单片机将DQ拉低
delay(80); //精确延时 大于 480us
DQ = 1;     //拉高总线
delay(10);
x=DQ;       //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
delay(5);
return (x);
}
/******************************************************************************************/
//读一个字节
unsigned char ReadOne(void)
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
   DQ = 0; // 给脉冲信号
   dat>>=1;
   DQ = 1; // 给脉冲信号
   if(DQ)
    dat|=0x80;
   delay(5);
}
return(dat);
}
/************************************************************************************************/
//写一个字节
void WriteOne(unsigned char dat)
{
unsigned char i=0;
for (i=8; i>0; i--)
{
   DQ = 0;
   DQ = dat&0x01;
   delay(5);
   DQ = 1;
   dat>>=1;
}
delay(5);
}
/*********************************************************************************************************/


void tempchange(void)
{
uchar a,b;
Init_DS18B20();
WriteOne(0xcc);
WriteOne(0x44);
delay(200);
Init_DS18B20();
WriteOne(0xcc);
WriteOne(0xbe);
a=ReadOne();
b=ReadOne();

if((b&0xF0)>0)
{  
flag=1;

}else
{
flag=0;

}
if(flag){ //如果为负温度取反加1

b=~b;
a=~a+1;
} //判断是否为负温度

temp=b;
temp<<=8;
temp=temp|a;
f_temp=temp*0.0625;
temp=f_temp*10+0.5;

}
void dis_temp()
{
uchar i;
//LCD_write_shu(4,2,f);
i=temp%1000/100;
LCD_write_shu(5,2,i);
i=temp%100/10;
LCD_write_shu(6,2,i);
i=temp%10;
LCD_write_shu(8,2,i);
}
void main()
{
unsigned char k,i;
res=0;
i++;
for(k=0;k<250;k++);
res=1;   
LCD_init();  //初始化LCD模块
LCD_clear(); //清屏幕
LCD_write_hanzi(1,0,0);  //J
LCD_write_hanzi(3,0,1);  //N
LCD_write_hanzi(5,0,2);  //S
LCD_write_hanzi(7,0,3);  //F
LCD_write_hanzi(9,0,4);  //X
LCD_write_hanzi(11,0,5);  //Y
LCD_write_shu(3,2,14);
LCD_write_shu(7,2,12);
LCD_write_shu(9,2,10);
LCD_write_shu(10,2,11);
LCD_write_hanzi(1,4,6);  //w
LCD_write_hanzi(3,4,7);  //y
LCD_write_hanzi(5,4,8);  //S
LCD_write_hanzi(9,4,9);  //制
LCD_write_hanzi(11,4,10);  //造
while(1)
{
  tempchange();
  dis_temp();
  
if(flag==1)
{LCD_write_shu(4,2,16);}
else
{LCD_write_shu(4,2,15);}

}
}

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

     
发表于 2010-3-24 22:49:44 | 显示全部楼层
不错不错,做个带温度显示的万年历吧
回复 支持 反对

使用道具 举报

发表于 2010-3-25 09:08:38 | 显示全部楼层
回复 支持 反对

使用道具 举报

     
发表于 2010-3-26 17:21:29 | 显示全部楼层
很不错的作品.
回复 支持 反对

使用道具 举报

     
发表于 2010-3-27 13:05:46 | 显示全部楼层
Code 代码 看到了  不错加油!
问下这个屏叫什么名?
回复 支持 反对

使用道具 举报

     
 楼主| 发表于 2010-3-27 13:33:47 | 显示全部楼层
诺基亚5110
nokia5110 液晶 ,带接口PCB和背光
回复 支持 反对

使用道具 举报

     
发表于 2010-6-16 11:57:38 | 显示全部楼层
不错的作品
回复 支持 反对

使用道具 举报

发表于 2010-6-17 17:46:14 | 显示全部楼层
   DQ = 1; // 给脉冲信号


you shouldn't set DQ under 1-wire. instead, you should let DQ float to high - it has a pull-up resistor.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 加入会员

本版积分规则

小黑屋|手机版|矿石收音机 ( 蒙ICP备05000029号-1 )

蒙公网安备 15040402000005号

GMT+8, 2025-4-28 07:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表