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

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

?? i2c_master_example.c

?? LPC單片機I2C編程
?? C
字號:
//------------------------------------------------------------------------------
// Keil Software, Inc.
// 
// Project: 	EXAMPLE I2C PROGRAM for Philips 87LPC764
//
// Filename: 	I2C_Master_Example.c
// Version: 	1.0.0
// Description:	This file contains all the necessary routines to communicate
//				to I2C slave devices on the I2C bus.  These routines use the
//				built in I2C hardware of the Philips MCUs.  See application
//				note for futher discussion on I2C.
//				
//				This is example will communicate to a I2C devices.
//				Device 1 will be a serial ADC / DAC from Philips (PCF8591)
//				The example will gather the data and print it out the serial
//				port (9600, 8, N, 1).
//
//				CPU Frequency: 11.0592 MHz
//
// Copyright 2000 - Keil Software, Inc.
// All rights reserved.
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Header files
//------------------------------------------------------------------------------
#include "REG764.H"							// Header file for LPC764 MCU
#include <STDIO.H>							// Standard I/O header file

sbit  P1_2 	= 0x92;							// Define the individual bit
sbit  P1_3 	= 0x93;							// Define the individual bit
sbit  P1_4 	= 0x94;							// Define the individual bit

//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
											// Get high byte macro
#define high_byte(x)		((x & 0xFF00) >> 8)

//------------------------------------------------------------------------------
// Value Definitions
//------------------------------------------------------------------------------
#define 	TRUE			0x01			// Value representing TRUE
#define		FALSE			0x00			// Value representing FALSE
#define 	ON				0x01			// Value representing ON
#define		OFF				0x00			// Value representing OFF
#define 	HIGH			0x01			// Value representing ON
#define		LOW				0x00			// Value representing OFF

#define  	DELAY_WRITE		1000			// Value for delay write time
#define  	DELAY_BLINK		25000			// Value for delay time - blink

//------------------------------------------------------------------------------
// I/O Port Defines
//------------------------------------------------------------------------------
#define  	LED				P1_4			// LED Output

//------------------------------------------------------------------------------
// I2C Peripheral Function Prototypes
//------------------------------------------------------------------------------
											// Writes a byte to the EEPROM
void write_byte (unsigned char data_out, unsigned int address);
											// Reads a bytee from the EEPROM
unsigned char read_byte (unsigned int address);

//------------------------------------------------------------------------------
// I2C Function Prototypes
//------------------------------------------------------------------------------
bit write_byte_I2C (unsigned char data_out);// Write single byte over I2C
bit	read_byte_I2C (unsigned char *data_in);	// Read single byte from I2C
											// Send the I2C address and start signal
bit send_slave_address_I2C (unsigned char slave_address);
void stop_I2C (void);						// Stops a I2C data transfer
											// Resends the I2C start signal
bit restart_I2C (unsigned char slave_address);	

//------------------------------------------------------------------------------
// Support Function Prototypes
//------------------------------------------------------------------------------
void initialize_system (void);				// Initializes MCU, except I2C
void delay_time (unsigned int time_end);    // To pause execution for pre-determined time

//------------------------------------------------------------------------------
// MAIN FUNCTION 
//------------------------------------------------------------------------------
void main (void)
{
	unsigned int eeprom_address;

	initialize_system();					// Initialize RS-232 and rest of system

	printf("\n\rKeil Software, Inc.\n\r");	// Display starup message
	printf("LPC764 MCU I2C Example Test Program\n\r");
	printf("Version 1.0.0\n\r");
	printf("Copyright 2000 - Keil Software, Inc.\n\r");
	printf("All rights reserved.\n\n\r");

	P1M1  = 0x0C;							// Set Port 1 Open Drain
	P1M2  = 0x0C;

	I2CFG = 0x22;							// Config byte: 0 MAS CLRT1 T1, 00 CC  (page 16)
											// In our case the config byte is:
										 	// Slave bit 	(7): 0 (we are not a slave)
										 	// Master bit 	(6): 0 (we are a master)
										 	// Clear T1 	(5): 1 (Clear TI) 
										 	// TI Run 		(4): 0 (set TI to run)
										 	// Not used		(3): 0 		
											// Not used		(2): 0 
										 	// CT 1			(1): 1 (Set for highest CPU clock rate)
											// CT 0			(0): 0 



	printf("Writing data to EEPROM....");
	for (eeprom_address = 0; eeprom_address < 75; eeprom_address++)
		write_byte((unsigned char)eeprom_address + 0x30, eeprom_address);

	printf("Done!\n\r");
	printf("Reading from EEPROM...ASCII table!\n\r");


	while (TRUE)							// Infinite loop, never exits
	{
		for (eeprom_address = 0; eeprom_address < 75; eeprom_address++)
		{
			delay_time(DELAY_BLINK);		// Blink LED with delay
			LED = ON;
			delay_time(DELAY_BLINK);
			LED = OFF;

			printf("Address: %3u	Character: %c\n\r", eeprom_address, read_byte(eeprom_address));
		}
	}
}

