⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2c.c

📁 DSP的I2C模块C程序
💻 C
字号:
/*********************************************************************************
* DEC6713_EEPROM.C	ver1.0	     							                            *
* Copyright	2008 by Hunan Geoson Hi-Tech Ltd.
* All rights reserved. Property of Hunan Geosun Hi-Tech Ltd.			                *
* Write by:	Zhili.Zeng
* Email:	zzl290@163.com								                                *
*********************************************************************************/ 

/*********************************************************************************
Program for test I2C module.
Bit Polling Mode.
Writting and reading operation on I2C device. 	
*********************************************************************************/

#define I2C_SLAVE_ADDRESS 0x50	//Set slave address of i2c device
//#define I2C_DataLen 4			//The number of bytes you access a time

#include "i2c.h"
#include <stdio.h>				//Used only for debug 

unsigned short I2C_Add=0x0020;			//The memory address  to be accessed
unsigned char I2C_DataLen 		= 4;	//The number of bytes you access a time
unsigned char I2C_DataSend[4] 	= {0x00,0xaa,0x55,0xff};//The data to be write 
unsigned char I2C_DataRec[4] 	= {0,0,0,0};		//The data you read			

unsigned char I2C_ByteSend	=0x55;	//The byte to be write
unsigned char I2C_ByteRec	=0;		//The byte you read


/*********************************************************************************
******************************* This is a example. *******************************
***You may modify the value of I2CPSC\I2CCLKH\I2CCLKL in I2C_Init() before use.***
****These registers are used to set data transfer rate,from 10kbps to 400kbps.****
*********************************************************************************/

main()
{
	unsigned int j;
	    
	I2C_Init();
	
	//Write or read more than one byte a time.
	I2C_WriteData(0,I2C_DataSend,I2C_DataLen);
	printf("\nWrite data is over.");
	printf("\nThe Data you write is %x,%x,%x,%x",I2C_DataSend[0],I2C_DataSend[1],I2C_DataSend[2],I2C_DataSend[3]);			
	I2C_ReadData(0,I2C_DataRec,I2C_DataLen);
	printf("\nReading data is over.");
	printf("\nThe Data you read is %x,%x,%x,%x",I2C_DataRec[0],I2C_DataRec[1],I2C_DataRec[2],I2C_DataRec[3]);
	
	//Write or read one byte a time.
	I2C_WriteByte(0x0200,&I2C_ByteSend);
	printf("\nReading data is over.");
	printf("\nThe byte you write is %x",I2C_ByteSend);
	I2C_ReadByte(0x0200,&I2C_ByteRec);
	printf("\nReading data is over.");
	printf("\nThe byte you read is %x",I2C_ByteRec);
	
	for(j=0;j<200000;j++);
//	while(1);
}

/*********************************************************************************
    End of  DEC6713_EEPROM.C
*********************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -