?? i2c.c
字號(hào):
/*------------------------------------------------------------
File Name: i2c.c
Auther: Samuel
Revision: R1
History: R1 Jul.05, 2007 Creation
------------------------------------------------------------*/
#include "i2c.h"
// SMBus byte write function-----------------------------------------------------
// Writes a single byte at the specified memory location.
//
// out_byte = data byte to be written
// byte_address = memory location to be written into (2 bytes)
// chip_select = device address of EEPROM chip to be written to
void EEPROM_Send (char chip_select, unsigned int byte_address, char out_byte)
{
I2C_Device=EEPROM; // To tell the interrupt service routine what the I2C device is!
while (SM_BUSY); // Wait for SMBus to be free.
SM_BUSY = 1; // Occupy SMBus (set to busy)
SMB0CN = 0x44; // SMBus enabled,
// ACK on acknowledge cycle
BYTE_NUMBER = 2; // 2 address bytes.
COMMAND = (chip_select | WRITE); // Chip select + WRITE
HIGH_ADD = ((byte_address >> 8) & 0x00FF);// Upper 8 address bits
LOW_ADD = (byte_address & 0x00FF); // Lower 8 address bits
WORD = out_byte; // Data to be writen
STO = 0;
STA = 1; // Start transfer
}
// SMBus random read function------------------------------------------------------
// Reads 1 byte from the specified memory location.
//
// byte_address = memory address of byte to read
// chip_select = device address of EEPROM to be read from
char EEPROM_Receive (char chip_select, unsigned int byte_address)
{
I2C_Device=EEPROM; // To tell the interrupt service routine what the I2C device is!
while (SM_BUSY); // Wait for bus to be free.
SM_BUSY = 1; // Occupy SMBus (set to busy)
SMB0CN = 0x44; // SMBus enabled, ACK on acknowledge cycle
BYTE_NUMBER = 2; // 2 address bytes
COMMAND = (chip_select | READ); // Chip select + READ
HIGH_ADD = ((byte_address >> 8) & 0x00FF);// Upper 8 address bits
LOW_ADD = (byte_address & 0x00FF); // Lower 8 address bits
STO = 0;
STA = 1; // Start transfer
while (SM_BUSY); // Wait for transfer to finish
return WORD;
}
///////////////////////////////////////////////
void TEA5777_Send (void)
{
I2C_Device=TEA5777; // To tell the interrupt service routine what the I2C device is!
while (SM_BUSY); // Wait for bus to be free.
SM_BUSY = 1; // Occupy SMBus (set to busy)
SMB0CN = 0x44; // SMBus enabled, ACK on acknowledge cycle
COMMAND = 0xC0; // TEA5777 address + WRITE
BYTE_NUMBER=6;
STO = 0;
STA = 1;
while (SM_BUSY); // 發(fā)起始條件
}
///////////////////////////////////////////////
void TEA5777_Receive (void)
{
I2C_Device=TEA5777; // To tell the interrupt service routine what the I2C device is!
while (SM_BUSY); // Wait for bus to be free.
SM_BUSY = 1; // Occupy SMBus (set to busy)
SMB0CN = 0x44; // SMBus enabled, ACK on acknowledge cycle
COMMAND = 0xC1; // TEA5777 address + READ
STO = 0;
STA = 1; // 發(fā)起始條件
while (SM_BUSY); // Wait for transfer to finish
TEA5777_receive_buffer[0]= WORD;
SM_BUSY = 1;
while (SM_BUSY); // Wait for transfer to finish
TEA5777_receive_buffer[1]= WORD;
SM_BUSY = 1;
AA=0;
while (SM_BUSY); // Wait for transfer to finish
TEA5777_receive_buffer[2]= WORD;
//STO=1;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -