i2c_test.c

来自「IARSOURCECODE是基于LPC2478嵌入式软件IAR EWARM V4」· C语言 代码 · 共 45 行

C
45
字号
#include "LPC2468.h"                        /* LPC24xx definitions */
#include "type.h"
#include "irq.h"
#include "target.h"
#include "timer.h"
#include "uart0.h"

#include "I2C.h"

/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
    BYTE i,chr_i2c;

    TargetResetInit();
    UART0Init(9600);
    enable_timer(0);

    I2CInit();

    for(i=0;i<255;i++)I2CWriteByte(i,i);              // 通过I2C写入EEPROM

    for(i=0;i<255;i++)
    {
      chr_i2c = I2CReadByte(i);                       // 通过I2C读出EEPROM
      if(chr_i2c != i)
      {
        UART0_puts("Found a error!\r\n");
        return -1;
      }

      UART0_PrintNum(chr_i2c,16);
      UART0_puts("  ");
    }

    UART0_puts("\r\nI2C test successed!\r\n");

}

/*****************************************************************************
**                            End Of File
*****************************************************************************/

⌨️ 快捷键说明

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