标题:
[求助]有GP32与DS18B20温度传感器的C源程序吗?
[打印本页]
作者:
tuorongou
时间:
2005-6-1 13:10
标题:
[求助]有GP32与DS18B20温度传感器的C源程序吗?
各位大虾:有GP32与DS18B20温度传感器的C源程序吗?要求用四位数码管显示温度值.
谢谢!
我的联系方式:tuorongou@126.com[em26]
[此贴子已经被作者于2005-6-1 13:10:58编辑过]
作者:
tuorongou
时间:
2005-6-2 12:43
怎么啦?大家都没有用过?
作者:
hdtv_tang
时间:
2006-5-4 18:02
同求。
作者:
at_sxf
时间:
2006-5-12 09:39
标题:
gt8的读写ds18b20的程序
void Delayiic(void)
{
return;
}
void delay100us(uchar n)
{
uchar i;
uchar j;
for (i=0; i
{
for (j=0; j<20; j++);
__RESET_WATCHDOG();
}
return;
}
void delay_400us(void)
{
T1SC_TSTOP = 1;
T1SC_TRST = 1;
T1MODH = 0xf0;
T1MODL = 0x00;
T1SC_PS2 = 0;
T1SC_PS1 = 1;
T1SC_PS0 = 1; //分频系数为8,计数频率为307200Hz,计数周期3.2552us
T1SC_TSTOP = 0;
while(1)
{
if (T1CNTH != 0 || T1CNTL >= 123)
{
T1SC_TSTOP = 1;
return;
}
__RESET_WATCHDOG();
}
}
void delay_82us(void)
{
T1SC_TSTOP = 1;
T1SC_TRST = 1;
T1MODH = 0xf0;
T1MODL = 0x00;
T1SC_PS2 = 0;
T1SC_PS1 = 1;
T1SC_PS0 = 1; //分频系数为8,计数频率为307200Hz,计数周期3.2552us
T1SC_TSTOP = 0;
while(1)
{
if (T1CNTH != 0 || T1CNTL >= 26)
{
T1SC_TSTOP = 1;
return;
}
__RESET_WATCHDOG();
}
}
void delay_33us(void)
{
T1SC_TSTOP = 1;
T1SC_TRST = 1;
T1MODH = 0xf0;
T1MODL = 0x00;
T1SC_PS2 = 0;
T1SC_PS1 = 1;
T1SC_PS0 = 1; //分频系数为8,计数频率为307200Hz,计数周期3.2552us
T1SC_TSTOP = 0;
while(1)
{
if (T1CNTH != 0 || T1CNTL >= 11)
{
T1SC_TSTOP = 1;
return;
}
__RESET_WATCHDOG();
}
}
void init_18b20_a (void)
{
DisableInterrupts;
wd_a_D = 1;
wd_a = 1;
Delayiic();
wd_a = 0;
delay_400us(); //delay 400 uS
wd_a = 1;
delay_82us(); //delay 82 uS
wd_a_D = 0;
if(wd_a == 0)
flag=1; //detect 1820 success!
else
flag=0; //detect 1820 fail!
delay_82us();
wd_a_D = 1;
wd_a = 1;
wd_a_D = 0;
EnableInterrupts;
}
void write_a (uchar wr)
{
uchar i;
__RESET_WATCHDOG();
DisableInterrupts;
wd_a_D = 1;
for (i=0;i<8;i++)
{
wd_a = 0;
Delayiic();
wd_a=wr&0x01;
delay_33us(); //delay 33 uS
wd_a = 1;
wr>>=1;
}
wd_a_D = 0;
EnableInterrupts;
}
uint read_word_a (void)
{
uchar i;
uint u=0;
DisableInterrupts;
__RESET_WATCHDOG();
for(i=0;i<16;i++)
{
wd_a_D = 1;
wd_a = 0;
u>>=1;
wd_a = 1;
wd_a_D = 0;
if(wd_a==1)
u|=0x8000;
delay_33us();
}
EnableInterrupts;
return(u);
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0