新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 自制帶有開機音樂的可顯數(shù)字溫度計

自制帶有開機音樂的可顯數(shù)字溫度計

作者: 時間:2012-10-24 來源:網(wǎng)絡 收藏
#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; //定義變量/*延時子函數(shù)*/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溫度傳感器函數(shù)*********************/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);}//讀一個字節(jié)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);}//寫一個字節(jié)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);}/*顯示子函數(shù)*/void  display(int bai,int shi,int ge){P2=0XFB; //顯示小數(shù)點P0=0X80; //顯示小數(shù)點delay(50);//顯示小數(shù)點P2=0xf7;P0=table[bai];//顯示千位delay(50);//一小段延時動態(tài)顯示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);//顯示函數(shù) }}/****************************

上一頁 1 2 下一頁

評論


相關推薦

技術專區(qū)

關閉