📄 main.c
字号:
#define IN_MAIN
#include "config.h"
#include "I2C.h"
#pragma import(__use_no_semihosting_swi) //don't delete this line
#define LED1CON (1<<22) // P0.22引脚控制LED1,低电平点亮
#define I2Cn_n 0 // I2C0
#define I2Cn_MODE 0 // I2C从模式
#define I2Cn_Fi2c 100000 // I2C时钟速率为100K
#define I2Cn_slot 0 // I2C使用中断通道0
#define CSI24WC02 0xb0 // 定义从机地址,忽略通用地址
uint8 eeprom[256]; // 定义EEPROM存储单元,256字节
/*********************************************************************************************************
** Function name: IRQ_Exception
**
** Descriptions: interrupt exceptional handler , change it as needed
** don't delete this function
********************************************************************************************************/
void IRQ_Exception(void)
{
}
/*********************************************************************************************************
** 函数名称:Main()
** 函数功能:使用LPC2103模拟EEPROM器件CSI24WC02。LPC2103具有硬件I2C接口,使用其从方式进行I2C器件模拟,
** 本例使用了256字节的RAM作为存储单元,为了与24WC02区分,将从机地址设置为0xb0。
** 说明:将主、从机的P0.3、P0.2、GND相连,注意要外加上拉电阻。
********************************************************************************************************/
void Main(void)
{
TargetInit(VPBDIV_DATA, PLLCFG_DATA, MAMTIM_DATA); // don't delete
while((PLLSTAT & (1 << 10)) == 0); // can delete
PINSEL0 = 0x00000000; // 设置I/O口为GPIO模式
PINSEL1 = 0x00000000;
I2C_buf = eeprom;
//初始化I2C为从机模式
I2C_Init(I2Cn_n,I2Cn_MODE,I2Cn_Fi2c,CSI24WC02,I2Cn_slot);
while(1); // 等待中断
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -