ds18b20.c
ds18b20.c
如下:
#include "iocc2530.h"
#define uint unsigned int
#define uchar unsigned char
#define Ds18b20Data P0_6 /* 温度传感器引脚 */
#define ON 0x01 /* 读取成功返回0x00,失败返回0x01 */
#define OFF 0x00
unsigned char temp; /* 储存温度信息 */
void Ds18b20Delay ( uint k ) {
/* 时钟频率为32M */
uint i, j;
for ( i = 0; i < k; i++ )
for ( j = 0; j < 2; j++ );
}
void Ds18b20InputInitial ( void ) {
/* 设置端口为输入 */
P0DIR &= 0xbf;
}
void Ds18b20OutputInitial ( void ) {
/* 设置端口为输出 */
P0DIR |= 0x40;
}
uchar Ds18b20Initial ( void ) {
/* ds18b20初始化,初始化成功返回0x00,失败返回0x01 */
uchar Status = 0x00;
uint CONT_1 = 0;
uchar Flag_1 = ON;
Ds18b20OutputInitial();
Ds18b20Data = 1;
Ds18b20Delay (