#define DS18B20
#define DQ S3C2410_GPIO6
#define rPDATF_IN S3C2410_GPIO6_INP
#define rPCONF_OUT S3C2410_GPIO6_OUTP
void delay_1us(void);
void delay_nus(unsigned int n);
void delay_1ms(void);
void tempconvert(unsigned char temH,unsigned char temL);
unsigned char InitDs18b20(void);
void ConfigDs18b20(void);
void DS18B20_WriteOneBit_0(void);
void DS18B20_WriteOneBit_1(void);
unsigned char DS18B20_ReadOneBit_1(void);
unsigned char ReadOneByte(void);
void WriteOneByte(unsigned char dat);
float ReadTemperature(void);
#endif
#include
#include
//#include "44B.H"
#include "hardware.h"
unsigned int rPDATF;
unsigned int rPCONF;
void delay_1us(void)//1us
{
asm("nop");
}
void delay_nus(unsigned int n)//N us
{unsigned int n, i=0;
for (i=0;i
}
void delay_1ms(void)//1ms
{
unsigned int i;
for (i=1;i<1140;i++);
}
void delay_nms(unsigned int n)//N ms
{
unsigned int i=0;
for (i=0;i
}
void tempconvert(unsigned char temH,unsigned char temL)
{
unsigned char L,H;
H=(temL >> 4)+(temH<<4);
L=(temL & 0x0F)? 5:0;
}
unsigned char InitDs18b20(void)
{
unsigned char RX=1;
// rPCONF=0x1255;
rPDATF=0x01;
delay_nus(5);
rPDATF=0x0;
delay_nus(500);
rPDATF=0x01;
// delay_nus(100);
rPCONF=0x0000;
delay_nus(100);
if((rPDATF & 0x01)==0)
{
RX=0;//success!
}
else
RX=1;//faill!
delay_nus(480);
// rPCONF=0x01;//output
rPCONF=0x1255;
rPDATF=0x01;
return RX;
}
unsigned char DS18B20_Read0neBit_1()
{
unsigned char bReturnValue=0;
//rPCONF=0x01;
rPCONF=0x1255;
rPDATF=0x01;
//delay_1us();
rPDATF=0x0;
delay_nus(15);
if(rPDATF&0x01)
{
bReturnValue=1;
}
delay_nus(50);
return bReturnValue;
}
unsigned char DS18B20_ReadOneBit_0()
{
unsigned char bReturnValue=1;
rPCONF=0x1255;
rPDATF=0x01;
rPDATF=0x0;
delay_1us();
rPCONF=0x0000;
delay_nus(15);
if((rPDATF&0x01)==0)
bReturnValue=0;
rPCONF=0x1255;
rPDATF=0x01;
delay_nus(50);
return bReturnValue;
}
unsigned char ReadOneByte(void)
{ unsigned char uci;
unsigned char ucReadData;
unsigned char ucMaskCode;
unsigned char ucReaData;
ucReadData=0;
ucMaskCode=0x01;
for(uci=0;uci<8;uci++)
{if(DS18B20_ReadOneBit_1()==1)
{
ucReaData |=ucMaskCode;
}
ucMaskCode <<=1;
}
return ucReadData;
}
void DS18B20_WriteOneBit_0()
{
rPCONF=0x1255;
//rPCONF=0x01;
rPDATF=0x01;
//dalay_1us();
rPDATF=0x0;
delay_nus(15);
delay_nus(15);
delay_nus(30);
rPDATF=0x01;
}
void DS18B20_WriteOneBit_1()
{
//rPCONF=0x01;
rPCONF=0x1255;
rPDATF=0x01;
// delay_1us();
rPDATF=0x0;
delay_nus(15);
rPDATF=0x01;
delay_nus(15);
delay_nus(30);
}
void WriteOneByte(unsigned char ucWriteData)
{
unsigned char uci;
unsigned char ucTemp;
ucTemp = ucWriteData;
for(uci=0; uci<8; uci++)
{
if(ucTemp & 0x01)
{
DS18B20_WriteOneBit_1();
}
else
{
DS18B20_WriteOne_0();
}
ucTemp >>= 1;
}
}
void ConfigDs18b20 (void)
{
InitDs18b20();
printf(" I am writing!\n");
WriteOneByte(0xcc);//skip rom
WriteOneByte(0x4e);//write scratchpad
WriteOneByte(0x19);
WriteOneByte(0x1a);
WriteOneByte(0x7f); //set 11 bit (0.0625)
InitDs18b20();
WriteOneByte(0xcc); //skip rom
WriteOneByte(0xb8);
IniteOneByte(0xcc); //skip rom
WriteOneByte(0xb8);
}
float ReadTemperature(void)
{
unsigned char tempL=0;
unsigned char tempH=0;
unsigned char TH=0;
unsigned char TL=0;
unsigned char con=0;
float temperature;
unsigned char ucTempDataBuff[9];
ConfigDs18b20();
if( InitDs18b20()==1)
{
printf("error");
exit(1);
}
WriteOneByte(0xcc);
WriteOneByte(0x44);
// usleep(750000);
delay_nms(750);
InitDs18b20();
WriteOneByte(0xcc);
WriteOneByte(0xbe);
// tempL=ReadOneByte();
// tempH=ReadOneByte();
ucTempDataBuff[0] = ReadOneByte();
ucTempDataBuff[1] = ReadOneByte();
ucTempDataBuff[2] = ReadOneByte();
ucTempDataBuff[3] = ReadOneByte();
ucTempDataBuff[4] = ReadOneByte();
ucTempDataBuff[5] = ReadOneByte();
ucTempDataBuff[6] = ReadOneByte();
ucTempDataBuff[7] = ReadOneByte();
ucTempDataBuff[8] = ReadOneByte();
for(con=0;con<9;con++)
printf("%x\n",ucTempDataBuff[con]);
tempL=ucTempDataBuff[0];
tempH=ucTempDataBuff[1];
tempconvert(tempH,tempL);
printf("----------------------------");
temperature=((tempH*256)+tempL*0.0625);
//delay(200);
return temperature;
}
void Main (void)
{
int y;
y=ReadTemperature();
}
这段程序用make编译时出现了如下错误
ot@localhost 1234]# make
/usr/local/arm/2.95.3/bin/arm-linux-gcc -o aa.txt aa.txt.o
/usr/local/arm/2.95.3/arm-linux/lib/crt1.o: In function `_start':
/usr/local/arm/2.95.3/arm-linux/lib/crt1.o(.text+0x2c): undefined reference to `main'
aa.txt.o: In function `ReadOneByte':
aa.txt.o(.text+0x3c4): undefined reference to `DS18B20_ReadOneBit_1'
aa.txt.o: In function `WriteOneByte':
aa.txt.o(.text+0x54c): undefined reference to `DS18B20_WriteOne_0'
aa.txt.o: In function `ConfigDs18b20':
aa.txt.o(.text+0x5d0): undefined reference to `IniteOneByte'
collect2: ld returned 1 exit status
make: *** [aa.txt] Error 1
我的Makefile文件时
C = /usr/local/arm/2.95.3/bin/arm-linux-gcc
LD = /usr/local/arm/2.95.3/bin/arm-linux-ld
EXEC = aa.txt
OBJS = aa.txt.o
CFLAGS +=
LDFLAGS +=
all: $(EXEC)
$(EXEC): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS$(LDLIBS_$@))
cp $(EXEC) /tftpboot/examples/
clean:
-rm -f $(EXEC) *.elf *.gdb *.o
我的内核是2.4.20-8 请问哪位高手可以指点一下
gllw915 于 2010-10-29 16:36:26发表:
低调路过
jzpdgywx 于 2010-05-14 13:49:28发表:
路过,看看
whmouse 于 2010-04-16 21:51:22发表:
谢谢
武大小强 于 2010-03-23 07:27:17发表:
辛苦了。。。
wxly 于 2010-03-21 13:13:49发表:
好东西啊
MEYEGG 于 2010-01-08 22:24:06发表:
DING ..
uchiha 于 2009-12-30 22:10:51发表:
路过,好复杂哦
@明 于 2009-08-08 21:23:41发表:
a这是什么
NANJIDEGOU 于 2009-08-08 18:54:15发表:
main函数应该小写吧
xinyuyadx 于 2009-08-06 10:41:29发表:
哪位高手可以帮忙看一下吗 真的很急 !!!!!!!!!!
xiaomeng 于 2009-08-05 13:17:21发表:
晕乎,路过