单片机DS18B20温度检测应用设计芯片解密
/****************************************************************
* 芯片解密实 验 名 :DS18B20温度实验
*芯片解密 实验说明 :数码管显示当前温度
* 芯片解密连接方式 :将DS18B20插到数字温度检测模块的U5上(注意方向),DS_RD接P2.2
*****************************************************************/
//包含文件
#include<reg52.h>
#include<intrins.h>
//宏定义
#defineBAUD 9600 //波特率设置,bps
#defineFOSC 11059200L //晶振设置,默认使用11.0592MHz
//#defineFOSC 12000000L //晶振设置,使用12M Hz
//#defineFOSC 24000000L //晶振设置,使用24M Hz
//IO接口定义
#defineLED_PORT P0
sbitwela_1 = P2^4;
sbitwela_2 = P2^5;
sbitwela_3 = P2^6;
sbitwela_4 = P2^7;
sbitDQ = P2^2; //定义DS18B20端口DQ
//全局变量定义
unsignedchar temperature;
unsignedchar temperature_dec;
unsignedchar qian,bai,shi,ge;
//LED显示字模 0-F 共阳模式
unsignedcode table[]={0Xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsignedchar RomCode[8]; //DS18B20中的RomCode
/*******************************************************************************
* 函 数 名 :Delayms
* 函数功能 :实现 ms级的延时
* 输 入:ms
* 输 出:无
*******************************************************************************/
voidDelayms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
#if FOSC == 11059200L
for(j=0;j<114;j++);
#elif FOSC == 12000000L
for(j=0;j<123;j++);
#elif FOSC == 24000000L
for(j=0;j<249;j++);
#else
for(j=0;j<114;j++);
#endif
}
/*******************************************************************************
* 函 数 名 :LEDdisplay
* 函数功能 :循环显示各个位上的数据
* 输 入:num要显示的数据
* 输 出:无
*******************************************************************************/
voidLEDdisplay()
{
wela_1 = 1; //关闭所有数码管
wela_2 = 1;
wela_3 = 1;
wela_4 = 1;
wela_4=0; //显示千位
LED_PORT=table[qian];
Delayms(1);
LED_PORT = 0xff;
wela_4=1;
wela_3=0; //显示百位
LED_PORT=table[bai];
Delayms(1);
LED_PORT = 0xff;
wela_3=1;
wela_2=0; //显示十位
LED_PORT=table[shi] & 0x7F;
Delayms(1);
LED_PORT = 0xff;
wela_2=1;
wela_1=0; //显示个位
LED_PORT=table[ge];
Delayms(1);
LED_PORT = 0xff;
}

芯片解密