微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 自制带有开机音乐的可显数字温度计

自制带有开机音乐的可显数字温度计

时间:10-24 来源:互联网 点击:
因为一个朋友要过生日,而且已经大三了,相聚的日子屈指可数,所以就想尽自己的所能给她做一件礼物。

说来也不顺,知道她过生日的时候,已经距她过生日还有仅仅4天的时间,时间很紧,也不知道送些啥,一想,自己这些天一直在做关于单片机的东西,索性利用身边的材料,做一个东西给她,也挺有意义的。但因为平时忙着复习考研,所以注定做得东西不能太复杂了,否则根本完成不了,后来也就决定做这个温度计了。电路也不难,程序自己也见过,大概改改也就差不多了。后来感觉仅仅显示温度也太单调了,就加了音乐功能,一首《隐形的翅膀》也不错。

从周三开始,每天晚上11:00开始做,到今天,总算研制成功吧!有点遗憾的是,身边没有2-4译码器,所以LED驱动的不好,就算加了两个上拉排阻,显示的还是挺暗!





由于本文篇幅有限部分文件请从这里下载:
http://www.51hei.com/ziliao/file/SoundPlay.rar 这个是音乐播放文件

#include REG52.H>#include "SoundPlay.h"#define  uchar  unsigned  char #define  uint   unsigned  intsbit  DATA = P3^7; //DS18B20接入口uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};char  bai,shi,ge; //定义变量/*延时子函数*/void delay(uint num){while(num--) ;}void Delay1ms(unsigned int count){unsigned int i,j;for(i=0;icount;i++)for(j=0;j120;j++);}/*************DS18b20温度传感器函数*********************/Init_DS18B20(void)     //传感器初始化{uchar x=0;DATA = 1;    //DQ复位delay(10);  //稍做延时DATA = 0;    //单片机将DQ拉低delay(80); //精确延时 大于 480us    //450DATA = 1;    //拉高总线delay(20);x=DATA;      //稍做延时后 如果x=0则初始化成功 x=1则初始化失败delay(30);}//读一个字节ReadOneChar(void){uchar i=0;uchar dat = 0;for (i=8;i>0;i--){DATA = 0; // 给脉冲信号dat>>=1;DATA = 1; // 给脉冲信号if(DATA)dat|=0x80;delay(8);}return(dat);}//写一个字节WriteOneChar(unsigned char dat){uchar i=0;for (i=8; i>0; i--){DATA = 0;DATA = dat0x01;delay(10);DATA = 1;dat>>=1;}delay(8);}//读取温度int ReadTemperature(void){uchar a=0;uchar b=0;int t=0;float tt=0;Init_DS18B20();WriteOneChar(0xCC); // 跳过读序号列号的操作WriteOneChar(0x44); // 启动温度转换Init_DS18B20();WriteOneChar(0xCC); //跳过读序号列号的操作WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度a=ReadOneChar();//低位b=ReadOneChar();//高位t=b;t=8;t=t|a;tt=t*0.0625;t= tt*10+0.5; return(t);}/*显示子函数*/void  display(int bai,int shi,int ge){P2=0XFB; //显示小数点P0=0X80; //显示小数点delay(50);//显示小数点P2=0xf7;P0=table[bai];//显示千位delay(50);//一小段延时动态显示P2=0xfb;P0=table[shi];//显示百位delay(50);P2=0xfd;P0=table[ge];//显示十位delay(100);}//*****************************Music********************************//挥着翅膀的女孩unsigned char code Music_Girl[]={ 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03,0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03,0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03,0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02,0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03, 0x16,0x03,0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03,0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03,0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03,0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03,0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02,0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03,0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03,0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03,0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03,0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03,0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03,0x15,0x17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03,0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E,0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03,0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66,0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03,0x1F,0x66, 0x1F,0x04, 0x1B,0x0E, 0x1B,0x03, 0x19,0x03,0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04,0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03,0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03,0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03,0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03,0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02,0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02,0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0x00,0x00};//***********************************************************************************main(){int  temp;InitialSound();Play(Music_Girl,0,3,360);Delay1ms(500);while(1){  temp=ReadTemperature();//读温度bai=temp%1000/100;//显示百位shi=temp%100/10;//显示十位ge=temp%10;//显示个位display(bai,shi,ge);//显示函数 }}/****************************

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top