📄 smbus_test.c
字号:
#include <C8051F320.h>
#include "SMBus.h"
void Port_Init(void);
void main()
{
unsigned char temp;
unsigned char in_buff[4] = {1}; // Incoming data buffer
unsigned char out_buff[4];
unsigned char chaner1[4] = {0x00,0x00,0x00 , 0x03};
unsigned char chaner2[4] = {0x00,0x00,0x00, 0x02};
unsigned char chaner3[4] = {0x00,0x00,0x00 , 0x01};
PCA0MD &= ~0x40; // WDTE = 0 (disable watchdog timer)
OSCICN |= 0x03; // Set internal oscillator to highest
// setting of 12000000
Port_Init();
SMBus_Init (); // Configure and enable SMBus
EEPROM_ReadArray(0x68,in_buff,0x02,4);
// EEPROM_WriteArray(0xa0,0x00, out_buff,4);
temp=in_buff[3];
while(temp);
out_buff[3]= chaner1[3];
EEPROM_WriteArray(0x68,0x29,out_buff,4);
EEPROM_ReadArray(0x68,in_buff,0x02,4);
temp=in_buff[3];
EEPROM_ReadArray(0x68,in_buff,0x29,4);
out_buff[3] = chaner2[3];
EEPROM_WriteArray(0x68,0x29,out_buff,4);
EEPROM_ReadArray(0x68,in_buff,0x02,4);
temp=in_buff[3];
EEPROM_ReadArray(0x68,in_buff,0x29,4);
out_buff[3] = chaner3[3];
EEPROM_WriteArray(0x68,0x29,out_buff,4);
EEPROM_ReadArray(0x68,in_buff,0x02,4);
temp=in_buff[3];
EEPROM_ReadArray(0x68,in_buff,0x29,4);
while(1)
{
}
}
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// Configure the Crossbar and GPIO ports.
//
// P0.0 digital open-drain SMBus SDA
// P0.1 digital open-drain SMBus SCL
//
// P2.2 digital push-pull LED
//
// all other port pins unused
//
// Note: If the SMBus is moved, the SCL and SDA sbit declarations must also
// be adjusted.
//
void PORT_Init (void)
{
P0MDOUT = 0x00; // All P0 pins open-drain output
P2MDOUT |= 0x04; // Make the LED (P2.2) a push-pull
// output
XBR0 = 0x04; // Enable SMBus pins
XBR1 = 0x40; // Enable crossbar and weak pull-ups
P0 = 0xFF;
}
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -