C8051F060读写EEPROM芯片24lc256源程序.docVIP

  • 9
  • 0
  • 约7.85千字
  • 约 13页
  • 2018-01-01 发布于河南
  • 举报
C8051F060读写EEPROM芯片24lc256源程序

C8051F060读写EEPROM芯片24lc256源程序 // // F06x_SMBus_EEPROM.c // #include C8051F060.h // SFR declarations #includeintrins.h #includemath.h #includeabsacc.h #define SYSCLK 3062500L // System clock frequency in Hz #define SMB_FREQUENCY 10000L // Target SCL clock rate // This example supports between 10kHz and 100kHz // sbit RX2 = P1^6; // RX2 on P1.6 sbit SDA = P0^6; // SMBus on P0.6 sbit SCL = P0^7; // and P0.7 #define Dealay5us _nop_(); _nop_(); _nop_(); _nop_(); //延时5us #define WriteDeviceAddress 0xa2 // 写I2C外围器件的寻址地址 #define ReadDeviceAddress 0xa3 // 读I2C外围器件的寻址地址 // 注:写I2C外围器件的寻址地址为器件的地址,读为器件地址加1 unsigned char E0; // 非应答信号标志位 unsigned char NACK=0; // 错误标志位 unsigned char Wdata[12]={0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0xAB,0xCD,0xEF,0x99,0x88,0x77}; unsigned char Rdata[12]={0,0,0,0,0,0,0,0,0,0,0,0}; void SYSCLK_Init(void); void Port_Init(void); void SMBus_Init(void); void WriteI2C(unsigned char RomAddressH,unsigned char RomAddressL,unsigned char number); void ReadI2C(unsigned char RomAddressH,unsigned char RomAddressL,unsigned char bytes); void main (void) { WDTCN = 0xde; // Disable watchdog timer WDTCN = 0xad; SYSCLK_Init (); Port_Init (); // Initialize Crossbar and GPIO RX2 = 1; // Turn off the RX2 before the test starts SMBus_Init (); // Configure and enable SMBus EA = 0; // Global interrupt enable SFRPAGE = SMB0_PAGE; SI = 0; WriteI2C(0x20,0x00,12); while(1) { ReadI2C(0x20,0x13,12); if((Rdata[0]==0xAA)(Rdata[1]==0xBB)(Rdata[2]==0xCC)(Rdata[3]==0xDD)(Rdata[4]==0xE

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档