亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? main.c

?? 達拉斯 1-Wire 主機通信 這份資料展示了如何把 1-Wire 主機通信在應用到一個AVR系統中
?? C
字號:
// This file has been prepared for Doxygen automatic documentation generation.
/*! \file ********************************************************************
*
* Atmel Corporation
*
* \li File:               main.c
* \li Compiler:           IAR EWAAVR 3.20a
* \li Support mail:       avr@atmel.com
*
* \li Supported devices:  All AVRs.
*
* \li Application Note:   AVR318 - Dallas 1-Wire(R) master.
*                         
*
* \li Description:        Example on how to use the 1-Wire(R) interface
*                         master.
*
*                         $Revision: 1.7 $
*                         $Date: Thursday, August 19, 2004 14:27:18 UTC $
****************************************************************************/

#include <ioavr.h>
#include <inavr.h>

#include "OWIPolled.h"
#include "OWIHighLevelFunctions.h"
#include "OWIBitFunctions.h"
#include "..\common_files\OWIcrc.h"

#include <string.h> // Used for memcpy.


// Defines used only in code example.
#define DS1820_FAMILY_ID                0x10 
#define DS1820_START_CONVERSION         0x44
#define DS1820_READ_SCRATCHPAD          0xbe
#define DS1820_ERROR                    -1000   // Return code. Outside temperature range.

#define DS2890_FAMILY_ID                0x2c
#define DS2890_WRITE_CONTROL_REGISTER   0X55
#define DS2890_RELEASE_CODE             0x96
#define DS2890_WRITE_POSITION           0x0f

#define SEARCH_SUCCESSFUL               0x00
#define SEARCH_CRC_ERROR                0x01

#define FALSE       0
#define TRUE        1

#define MAX_DEVICES 8       //!< Max number of devices to search for.

#define BUSES   (OWI_PIN_0 | OWI_PIN_1) //!< Buses to search.


/*! \brief  Data type used to hold information about slave devices.
 *  
 *  The OWI_device data type holds information about what bus each device
 *  is connected to, and its 64 bit identifier.
 */
typedef struct
{
    unsigned char bus;      //!< A bitmask of the bus the device is connected to.
    unsigned char id[8];    //!< The 64 bit identifier.
} OWI_device;


// Prototypes of functions used in exemples.
unsigned char SearchBuses(OWI_device * devices, unsigned char len, unsigned char buses);
OWI_device * FindFamily(unsigned char familyID, OWI_device * devices, unsigned char size);
signed int DS1820_ReadTemperature(unsigned char bus, unsigned char * id);
void DS2890_SetWiperPosition(unsigned char position, unsigned char bus, unsigned char * id);


/*! \brief  Example application for the polled drivers.
 *
 *  Example application for the software only and polled UART driver.
 *  This example application will find all devices (upper bounded by MAX_DEVICES) 
 *  on the buses defined by BUSES. It then tries to find either a DS1820 or DS2890 
 *  device on a bus, and communicate with them to read temperature (DS1820) or 
 *  set wiper position (DS2890).
 *  This example is not written in a very optimal way. It is merely intended to show
 *  how the polled 1-Wire(R) driver can be used.
 */
void main(void)
{
    static OWI_device devices[MAX_DEVICES];
    OWI_device * ds1820;
    OWI_device * ds2890;
    signed int temperature = 0;
    unsigned char wiperPos = 0;
    
    // Initialize PORTB as output. Can be used to display values on
    // the LEDs on a STK500 development board.
    DDRB = 0xff;

    OWI_Init(BUSES);
    
    // Do the bus search until all ids are read without crc error.    
    while(SearchBuses(devices, MAX_DEVICES, BUSES) != SEARCH_SUCCESSFUL)
    {
    
    }
    
    // See if there is a DS1820 or DS2890 on a bus.
    ds1820 = FindFamily(DS1820_FAMILY_ID, devices, MAX_DEVICES);
    ds2890 = FindFamily(DS2890_FAMILY_ID, devices, MAX_DEVICES);
    
    // Do something useful with the slave devices in an eternal loop.
    for (;;)
    {
        // If there is a DS1820 temperature sensor on a bus, read the
        // temperature.
        // The DS1820 must have Vdd pin connected for this code to work.
        if (ds1820 != NULL)
        {
            temperature = DS1820_ReadTemperature((*ds1820).bus, (*ds1820).id);
        }        
        // If there is a DS2890 digital potentiometer, increment the
        // wiper value.
        if (ds2890 != NULL)
        {
            DS2890_SetWiperPosition(wiperPos++, (*ds2890).bus, (*ds2890).id);
        }
        
        // Discard lsb of temperature and output to PORTB.
        PORTB = ~(temperature >> 1);
    }
}


/*! \brief  Perform a 1-Wire search
 *
 *  This function shows how the OWI_SearchRom function can be used to 
 *  discover all slaves on the bus. It will also CRC check the 64 bit
 *  identifiers.
 *
 *  \param  devices Pointer to an array of type OWI_device. The discovered 
 *                  devices will be placed from the beginning of this array.
 *
 *  \param  len     The length of the device array. (Max. number of elements).
 *
 *  \param  buses   Bitmask of the buses to perform search on.
 *
 *  \retval SEARCH_SUCCESSFUL   Search completed successfully.
 *  \retval SEARCH_CRC_ERROR    A CRC error occured. Probably because of noise
 *                              during transmission.
 */
unsigned char SearchBuses(OWI_device * devices, unsigned char len, unsigned char buses)
{
    unsigned char i, j;
    unsigned char presence;
    unsigned char * newID;
    unsigned char * currentID;
    unsigned char currentBus;
    unsigned char lastDeviation;
    unsigned char numDevices;
    
    // Initialize all addresses as zero, on bus 0 (does not exist).
    // Do a search on the bus to discover all addresses.    
    for (i = 0; i < len; i++)
    {
        devices[i].bus = 0x00;
        for (j = 0; j < 8; j++)
        {
            devices[i].id[j] = 0x00;
        }
    }
    
    // Find the buses with slave devices.
    presence = OWI_DetectPresence(BUSES);
    
    numDevices = 0;
    newID = devices[0].id;
    
    // Go through all buses with slave devices.
    for (currentBus = 0x01; currentBus; currentBus <<= 1)
    {
        lastDeviation = 0;
        currentID = newID;
        if (currentBus & presence) // Devices available on this bus.
        {
            // Do slave search on each bus, and place identifiers and corresponding
            // bus "addresses" in the array.
            do  
            {
                memcpy(newID, currentID, 8);
                OWI_DetectPresence(currentBus);
                lastDeviation = OWI_SearchRom(newID, lastDeviation, currentBus);
                currentID = newID;
                devices[numDevices].bus = currentBus;
                numDevices++;
                newID=devices[numDevices].id;                
            }  while(lastDeviation != OWI_ROM_SEARCH_FINISHED);            
        }
    }

    // Go through all the devices and do CRC check.
    for (i = 0; i < numDevices; i++)
    {
        // If any id has a crc error, return error.
        if(OWI_CheckRomCRC(devices[i].id) != OWI_CRC_OK)
        {
            return SEARCH_CRC_ERROR;
        }
    }
    // Else, return Successful.
    return SEARCH_SUCCESSFUL;
}

/*! \brief  Find the first device of a family based on the family id
 *
 *  This function returns a pointer to a device in the device array
 *  that matches the specified family.
 *
 *  \param  familyID    The 8 bit family ID to search for.
 *
 *  \param  devices     An array of devices to search through.
 *
 *  \param  size        The size of the array 'devices'
 *
 *  \return A pointer to a device of the family.
 *  \retval NULL    if no device of the family was found.
 */
OWI_device * FindFamily(unsigned char familyID, OWI_device * devices, unsigned char size)
{
    unsigned char i = 0;
    
    // Search through the array.
    while (i < size)
    {
        // Return the pointer if there is a family id match.
        if ((*devices).id[0] == familyID)
        {
            return devices;
        }
        devices++;
        i++;
    }
    // Else, return NULL.
    return NULL;
}


/*! \brief  Read the temperature from a DS1820 temperature sensor.
 *
 *  This function will start a conversion and read back the temperature
 *  from a DS1820 temperature sensor.
 *
 *  \param  bus A bitmask of the bus where the DS1820 is located.
 *  
 *  \param  id  The 64 bit identifier of the DS1820.
 *
 *  \return The 16 bit signed temperature read from the DS1820.
 */
signed int DS1820_ReadTemperature(unsigned char bus, unsigned char * id)
{
    signed int temperature;
    
    // Reset, presence.
    if (!OWI_DetectPresence(bus))
    {
        return DS1820_ERROR; // Error
    }
    // Match the id found earlier.
    OWI_MatchRom(id, bus);
    // Send start conversion command.
    OWI_SendByte(DS1820_START_CONVERSION, bus);
    // Wait until conversion is finished.
    // Bus line is held low until conversion is finished.
    while (!OWI_ReadBit(bus))
    {
    
    }
    // Reset, presence.
    if(!OWI_DetectPresence(bus))
    {
        return -1000; // Error
    }
    // Match id again.
    OWI_MatchRom(id, bus);
    // Send READ SCRATCHPAD command.
    OWI_SendByte(DS1820_READ_SCRATCHPAD, bus);
    // Read only two first bytes (temperature low, temperature high)
    // and place them in the 16 bit temperature variable.
    temperature = OWI_ReceiveByte(bus);
    temperature |= (OWI_ReceiveByte(bus) << 8);
    
    return temperature;
}


/*! \brief  Set the wiper position of a DS2890.
 *
 *  This function initializes the DS2890 by enabling the charge pump. It then
 *  changes the wiper position.
 *
 *  \param  position    The new wiper position.
 *
 *  \param  bus         The bus where the DS2890 is connected.
 *
 *  \param  id          The 64 bit identifier of the DS2890.
 */
void DS2890_SetWiperPosition(unsigned char position, unsigned char bus, unsigned char * id)
{
    // Reset, presence.
    if(!OWI_DetectPresence(bus))
    {
        return;
    }
    //Match id.
    OWI_MatchRom(id, bus);
    
    // Send Write control register command.
    OWI_SendByte(DS2890_WRITE_CONTROL_REGISTER, bus);
    
    // Write 0x4c to control register to enable charge pump.
    OWI_SendByte(0x4c, bus);
    
    // Check that the value returned matches the value sent.
    if (OWI_ReceiveByte(bus) != 0x4c)
    {
        return;
    }
    
    // Send release code to update control register.
    OWI_SendByte(DS2890_RELEASE_CODE, bus);
    
    // Check that zeros are returned to ensure that the operation was
    // successful.
    if (OWI_ReceiveByte(bus) == 0xff)
    {
        return;
    }
    
    // Reset, presence.
    if (!OWI_DetectPresence(bus))
    {
        return;
    }
    
    // Match id.
    OWI_MatchRom(id, bus);
    
    // Send the Write Position command.
    OWI_SendByte(DS2890_WRITE_POSITION, bus);
    
    // Send the new position.
    OWI_SendByte(position, bus);
    
    // Check that the value returned matches the value sent.
    if (OWI_ReceiveByte(bus) != position)
    {
        return;
    }
    
    // Send release code to update wiper position.
    OWI_SendByte(DS2890_RELEASE_CODE, bus);
    
    // Check that zeros are returned to ensure that the operation was
    // successful.
    if (OWI_ReceiveByte(bus) == 0xff)
    {   
        return;
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三国产精华液| 亚洲一区中文日韩| 亚洲天天做日日做天天谢日日欢| 精品国产自在久精品国产| 久久亚洲精品小早川怜子| 亚洲三级在线看| 日韩电影在线免费观看| 国产91精品露脸国语对白| 在线观看成人小视频| 精品久久国产字幕高潮| 中文字幕一区二区三区蜜月| 日韩av二区在线播放| 秋霞午夜鲁丝一区二区老狼| av毛片久久久久**hd| 制服视频三区第一页精品| 国产精品毛片久久久久久久| 亚洲午夜激情网站| 国产91在线观看丝袜| 欧美日韩成人一区| 亚洲视频图片小说| 日韩伦理av电影| 国产乱色国产精品免费视频| 欧美美女黄视频| 亚洲丝袜精品丝袜在线| 国产精品一区二区在线观看网站| 欧美美女激情18p| 亚洲免费资源在线播放| 国产成人自拍在线| 欧美日本一区二区在线观看| 亚洲欧美成人一区二区三区| 国内精品伊人久久久久影院对白| 欧美久久久一区| 亚洲精品国产一区二区精华液| 国产成人亚洲综合色影视| 日韩一区二区不卡| 亚洲国产精品嫩草影院| 99精品视频一区| 欧美国产日本韩| 激情五月婷婷综合网| 日韩午夜激情免费电影| 日本强好片久久久久久aaa| 一本久道中文字幕精品亚洲嫩| 国产午夜精品一区二区| 久久99精品久久只有精品| 欧美一区二区三区免费大片| 亚洲福利一区二区三区| 欧美三区在线观看| 亚洲午夜久久久久久久久久久| 欧美午夜精品一区| 性久久久久久久久| 欧美伦理电影网| 亚洲国产精品自拍| 91精品国产欧美一区二区| 亚洲主播在线观看| 国产v日产∨综合v精品视频| 久久久一区二区三区捆绑**| 国产又黄又大久久| 精品少妇一区二区三区在线视频| 琪琪久久久久日韩精品| 精品免费国产二区三区| 欧美自拍丝袜亚洲| 日本不卡视频在线| 欧美日韩国产高清一区二区| 裸体健美xxxx欧美裸体表演| 成人av中文字幕| ●精品国产综合乱码久久久久| 日本道精品一区二区三区| 夜夜嗨av一区二区三区网页| 欧美tickling网站挠脚心| 91一区一区三区| 极品尤物av久久免费看| 亚洲三级免费观看| 精品国产乱码久久久久久久久 | 精品日韩99亚洲| 色天天综合久久久久综合片| 精品一二三四区| 中文字幕综合网| 久久久久久久网| 欧美精品日韩精品| 91麻豆精品秘密| 国产精品一级片| 午夜激情久久久| 亚洲欧美日韩在线不卡| 精品对白一区国产伦| 欧美影片第一页| av不卡免费电影| 国产精品888| 免费高清在线视频一区·| 亚洲小说春色综合另类电影| 国产精品天干天干在观线| 91精品国产免费| 欧美日韩性生活| 99久久久国产精品| 国产老肥熟一区二区三区| 日本欧美一区二区在线观看| 亚洲最新在线观看| 综合分类小说区另类春色亚洲小说欧美| 精品精品国产高清一毛片一天堂| 欧美色综合久久| 色一情一乱一乱一91av| 成人国产精品免费观看视频| 国产在线播精品第三| 极品瑜伽女神91| 韩国精品一区二区| 久久精品国产亚洲一区二区三区 | 黄页网站大全一区二区| 日韩av在线播放中文字幕| 亚洲成人动漫在线观看| 亚洲一区二区精品久久av| 亚洲午夜在线观看视频在线| 一区二区三区欧美日韩| 亚洲乱码精品一二三四区日韩在线| 国产精品另类一区| 国产精品高潮久久久久无| 亚洲欧洲三级电影| 亚洲激情欧美激情| 亚洲午夜电影网| 三级在线观看一区二区| 爽好久久久欧美精品| 亚洲超碰精品一区二区| 日产国产高清一区二区三区| 久久精品久久精品| 国产精品69久久久久水密桃| 国产99一区视频免费| 97aⅴ精品视频一二三区| 在线影院国内精品| 51精品秘密在线观看| 精品久久久久久久久久久久久久久 | 国产精品美女一区二区| 中文字幕一区二区三区av | 亚洲欧洲精品成人久久奇米网| 久久精品国产99国产| 精品亚洲成a人| 99久久精品一区| 欧美日韩一区二区在线观看视频| 在线播放/欧美激情| 精品国产99国产精品| 国产精品美女一区二区三区| 一区二区三区久久| 男男成人高潮片免费网站| 精品伊人久久久久7777人| 国产成都精品91一区二区三| 94-欧美-setu| 91精品国产综合久久久久久久| 久久久久久免费| 一区二区三区不卡在线观看 | 91免费视频大全| 欧美肥妇free| 国产精品视频一二| 午夜电影网亚洲视频| 国产精品99久久不卡二区| 在线免费av一区| 久久中文娱乐网| 午夜一区二区三区视频| 精品一二三四在线| 欧美日韩一区二区三区在线看 | 99国产精品国产精品久久| 欧美一区二区视频在线观看2020| 国产女主播视频一区二区| 亚洲大型综合色站| 成人黄色在线网站| 欧美大片拔萝卜| 一区二区三区在线免费视频| 国产专区欧美精品| 欧美日韩精品一区二区三区四区 | 美国精品在线观看| 91福利在线看| 国产免费成人在线视频| 日韩精品一卡二卡三卡四卡无卡| 成人国产视频在线观看| 精品日本一线二线三线不卡| 一区二区三区产品免费精品久久75| 国产精品18久久久久久久网站| 91麻豆精品国产91久久久久久 | 亚洲线精品一区二区三区八戒| 国产成人av福利| 精品国产在天天线2019| 亚洲777理论| 在线一区二区三区做爰视频网站| 国产精品视频九色porn| 国产在线播放一区三区四| 日韩欧美中文字幕公布| 亚洲超碰精品一区二区| 欧美自拍偷拍一区| 亚洲一本大道在线| 91福利视频在线| 亚洲一区二区美女| 在线观看视频欧美| 亚洲线精品一区二区三区八戒| 91老师片黄在线观看| 中文字幕一区二区不卡| 丁香婷婷深情五月亚洲| 久久精品一区二区| 国产一区二区福利视频| 久久亚洲综合av| 国产精品一区三区| 中文字幕不卡在线播放| www.av亚洲| 亚洲品质自拍视频网站| 91在线观看污|