/*
*******************************************************************************
** Include files
*******************************************************************************
*/
#include <iom16.h>
#include <comp_a90.h>
#include <avr_macros.h>
#include <intrinsics.h>
#include "onewire.h"
//-----------------------------------------------------------------------------
//Generate a 1-wire reset, return 1 of no presence detect was found,
//return 0 otherwise.
//(NOTE: Does not handle alarm presence for DS2404/DS1994)
//
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is OneWire Reset.
**
** Parameters:
** None
**
** Returns:
** Return 1 of no presence detect was found, return 0 otherwise.
**
**-----------------------------------------------------------------------------
*/
unsigned char OWTouchReset(void)
{
unsigned char result = 0;
unsigned char i;
DQOut_Low(); //Drives DQ_T low
__delay_cycles(480*8);
DQOutData = High;
DQChangeInput(); //Releases the bus
__delay_cycles(40*8);
// result = DQ_T ^ 0x01; //Sample for presence pulse from slave
i = 250;
while(!DQ_T)
{
if(--i)
result = 1;
else
{
result = 0;
break;
}
_NOP();
}
__delay_cycles(300*8);
return result; //Return sample presence pulse result
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is Send a 1-wire bit.
**
** Parameters:
** provide 10us recovery time
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void OWWriteBit(unsigned char bit)
{
//write '1' bit
DQOut_Low(); //Drives DQ_T low
// delay1us();
__delay_cycles(8);
DQOutData = bit;
__delay_cycles(90*8); //Complete the time slot and 10us recovery
DQChangeInput(); //Releases the bus
__delay_cycles(30*8);
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is Read a bit from the 1-wire bus return it.
** Provide 10us recovery time.
** Parameters:
** None
**
** Returns:
** Return a bit from the 1-wire bus.
**
**-----------------------------------------------------------------------------
*/
unsigned char OWReadBit(void)
{
unsigned char result;
DQOut_Low(); //Drives DQ_T low
// delay1us();
DQChangeInput(); //Releases the bus
__delay_cycles(10*8);
_NOP();_NOP();_NOP();
result = DQ_T & 0x01; //Sample the bit value from the slave
__delay_cycles(60*8); //Complete the time slot and 10us recovery
return result;
}
/*
*******************************************************************************
** This is all for bit-wise manipulation of the 1-Wire bus.The above routines
** can be built upon to create byte-wise manipulator functions as seen in
** Example 3.
** Example 3.Derived 1-Wire Functions
*******************************************************************************
*/
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is Wirte 1-Wire data byte.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void OWWriteByte(unsigned char data)
{
unsigned char loop;
//Loop to write each bit in the byte, LS-bit first
for(loop = 8; loop != 0 ; loop--)
{
OWWriteBit(data & 0x01);
data >>= 1;
}
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is Read 1-wire data byte and retrurn it.
**
** Parameters:
** None
**
** Returns:
** Return read 1-wire
**
**-----------------------------------------------------------------------------
*/
unsigned char OWReadByte(void)
{
unsigned char loop,result = 0;
for(loop = 8;loop != 0;loop --)
{
//Shift the result to get it ready for the nexit bit
result >>= 1;
//if result is one,then set MS bit
if(OWReadBit())
result |= 0x80;
}
return result;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is Write a 1-wire data byte and return the
** sampled result.
**
** Parameters:
** Write value.
**
** Returns:
** return the sampled result.
**
**-----------------------------------------------------------------------------
*/
unsigned char OWTouchByte(unsigned char data)
{
unsigned char loop,result = 0;
for(loop = 8;loop != 0;loop --)
{
//Shift the result to get it ready for the next bit
result >>= 1;
//if sending a '1' then read a bit else write a '0'
if(data & 0x01)
{
if(OWReadBit())
result |= 0x80;
}
else
OWWriteBit(0);
//Sfhift the data byte for the next bit
data >>= 1;
}
return result;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is Wirte a block 1-wire data bytes and return
** the sampled result in the same buffer.
**
** Parameters:
** None
**
** Returns:
** Return the sampled result.
**
**-----------------------------------------------------------------------------
*/
void OWOverdriveSkip(unsigned char *data,unsigned char data_len)
{
unsigned char loop;
for( loop = 8; loop != 0; loop --)
{
data[loop] = OWTouchByte(data[loop]);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
红外遥控解码+Atmega16 +74HC595 数码管显示+C源代码+IAR (126个子文件)
IRread.a90 3KB
IRread_a90.aps 2KB
IRread_hex.aps 2KB
IRread_dbg.aps 2KB
IRread_d90.aps 2KB
irread_hex.aws 782B
irread_a90.aws 362B
irread_dbg.aws 106B
irread_d90.aws 106B
IRread.cspy.bat 2KB
onewire.c 6KB
readtemperature.c 5KB
IRRX.c 4KB
main.c 3KB
timer_use.c 1KB
display.c 916B
timer.c 867B
74h595.c 797B
datachange.c 611B
int.c 585B
main.c 39B
IRRX.cPreview 31KB
timer.cPreview 17KB
timer_use.cPreview 14KB
int.cPreview 12KB
datachange.cPreview 11KB
IRread.d90 31KB
IRread.dbg 28KB
IRread.dbgdt 15KB
Last Loaded IR Test.DBK 120KB
IRread.dep 10KB
IRread.dni 895B
IR Test.DSN 120KB
IRread.eep 34B
IRread.ewp 52KB
IRreadTest.eww 160B
onewire.h 3KB
readtemperature.h 986B
74h595.h 478B
IRRX.h 477B
timer.h 158B
datachange.h 147B
timer_use.h 146B
int.h 122B
display.h 108B
IRread.hex 3KB
IRRX.hPreview 11KB
IRread.pbd 502B
readtemperature.pbi 537B
datachange.pbi 527B
timer_use.pbi 525B
display.pbi 521B
onewire.pbi 521B
74h595.pbi 519B
timer.pbi 517B
main.pbi 515B
IRRX.pbi 515B
int.pbi 513B
IR Test.PWI 4KB
readtemperature.r90 26KB
main.r90 14KB
IRRX.r90 14KB
onewire.r90 13KB
timer_use.r90 8KB
74h595.r90 6KB
timer.r90 6KB
display.r90 6KB
int.r90 5KB
datachange.r90 5KB
IRreadTest.wsdt 4KB
IRRX.~(29).c.Zip 2KB
IRRX.~(32).c.Zip 2KB
IRRX.~(31).c.Zip 2KB
IRRX.~(30).c.Zip 2KB
IRRX.~(33).c.Zip 2KB
IRRX.~(25).c.Zip 2KB
IRRX.~(27).c.Zip 2KB
IRRX.~(28).c.Zip 2KB
IRRX.~(26).c.Zip 2KB
IRRX.~(35).c.Zip 2KB
IRRX.~(34).c.Zip 2KB
IRRX.~(10).c.Zip 2KB
IRRX.~(36).c.Zip 2KB
IRRX.~(22).c.Zip 2KB
IRRX.~(23).c.Zip 2KB
IRRX.~(24).c.Zip 2KB
IRRX.~(11).c.Zip 2KB
IRRX.~(9).c.Zip 2KB
IRRX.~(8).c.Zip 2KB
IRRX.~(6).c.Zip 2KB
IRRX.~(7).c.Zip 2KB
IRRX.~(18).c.Zip 2KB
IRRX.~(5).c.Zip 2KB
IRRX.~(41).c.Zip 2KB
IRRX.~(4).c.Zip 2KB
IRRX.~(37).c.Zip 1KB
IRRX.~(2).c.Zip 1KB
IRRX.~(39).c.Zip 1KB
IRRX.~(42).c.Zip 1KB
IRRX.~(40).c.Zip 1KB
共 126 条
- 1
- 2
熊已出没
- 粉丝: 55
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- push_version
- 软件自制图像批量压缩工具
- 基于深度学习的抗梯度噪声的缺陷检测器python源码+文档说明+模型的预训练
- 基于python+pytorch+mysql实现停车场车牌识别管理系统源码+文档说明
- 基于QT+MySQl+OpenCV车牌识别搭建停车场管理系统C++源码+文档说明+界面展示
- 基于深度学习的停车场收费系统-车牌识别模块python源码+文档说明+博客教学
- 空白.pages
- 基于Java+Springboot+vue的智能停车场管理系统(源代码+数据库+9000字论文) 本项目前后端不分离+部署教程
- 基于SSM写的停车场管理系统,加入了车牌识别和数据分析+源码+文档说明
- stream-response.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页