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

📄 main.c

📁 I2C的实现代码。包括源程序、头文件。适合在arm上做仿真实现。
💻 C
字号:
#include "i2c.h"
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"

#define WRDATA	    (1)
#define POLLACK     (2)
#define RDDATA	    (3)
#define SETRDADDR   (4)

#define IICBUFSIZE 0x20

void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);      
void HaltDabort(void);
void Rd24C040(U32 slvAddr,U32 addr,U8 *data);
void Wr24C040(U32 slvAddr,U32 addr,U8 data);

U8 _iicData[IICBUFSIZE];
volatile int _iicDataCount;
volatile int _iicStatus;
volatile int _iicMode;
int _iicPt;

void __irq IicInt(void);

void Main(void)
{
    unsigned int i,j;
    static U8 data[256];
    unsigned char *src, *dst;
    unsigned int memSum;

    rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
    ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif

  
    Port_Init();
  //    Isr_Init();
    Uart_Init(0,57600);
    Uart_Select(0);
  /*
    Delay(0);  //calibrate Delay()
    Led_Display(7);
    Delay(1000);  //calibrate Delay()
    Led_Display(0);
    Delay(5000);  //calibrate Delay()
    Led_Display(7);
*/
    Uart_Printf("[IIC Test using KS24C02]\n");

   // pISR_IIC=(unsigned)IicInt;
    rINTMSK=~(BIT_GLOBAL|BIT_IIC);

    rIICCON=(1<<7)|(0<<6)|(1<<5)|(0xf);
    //Enable interrupt, IICCLK=MCLK/16, Enable ACK
    //40Mhz/16/(15+1) = 257Khz	
   // rIICADD=0xa0;   // S3C44B0X slave address

    //rIICSTAT=0x10;

    Uart_Printf("trying to Write 7 test data into KS24C080\n");


for(i=0;i<255;i++)
   data[i]=i;

Uart_Printf("\n the data written to 24c02 is:\n ");
   for(i=0;i<7;i++){
Uart_Printf("%d\t", data[i]);
}
Write24c02((unsigned char *)data,0,7);
for(i=0;i<255;i++)
   data[i]=0;

Read24c02((unsigned char *)data,0,7); 

Uart_Printf("\n the data read from  24c02 is:\n ");
   for(i=0;i<7;i++){
Uart_Printf("%d\t", data[i]);
   }
while(1);
    
}



/******************************************************************/

void Isr_Init(void)
{
    U32 i;
    
    pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;
    
     for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
    {
	*((volatile unsigned *)i)=0xEA000000+0x1FFE;
    }

    rINTCON=0x5;	  // Non-vectored,IRQ enable,FIQ disable    

    rINTMOD=0x0;	  // All=IRQ mode
    rINTMSK|=BIT_GLOBAL|BIT_EINT3;	  // All interrupt is masked.
}


void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception!!!\n");
    while(1);
}

void HaltSwi(void)
{
    Uart_Printf("SWI exception!!!\n");
    while(1);
}

void HaltPabort(void)
{
    Uart_Printf("Pabort exception!!!\n");
    while(1);
}

void HaltDabort(void)
{
    Uart_Printf("Dabort exception!!!\n");
    while(1);
}

⌨️ 快捷键说明

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