//------------------------------------------------------------------------------
// I2C Peripheral Function Prototypes
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Procedure:	write_byte
// Inputs:		data out, address
// Outputs:		none
// Description:	Writes a byte to the EEPROM given the address 
//------------------------------------------------------------------------------
void write_byte (unsigned char data_out, unsigned int address)
{
  	send_slave_address_I2C(0xA0); 			// Send I2C Start Transfer
       					         			// Send identifier I2C address
   	write_byte_I2C(high_byte(address)); 	// Send address to EEPROM
   	write_byte_I2C((unsigned char)address); // Send address to EEPROM
   	write_byte_I2C(data_out);          		// Send low byte to EEPROM
   	stop_I2C();                   			// Send I2C Stop Transfer
   	delay_time(DELAY_WRITE);       			// Delay a period of time to write
}

//------------------------------------------------------------------------------
// Procedure:	read_byte
// Inputs:		address
// Outputs:		output byte
// Description:	Reads a byte from the EEPROM given the address 
//------------------------------------------------------------------------------
unsigned char read_byte (unsigned int address)
{
   	unsigned char data_in;

  	send_slave_address_I2C(0xA0); 			// Send I2C Start Transfer
   					              			// Send identifer I2C address
   	write_byte_I2C(high_byte(address));   	// Send address to EEPROM
   	write_byte_I2C((unsigned char)address); // Send address to EEPROM
   	restart_I2C(0xA1);         				// Send identifer I2C address
   	read_byte_I2C(&data_in);     			// Read byte
   	stop_I2C();                   			// Send I2C Stop Transfer

   	return data_in;                 
}


//------------------------------------------------------------------------------
// I2C FUNCTIONS
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Procedure:	write_byte_I2C
// Inputs:		data output byte
// Outputs:		TRUE for Pass, FALSE for Failure
// Description:	Writes one byte over the I2C bus
//------------------------------------------------------------------------------
bit write_byte_I2C (unsigned char data_out)
{
	unsigned char bit_index;

	while (!ATN);						// Wait for I2C ready
	for (bit_index = 0; bit_index < 8; bit_index++)
	{
		I2DAT = data_out;				// Output MSB to the I2C bus
		while (!ATN);					// Wait for the bit to be sent
		if (!DRDY) return FALSE;		// If bus not ready for data then error
		data_out <<= 1;					// Shift data out right by one bit
	}
	
	I2CON = 0xA0;						// Clear the TXD active flag and switch to RXD
	while (!ATN);						// Wait for the ACK from the I2C
	
	if (!RDAT) return TRUE;				// If the bit is high then we were not
										// acknoledged from the slave device
										// return error, else if low then 
										// the data was received OK
	return FALSE;						// If bus no ACK then error
}

//------------------------------------------------------------------------------
// Procedure:	write_byte_I2C
// Inputs:		none
// Outputs:		TRUE for Pass, FALSE for Failure
// Description:	Reads one byte over the I2C bus from the specified address
//------------------------------------------------------------------------------
bit	read_byte_I2C (unsigned char *data_in)
{
	unsigned char bit_index, byte_in;
	bit data_i2c;

	byte_in = 0x00;						// Clear the input buffer
	for (bit_index = 0; bit_index < 8; bit_index++)
	{
		byte_in <<= 1;					// Shift data right by one bit
		data_i2c = I2DAT;
		data_i2c = RDAT;
		while (!ATN);					// Wait for the bit to be read
		if (!DRDY) return FALSE;		// If bus not ready for data then error
		byte_in |= data_i2c;
	}

	// No Ack need with the 24LC65!

	*data_in = byte_in;
	return TRUE;
}

