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

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

?? iic.c

?? 2.4G無線音箱的接收程序,采用ATMEGA8單片機和STS公司的無線模塊完成
?? C
字號:
/******************************************************************************
*
* Purpose:      IIC.c
*
* Creator:      Rob Lansbergen
*
* Version:		$Revision: 7 $
*
* File Name:	$Workfile: iic.c $
*
* Author:		Rob Lansbergen
*
* Check in:		$Author: Chong.cheeleong $
*
* The information is provided 揳s is?without any express or implied warranty  
* of any kind, * including warranties of merchantability, noninfringement of   
* intellectual property, or fitness for any particular purpose. In no event sha
* Wireless Sound Solutions and/or its affiliate companies, or its suppliers be 
* liable for any damages whatsoever arising out of the use of or inability to  
* use the information or the materials. Wireless Sound Solutions, its affiliate
* companies, and its suppliers further do not warrant the accuracy or          
* completeness of information, text, graphics, or other items contained within 
* materials. Wireless Sound Solutions, Inc., may make changes to materials, or 
* the products described within, at any time, without notice.                  
* ?007 Wireless Sound Solutions. All rights reserved. Wireless Sound Solutions
* STS and STS-wireless are trademarks of Wireless Sound Solutions.        
******************************************************************************/
#include "pgmspace.h"
#include "defines.h"

#ifndef USE_ATMEL_I2C

unsigned char i2cSlaveAddress = 0x80;

/*
I2C wiring
SCL on SCL_PIN : uC output
SDA on SDA_PIN : uc input
*/

/** on AT128 use extra delay **/
#ifndef MCU_ATMEGA128
	#define FAST_I2C	/* slow version cost 100 Byte */
#endif /* END MCU_ATMEGA128 */

#ifdef FAST_I2C			/* No delay */
	#define i2c_half_delay()
	#define i2c_delay()
#else
	#define i2c_half_delay()
	#define i2c_delay()  {\
	int i=0;\
	while (i !=10) i++;\
	}    ;
/*
#define i2c_half_delay(){
	int i=0;\
	while (i !=10) i++;\
}
#define i2c_delay()  {\
	int i=0;\
	while (i !=20) i++;\
}	 ;
*/
#endif /* END FAST_I2C */


// SET SCL to input instead of Output High
//#define SCL_H()         {I2C_PORT = I2C_PORT |SCL_PIN;}   /* SCL high */
//#define SCL_L()         {I2C_PORT = I2C_PORT & ~SCL_PIN;} /* Pull SCL down */

#define SCL_H()         {I2C_DDR = I2C_DDR & ~SCL_PIN;    I2C_PORT = I2C_PORT & ~SCL_PIN;}  /* SCL high using external pull-up (SDA is input)*/
#define SCL_L()         {I2C_DDR = I2C_DDR | SCL_PIN;     I2C_PORT = I2C_PORT & ~SCL_PIN;}  /* Pull SCL down */

#define SDA_H()         {I2C_DDR = I2C_DDR & ~SDA_PIN;    I2C_PORT = I2C_PORT & ~SDA_PIN;}  /* SDA high using external pull-up (SDA is input)*/
#define SDA_L()         {I2C_DDR = I2C_DDR | SDA_PIN;     I2C_PORT = I2C_PORT & ~SDA_PIN;}  /* Pull SDA down */

unsigned char SDA_IN(void)
{
	if ((I2C_PIN & SDA_PIN) == 0x00) return(0);
	else return(1);
}


void SDA_OUT(unsigned char b)
{
	if (b == 0) {SDA_L();}
	else {SDA_H();}
}

unsigned char i2c_error = 0;                 /* Last error */


/*
 * Makes sure that the bus is in a known condition. Returns 1 on success,
 * 0 if some other device is pulling on the bus.
 */

void i2c_init(void)
{
	SCL_H();
	SDA_H();
	i2c_error = 0;
	return; 
}


/*
 * Generates a start condition on the bus. Returns 0 on success, 1 if some
 * other device is holding the bus.
 */
 
unsigned char i2c_start(void)
{
	SCL_H();        /* EHO: 15-07-2003 in case of repeated start, first scl high */
	i2c_half_delay();
	SDA_L();        /* Pull SDA down... */
	i2c_half_delay();
	SCL_L();        /* ...and then SCL -> start condition. */
	i2c_half_delay();
	return 0;
}


/*
 * Generates a stop condition on the bus. Returns 0 on success, 1 if some
 * other device is holding the bus.
 */

unsigned char i2c_stop(void)
{
	SDA_L();        /* Pull SDA down if it was not down */
	i2c_half_delay();
	SCL_H();        /* Let SCL go up */
	i2c_half_delay();
	SDA_H();        /* ...and then SDA up -> stop condition. */
	i2c_half_delay();
	return (0);
}


/*
 * Clock out one bit.
 * Returns 0 on success, 1 if we lose arbitration.
 */

unsigned char i2c_bit_out(unsigned char bout)
{
	int i = 0;
	SDA_OUT(bout);		/* Put data out on SDA */
	i2c_half_delay();
	SCL_H();			/* Let SCL go up */
	i2c_delay();
	while (i != 1) i++;	/* SCL must be at least 500 ns High */
	SCL_L();			/* Pull SCL back down */
	i2c_delay();
	return 0;			/* OK */
}


/*
 * Clock in one bit.
 */

unsigned char i2c_bit_in(void)
{
	unsigned char bin;
	int i	=	0;
	SDA_H();
	i2c_half_delay();
	SCL_H();			/* Let SCL go up */
	i2c_delay();
	bin = SDA_IN();		/* Read in data */
	while (i !=	1) i++;	/* SCL must be at least 500 ns High */
	i2c_delay();
	SCL_L();			/* Pull SCL back up */
	i2c_delay();
	return bin;			/* Return the sampled bit */
}


/*
 * Send one byte on the bus. No start or stop conditions are generated here,
 * but i2c_error will be set according to the result.
 * Returns 0 on success, 1 if we lose arbitration or if the slave doesn't
 * acknowledge the byte. Check i2c_error for the actual result on error.
 */

unsigned char i2c_byte_out(unsigned char dat)
{
	unsigned char  bit_count;
	bit_count = 8;
	while(bit_count)
	{
		if (dat & 0x80)
		{
			if (i2c_bit_out(1)) return 1;
		}
		else
		{
			if (i2c_bit_out(0)) return 1;
		}
		dat <<= 1;
		bit_count--;
	}
	if (i2c_bit_in())
	{
		i2c_error = I2CERR_NAK;
		return 1;
	}
	return 0;
}


/*
 * Reads one byte in from the slave. Ack must be 1 if this is the last byte
 * to be read during this transfer, 0 otherwise (as per I2C bus specification,
 * the receiving master must acknowledge all but the last byte during a
 * transfer).
 */

unsigned char i2c_byte_in(unsigned char ack)
{
	unsigned char bit_count, byte_in;

	bit_count = 8;
	byte_in = 0;

	while(bit_count)
	{
		byte_in <<= 1;
		if (i2c_bit_in()) byte_in |= 0x01;
		bit_count--;
	}

	i2c_bit_out(ack);
	SDA_H();

	return byte_in;
}



unsigned char I2C_Write_Byte(unsigned char map,	unsigned char data)
{
	return 	(I2C_Write_Buf(map, &data, 1, 0));
}

/* Value is returned And will not damage the Receive buffer  */
/* This is to prevent a byte read can dammage the buffer that was read in I2C_read_buf*/

unsigned char I2C_Read_Byte(unsigned char map)
{
	unsigned char tmp;
	unsigned char result;
		
	/* we do not want to overwrite RX_Data_recv_array[0] */
	tmp = RX_Data_recv_array[0];
	
    I2C_Read_Buf(map, 1);
    
	result = RX_Data_recv_array[0];
	/* set back the old data */
	RX_Data_recv_array[0] = tmp;

    return (result);
}

/* read data is availeble in RX_Data_recv_array */
unsigned char I2C_Read_Buf (unsigned char map, unsigned char rx_count)
{
	if ( I2C_Write_Buf (map, &map, 0, 0))/* second map addres is dummy pointer no data writtten only i2cSlave address and map address*/
	{
		/* If send fails, abort but don't send a stop condition if we lost
		arbitration */

		if (i2c_error != I2CERR_LOST) i2c_stop();
		return 1;
	}

	SDA_H();        /* One of these may be low now, in which case the next */
	SCL_H();        /*   start condition wouldn't be detected so make */
	i2c_delay();    /*   sure that they're up and wait for one delay slot */

	if (i2c_recv(rx_count)) return 1;

	return (i2c_error ? 1 : 0);
}


/*
 * Read in 'count' bytes from slave 'addr'.
 * Returns 0 on success.
 */

unsigned char i2c_recv(unsigned char count)
{
	unsigned char byteptr, byte_in;

	if (i2c_start()) return 1;
	i2c_error = 0;
	byteptr = 0;

	byte_in = i2cSlaveAddress  | 0x01;

	if (i2c_byte_out(byte_in))
	{
		if (i2c_error == I2CERR_NAK) i2c_stop();
		return i2c_error;
	}

	while(count)
	{
		if (--count)
		{
			byte_in = i2c_byte_in(0);
		}
		else
		{
			byte_in = i2c_byte_in(1);   /* No ACK during last byte */
		}
		RX_Data_recv_array[byteptr] = byte_in;
		byteptr++;
	}

	i2c_stop();

	return (i2c_error ? 1 : 0);
}


unsigned char I2C_Write_Buf (unsigned char addr, unsigned char *buf, unsigned char count, unsigned char flash_type)

{
	unsigned char byte_out;
	const unsigned char __flash *fl_buf;
	
	if (flash_type) fl_buf = (const unsigned char __flash *)buf;

	if (i2c_start()) return 1;
	i2c_error = 0;

	byte_out = i2cSlaveAddress & 0xFE;     /* Ensure that it's a write address */
	if (i2c_byte_out(byte_out))
	{
		if (i2c_error == I2CERR_NAK )
		{
			i2c_stop();
			
			putstring("NA ");
			putdec(addr);
			putchar('=');
			if (flash_type) puthex(*fl_buf);
			else 			puthex(*buf);
			putchar('\r');
			
		}
		return i2c_error;
	}
	byte_out = addr;
	count = count+1;                    /* Include map addres to byte count */
	while(count)
	{
		
	     if (Use_I2C_Log_Write == 1)
	     {
			if (count != 1)
			{
				puthex(i2cSlaveAddress);
				putchar('-');
				putdec(addr++);
				putchar('=');
				if (flash_type) puthex(*fl_buf);
				else 			puthex(*buf);
				putstring(" (");
				if (flash_type) putdec(*fl_buf);
				else 			putdec(*buf);
				putstring(")\r");
			}
		}
		
		if (i2c_byte_out(byte_out))
		{
			if (i2c_error == I2CERR_NAK)
			{
				i2c_stop();
			}
			return i2c_error;
		}
		if (flash_type) byte_out = *fl_buf++;
		else 			byte_out = *buf++;
		count--;
	}

	i2c_stop();
	return 0;
}

#endif /* USE_ATMEL_I2C */


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一级片在线播放| 亚洲综合视频在线| 亚洲在线视频一区| 九一久久久久久| 色女孩综合影院| 国产亚洲欧美日韩在线一区| 午夜一区二区三区视频| 成人久久视频在线观看| 亚洲精品一区二区在线观看| 天堂成人免费av电影一区| 成人av在线播放网址| 久久免费午夜影院| 日本成人中文字幕在线视频| 在线亚洲高清视频| 亚洲人一二三区| 成a人片国产精品| 国产三级一区二区| 韩国av一区二区| 欧美丰满一区二区免费视频| 亚洲影院在线观看| 成人免费看片app下载| 久久嫩草精品久久久久| 蓝色福利精品导航| 欧美高清www午色夜在线视频| 亚洲精品免费播放| av午夜一区麻豆| 中文字幕欧美区| 成人精品一区二区三区四区| 国产亲近乱来精品视频| 国产精品99久久不卡二区| 日韩精品综合一本久道在线视频| 亚洲成人激情自拍| 欧美久久久久久蜜桃| 亚洲电影第三页| 欧美日韩极品在线观看一区| 亚洲综合成人在线| 欧美三级视频在线观看| 亚洲国产精品尤物yw在线观看| 色哟哟精品一区| 亚洲国产视频一区| 制服丝袜亚洲精品中文字幕| 日韩成人一级大片| 精品国产免费人成电影在线观看四季 | 国产在线不卡一区| 久久久久久久久久久99999| 狠狠色综合播放一区二区| 久久综合99re88久久爱| 风间由美一区二区av101| 中文字幕日本乱码精品影院| 日本丶国产丶欧美色综合| 亚洲在线视频免费观看| 日韩欧美激情一区| 成人精品国产免费网站| 亚洲人成小说网站色在线 | 大桥未久av一区二区三区中文| 国产欧美日韩在线| 91行情网站电视在线观看高清版| 亚洲一区免费观看| 亚洲精品在线一区二区| 91在线观看污| 日本免费新一区视频| 国产日韩欧美电影| 欧美在线一区二区三区| 麻豆91在线看| 国产精品国产三级国产aⅴ原创| 91玉足脚交白嫩脚丫在线播放| 亚洲成a天堂v人片| 久久午夜老司机| 精品视频一区二区不卡| 国产一区二区剧情av在线| 亚洲人成7777| 久久青草国产手机看片福利盒子| 日本精品一区二区三区四区的功能| 日韩二区在线观看| 一区在线播放视频| 精品国产免费人成在线观看| 欧美性极品少妇| 成人综合在线视频| 免费看欧美女人艹b| 一区二区三区免费在线观看| 精品三级av在线| 欧美性生交片4| 国产高清视频一区| 久草中文综合在线| 亚洲成人自拍一区| 最好看的中文字幕久久| 精品av久久707| 3atv一区二区三区| 一本大道久久a久久综合 | 99国产精品99久久久久久| 视频一区视频二区中文| 最新成人av在线| 2021国产精品久久精品| 6080亚洲精品一区二区| 91久久国产最好的精华液| 国产999精品久久| 国产麻豆一精品一av一免费| 日本欧美加勒比视频| 亚洲一区二区精品视频| 亚洲精品国产一区二区精华液| 国产三级欧美三级日产三级99| 日韩午夜电影在线观看| 91麻豆精品国产自产在线观看一区 | 国产高清久久久| 麻豆成人在线观看| 日韩精品欧美成人高清一区二区| 亚洲国产中文字幕在线视频综合| 中文字幕亚洲在| 国产精品久久三| 国产精品青草久久| 国产女主播视频一区二区| 国产欧美日韩在线| 国产精品免费久久| 国产精品电影院| 中文字幕一区二区三区不卡| 国产欧美日韩亚州综合| 日本一区二区三区四区| 国产精品天干天干在观线| 国产日韩欧美综合一区| 久久久久久亚洲综合影院红桃| 久久久蜜臀国产一区二区| 久久久久99精品一区| 欧美国产精品一区二区三区| 国产精品理论片| 综合激情网...| 夜夜操天天操亚洲| 日本亚洲三级在线| 精品伊人久久久久7777人| 久久99精品久久久| 国产成人综合精品三级| av电影在线观看完整版一区二区| 97se亚洲国产综合在线| 日本高清不卡aⅴ免费网站| 在线影视一区二区三区| 在线91免费看| 久久网站最新地址| 亚洲日韩欧美一区二区在线| 一区二区免费看| 久久99精品一区二区三区| 大桥未久av一区二区三区中文| 99免费精品视频| 欧美日韩一区二区三区免费看| 日韩精品专区在线| 国产精品久线在线观看| 亚洲福利一区二区| 国产乱一区二区| 欧美少妇一区二区| 久久网站热最新地址| 亚洲嫩草精品久久| 久久精品国产久精国产| 国产精品91xxx| 欧美人妖巨大在线| 国产精品久久一卡二卡| 亚洲午夜精品网| 韩日av一区二区| 欧美午夜在线一二页| 久久中文字幕电影| 亚洲国产一区二区a毛片| 国产一区二区剧情av在线| 欧美性猛交xxxxxx富婆| 国产精品久久久久三级| 日本人妖一区二区| 91久久线看在观草草青青| 精品久久久久久久久久久久久久久久久 | 一本到一区二区三区| 日韩一二在线观看| 一区二区在线观看视频在线观看| 毛片av一区二区| 欧美视频一区在线观看| 国产精品亲子伦对白| 久久精品999| 欧美日本在线看| 国产精品久久久久久亚洲伦| 狠狠色丁香九九婷婷综合五月| 欧美日本一区二区三区| 亚洲精品乱码久久久久久日本蜜臀| 国产一二精品视频| 欧美日韩国产乱码电影| 亚洲精品伦理在线| 97aⅴ精品视频一二三区| 国产精品天天看| 国产一区二区剧情av在线| 日韩三级电影网址| 丝袜亚洲精品中文字幕一区| 日本韩国视频一区二区| 国产精品短视频| 成人午夜免费av| 中文字幕av一区 二区| 国产毛片一区二区| 久久天堂av综合合色蜜桃网| 激情综合网最新| 欧美大片国产精品| 精品影院一区二区久久久| 日韩欧美一区二区在线视频| 三级久久三级久久| 51精品秘密在线观看| 奇米影视7777精品一区二区| 欧美一区二区免费| 蜜桃av一区二区三区| 欧美成人一区二区三区在线观看 |