⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 18b20test.c

📁 2005年吉林省电子大赛一等奖的全部代码
💻 C
字号:
//ICC-AVR application builder : 2005-4-11 12:45:38
// Target : M16
// Crystal: 8.0000Mhz

#include <iom16v.h>
#include <macros.h>
#include "DS18B20.h"
#include "7279.h"

//#include <string.h>
//#include <stdlib.h>



//*****变量声明*******
unsigned char DS18B20[9]={0,0,0,0,0,0,0,0,0};
unsigned char *asc2p;
unsigned char sec_count[3]={0,0,0};
const unsigned char table[]="0123456789ABCDEF";
/****温度转换****/

void turnon(void)
{
  unsigned long int turnoff;
  unsigned char i,crc;

  unsigned int  DS18B20_temp;

	PORTA&=~(1<<1);
    DS18B20_reset();
    DS18B20_write(0xcc);     // 跳过多器件识别 
    DS18B20_write(0xbe);     // 读暂存器 
	PORTA|=(1<<1);
	for(i=0;i<9;i++)
	 DS18B20[i]=DS18B20_read();
	asc2p=&DS18B20[0];	
	crc=CRCcheck(asc2p,9);
	delay(3);
	if(crc==0x00)
	{
	 DS18B20_temp=DS18B20[1];
	 DS18B20_temp=DS18B20_temp<<8;
	 DS18B20_temp+=DS18B20[0];
	 value_temp=DS18B20_temp;
	 asc2p=&DS18B20[0];
	}
	turnoff=(unsigned long int)(DS18B20_temp);
	turnoff=(turnoff*10000/16);
    /*for(i=6;i>0;i--)
	{
	 DS18B20[i-1]=table[turnoff%10];
	 turnoff/=10;
	}*/
	for(i=0;i<6;i++)
	{
	 DS18B20[i]=table[turnoff%10];
	 turnoff/=10;
	}
	DS18B20[4]|=0x80;
	//return(value_temp);
	delay(2);
  }

 
/****温度显示****/

void DS18B20Display(void)
{
 unsigned char i;
 //send_byte(CMD_RESET);			// 复位HD7279A
 for(i=4;i>0;i--)
  {
    write7279((DECODE1+(i-1)),DS18B20[i+1]);
  }
}	
/****读秒计数****/
void sec_display(int value)
{
 unsigned char i,j,count;
 if((value==800)&&(count<120))
  {
   count++;
   for(i=0;i<3;i++)
   {
    sec_count[i]=count%10;
	count/=10;
   }
   for(j=0;j<3;j++)
   write7279(DECODE1+j,sec_count[i]);
   
  }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -