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

📄 main.c

📁 在keil-ARM环境下对ARM7处理器编译成功的I2C总线程序
💻 C
字号:
#include "config.h"
#include "Uart.h"
#include "I2CINT.h"


/*********************************************************************************************************
** Function name:		I2cInit
** Descriptions:		I2C初始化
** input parameters:    uiFi2c	I2C总线频率(最大400K)
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
void I2CInit(uint32 uiFi2c)
{
	if (uiFi2c > 400000)
		uiFi2c = 400000;
		
   	PINSEL0 = (PINSEL0 & (~0xF0)) | 0x50; 	                            /* 设置I2C引脚连接              */
	I2SCLH  = (Fpclk / uiFi2c + 1)  / 2;						        /* 设定I2C时钟 					*/
	I2SCLL  = (Fpclk / uiFi2c) / 2;
	
	I2CONCLR = 0x2C;
	I2CONSET = 0x40;									                /* 使能主I2C 					*/
	
	/* 
	 * 设置I2C中断 
	 */
	VICIntSelect = 0x00000000;							                /* 设置所有通道为IRQ中断 		*/
	VICVectCntl0 = (0x20 | 0x09);						                /* I2C通道分配最高优先级        */
	VICVectAddr0 = (int32)IRQ_I2C;						                /* 设置I2C中断向量 				*/
	VICIntEnable = 1 << 9;							                    /* 使能I2C中断 					*/
}

int main(void)
{
	char temp;
	uint8 s[9]={0x00,0x12,0x40,0x42,0x09,0x29,0x04,0x08,0x08};
	uint8 s1[7]={0};
	UARTInit();
	I2CInit(40000);


	temp=I2C_WriteNByte(0xa2,1,0,s,9);
	UART0SendByte(temp);
		
	temp=I2C_ReadNByte(0xa2,1,2,s1,7);
	UART0SendByte(temp);

	for(temp=0;temp<7;temp++)
		UART0SendByte(s1[temp]);
	return 0;
}

⌨️ 快捷键说明

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