?? 18b20test.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 + -