//------------------------------------------------------------------------------
// Procedure:	send_slave_address_I2C
// Inputs:		slave_address
// Outputs:		TRUE for Pass, FALSE for Failure
// Description:	Sends slave address for data transfer on the bus
//------------------------------------------------------------------------------
bit send_slave_address_I2C (unsigned char slave_address)
{
	unsigned char bit_index;

	I2CFG = 0x52;							// Config byte: 0 MAS CLRT1 T1, 00 CC  (page 16)

	while (!ATN);							// Loop until we receive an attention flag

	if (MASTER)
	{										// Send all eight bits over the I2C bus
		I2DAT = slave_address;				// Output MSB to the I2C bus
		I2CON = 0x1C;						// Clear the CARL, START, and STOP flags
		slave_address <<= 1;				// Shift address right by one bit
	
		while (!ATN);						// Wait for the MSB to be sent
		for (bit_index = 0; bit_index < 7; bit_index++)
		{
			I2DAT = slave_address;			// Output MSB to the I2C bus
			while (!ATN);					// Wait for the bit to be sent
			if (!DRDY) return FALSE;		// If bus not ready for data then error
			slave_address <<= 1;			// Shift address right by one bit
		}

		I2CON = 0xA0;						// Clear the TXD active flag and switch to RXD
		while (!ATN);						// Wait for the ACK from the I2C

		if (!RDAT) return TRUE;				// If the bit is high then we were not
											// acknoledged from the slave device
											// return error, else if low then 
											// the address was sent OK
	}
	return FALSE;							// If we do not return true, then error
											// Cause of error might be due to an 
											// invalid bus if RDAT is not LOW
}

//------------------------------------------------------------------------------
// Procedure:	stop_I2C
// Inputs:		none
// Outputs:		none
// Description:	Stops the data transfer on the bus
//------------------------------------------------------------------------------
void stop_I2C (void)
{
	MASTRQ = 0;								// Clear the Master Request	bit
	I2CON = 0x31;							// Clear the data ready flag, generate a I2C Bus Stop
	while (!ATN);							// Loop until we receive an attention flag
	I2CON = 0x20;							// Clear the data ready flag
	while (!ATN);							// Loop until we receive an attention flag
	I2CON = 0x94;							// Clear the bus arb bit, I2C stop, and deactive the Xmit
	I2CFG = 0x22;							// Config byte: 0 MAS CLRT1 T1, 00 CC  (page 16)
}

//------------------------------------------------------------------------------
// Procedure:	restart_I2C
// Inputs:		slave_address
// Outputs:		TRUE for Pass, FALSE for Failure
// Description:	Restarts I2C with slave address (ie. control byte)
//------------------------------------------------------------------------------
bit restart_I2C (unsigned char slave_address)
{
	unsigned char bit_index;

	I2CON = 0x22;							// Send repeated start
	while (!ATN);							// Wait for the ACK
	I2CON = 0x20;							// Clear data ready
	while (!ATN);							// Wait for the ACK

											// Send all eight bits over the I2C bus
	I2DAT = slave_address;					// Output MSB to the I2C bus
	I2CON = 0x1C;							// Clear the CARL, START, and STOP flags
	slave_address <<= 1;					// Shift address right by one bit
	
	while (!ATN);							// Wait for the MSB to be sent
	for (bit_index = 0; bit_index < 7; bit_index++)
	{
		I2DAT = slave_address;				// Output MSB to the I2C bus
		while (!ATN);						// Wait for the bit to be sent
		if (!DRDY) return FALSE;			// If bus not ready for data then error
		slave_address <<= 1;				// Shift address right by one bit
	}
	I2CON = 0xA0;							// Clear the TXD active flag and switch to RXD
	while (!ATN);							// Wait for the ACK from the I2C
	if (!RDAT) return TRUE;					// If the bit is high then we were not
											// acknoledged from the slave device
											// return error, else if low then 
											// the address was sent OK
	return FALSE;
}

//------------------------------------------------------------------------------
// SUPPORT FUNCTIONS
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Procedure:	initialize_system
// Inputs:		none
// Outputs:		none
// Description:	Initializes embedded system MCU LPC764
//------------------------------------------------------------------------------
void initialize_system (void)
{
	// Initialize the serial port (1200, 8, N, 1) [see page 32 of data sheet]
	PCON &= 0x7F;							// Clear bit 7 of the PCON register (SMOD1 = 0)  
	SCON = 0x50;							// 0101,0000 (Mode 1 and RxD enable)			
	TMOD = 0x20;							// Timer #1 in autoreload 8 bit mode
	TCON = 0x40;							// Set Timer #1 to run mode
	TH1 = 0xCC;								// Baud rate is determined by
											// Timer #1 overflow rate
											// Baud Rate = (Fcpu / 192) / (256 - TH1)
											// Fcpu = 12.00 MHz (XTAL)
	TR1 = 1;								// Turn on Timer 1
	TI = 1;									// Set UART to send first char
}

////////////////////////////////////////////////////////////////////////////////
// 	Routine:	delay_time
//	Inputs:		counter value to stop delaying
//	Outputs:	none
//	Purpose:	To pause execution for pre-determined time
////////////////////////////////////////////////////////////////////////////////
void delay_time (unsigned int time_end)
{
	unsigned int index;
	for (index = 0; index < time_end; index++);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
正在播放亚洲一区| 一区二区在线电影| 色婷婷激情久久| 国内精品在线播放| 视频一区二区三区在线| 亚洲香肠在线观看| 亚洲综合999| 亚洲国产aⅴ天堂久久| 国产一区二区三区四区在线观看| 久久精品国产**网站演员| 久久99热狠狠色一区二区| 91视频免费观看| 色屁屁一区二区| 国产精品视频线看| 国产精品国产三级国产普通话蜜臀 | 丝袜美腿高跟呻吟高潮一区| 丁香啪啪综合成人亚洲小说| 东方欧美亚洲色图在线| 一本到三区不卡视频| 久久久久国色av免费看影院| 欧美国产97人人爽人人喊| 中文字幕欧美国产| 国产美女精品在线| 欧美成人猛片aaaaaaa| 欧美精品一区二区三区在线| 国产精品久久久久精k8| 国产成人av一区二区三区在线观看| www.欧美亚洲| 7777精品伊人久久久大香线蕉的 | 欧美成人女星排行榜| 日本视频在线一区| 国产精品538一区二区在线| 99久久精品情趣| 在线成人av网站| 久久蜜臀精品av| 九色综合狠狠综合久久| 岛国一区二区在线观看| 亚洲国产成人在线| 成人免费观看av| 亚洲视频免费在线观看| 麻豆成人久久精品二区三区红 | 在线中文字幕一区| 欧美成人国产一区二区| 久久99精品视频| 国产清纯白嫩初高生在线观看91| 亚洲一区二区五区| 欧美久久久久中文字幕| 免费精品视频在线| 欧美少妇bbb| 国产日韩精品一区二区三区| 国产iv一区二区三区| 亚洲欧洲韩国日本视频| 国产激情一区二区三区桃花岛亚洲| www亚洲一区| 奇米精品一区二区三区在线观看| 日韩一区二区免费在线观看| 亚洲美女视频在线观看| 国产98色在线|日韩| 亚洲天堂av一区| 欧美精品18+| 国产一区二区按摩在线观看| 亚洲欧美一区二区视频| 欧美视频在线一区二区三区 | 激情文学综合网| 国产欧美精品一区二区三区四区 | 亚洲欧美乱综合| 9191国产精品| 丁香一区二区三区| 亚洲1区2区3区4区| 一本到不卡免费一区二区| 琪琪一区二区三区| 中文字幕一区不卡| 欧美一区二区三区视频在线| 免费人成在线不卡| 国产精品久久网站| 日韩欧美国产系列| 毛片一区二区三区| 亚洲丝袜美腿综合| 欧美v日韩v国产v| 在线观看亚洲专区| 亚洲综合色噜噜狠狠| 欧美变态凌虐bdsm| 欧洲一区二区av| 风间由美一区二区av101| 日日骚欧美日韩| 中文字幕五月欧美| 久久亚洲私人国产精品va媚药| 色94色欧美sute亚洲线路二| 国产精品亚洲第一| 奇米色777欧美一区二区| 一区二区三区在线视频播放| 欧美视频一区在线观看| 高清久久久久久| 久草精品在线观看| 视频一区视频二区在线观看| 一区在线观看视频| 国产欧美日韩综合| 久久综合久久综合亚洲| 欧美丰满少妇xxxxx高潮对白| 97久久超碰精品国产| 国产精品88av| 狠狠久久亚洲欧美| 蜜臀av性久久久久av蜜臀妖精| 亚洲图片有声小说| 一区二区三区日韩精品| 亚洲图片你懂的| 亚洲私人黄色宅男| 国产精品久久久久国产精品日日 | 国产精品久久久久久久久久久免费看| 日韩欧美中文字幕制服| 91精品在线麻豆| 69av一区二区三区| 91麻豆精品国产| 欧美一级视频精品观看| 欧美一区二区三区免费观看视频 | 午夜视黄欧洲亚洲| 久久久久久久久蜜桃| 国产精品视频你懂的| 国产精品美女久久久久aⅴ| 久久久久久久久久久久久女国产乱 | 欧美一区二区久久| 欧美一区二区在线免费播放| 5566中文字幕一区二区电影| 日韩欧美成人激情| 精品国一区二区三区| 国产亚洲1区2区3区| 欧美日韩你懂得| av在线播放一区二区三区| av中文字幕亚洲| 在线视频综合导航| 欧美久久久一区| 日韩精品一区二区在线| 国产亚洲精品中文字幕| 中文字幕二三区不卡| 亚洲免费大片在线观看| 午夜婷婷国产麻豆精品| 久久99久久99小草精品免视看| 国产一区中文字幕| 99精品国产91久久久久久| 色噜噜狠狠一区二区三区果冻| 欧美日韩国产一二三| 色悠久久久久综合欧美99| 欧美亚洲高清一区二区三区不卡| 91精品国产色综合久久ai换脸| 亚洲精品在线三区| 亚洲欧美日韩国产中文在线| 五月综合激情日本mⅴ| 国产乱子伦视频一区二区三区| 99久久久精品| 日韩午夜激情电影| 中文字幕一区二区三区四区不卡| 亚洲成人av资源| 国产乱一区二区| 欧美日韩在线免费视频| 精品国产电影一区二区| 综合色中文字幕| 久久精品久久精品| 91免费国产在线观看| 日韩免费观看2025年上映的电影| 中文成人av在线| 蜜桃精品在线观看| 99re成人在线| 日韩视频永久免费| 亚洲精品美腿丝袜| 国产在线精品一区二区不卡了| 久久久久九九视频| 五月开心婷婷久久| 成人激情小说乱人伦| 成人综合在线视频| 91精品国产综合久久精品| 亚洲人午夜精品天堂一二香蕉| 美女一区二区久久| 欧美在线你懂的| 国产精品国产a级| 国产一区二区三区黄视频| 在线成人免费视频| 亚洲综合一区二区| 99久久伊人精品| 国产午夜精品一区二区三区视频 | 欧美精品欧美精品系列| 国产精品久久久久久久岛一牛影视| 麻豆精品在线播放| 欧美日韩一区在线观看| 中文字幕佐山爱一区二区免费| 国产成人免费视频一区| 日韩美女视频在线| 免费成人av在线| 欧美美女直播网站| 亚洲成av人片www| 在线视频你懂得一区二区三区| 国产精品第13页| 成人午夜伦理影院| 中文一区二区完整视频在线观看| 狠狠色丁香婷综合久久| 精品国产91久久久久久久妲己| 麻豆一区二区99久久久久| 日韩一级片网站| 麻豆视频观看网址久久| 精品理论电影在线观看 | 精品美女在线观看|