?? r2s15902.c
字號:
/****************************************************************
* MT View Silicon Tech. Inc.
* Copyright 2005, MT View Silicon Tech. Inc., ShangHai, China
* All rights reserved.
*
* Filename: R2S15902.c
* Programmer: Grey
* Created: 01/xx/2006
* Description: R2S15902 audio control operation function file
*
* Change History (most recent first):
****************************************************************/
#include <reg51.h>
#include "type.h"
#include "utility.h"
#include "R2S15902.h"
/* Internal I2C protocol */
/*declare I2C port and pins*/
#define PORT P3
#define SCL 0x01 //= P3^0
#define SDA 0x02 //= P3^1
/*define pin operate macro*/
#define SET_PIN(reg, mask) ((reg) |= (mask)) //pin = 1
#define CLR_PIN(reg, mask) ((reg) &= (~(mask))) //pin = 0
#define GET_PIN(reg, mask) ((reg) & (mask)) //get pin status
/*set SCL rate: 100Kbps~400Kbps*/
#define I2C_TIME 1 //EX51 -> 100 us/bit
//I51 -> 10 us/bit
BYTE CODE R2S15902_INIT_DATA[12] = {0x03,0x02,0x00,0xc0,0x03,0x8f,0xc0,0x03,0x4f,0xc0,0x03,0xcf};
BYTE R2S15902_DATA[12];
//
// I2C start condition: SCL = 1, SDA 1->0
//
static void
I2CStart(void)
{
CLR_PIN(PORT, SDA);
WaitUs(I2C_TIME);
CLR_PIN(PORT, SCL);
WaitUs(0);
}
//
// I2C stop condition: SCL = 1, SDA 0->1
//
static void
I2CStop(void)
{
// CLR_PIN(PORT, SCL);
// WaitUs(I2C_TIME);
SET_PIN(PORT, SDA);
WaitUs(I2C_TIME);
SET_PIN(PORT, SCL);
WaitUs(I2C_TIME);
CLR_PIN(PORT, SCL);
WaitUs(I2C_TIME);
CLR_PIN(PORT, SDA);
WaitUs(I2C_TIME);
SET_PIN(PORT, SCL);
WaitUs(I2C_TIME);
CLR_PIN(PORT, SCL);
}
//
// I2C write 8 bits to device
//
static bit //if error return 1, else return 0
I2CWrite8Bit(
unsigned char b //data to write into device
)
{
unsigned char temp;
for(temp=8; temp!=0; temp--)
{
CLR_PIN(PORT, SCL);
WaitUs(I2C_TIME);
if(b & 0x01) //MSB output first
{
SET_PIN(PORT, SDA);
}
else
{
CLR_PIN(PORT, SDA);
}
WaitUs(I2C_TIME);
SET_PIN(PORT, SCL);
WaitUs(I2C_TIME);
b = b >> 1;
}
//CLR_PIN(PORT, SCL);
return 0;
}
/* Internal I2C protocol */
//
// R2S15902 set multi registers
//
extern bit //if succeed return 0, else return 1
R2S15902SetReg(void)
{
unsigned char i;
I2CStart();
for(i = 0; i < 3; i++)
{
I2CWrite8Bit(R2S15902_DATA[i]);
}
I2CStop();
for(i = 3; i < 6; i++)
{
I2CWrite8Bit(R2S15902_DATA[i]);
}
I2CStop();
for(i = 6; i < 9; i++)
{
I2CWrite8Bit(R2S15902_DATA[i]);
}
I2CStop();
for(i = 9; i < 12; i++)
{
I2CWrite8Bit(R2S15902_DATA[i]);
}
I2CStop();
return 0;
}
//
// Initial R2S15902 port
//
extern void
R2S15902Init(void)
{
SET_PIN(PORT, SDA | SCL);
}
//extern BYTE gAddOnFlag; //record add-on module connection status
//
// Audio initial
//
extern void
AudioInit(
void
)
{
unsigned char i;
for(i = 0; i < 12; i++)
{
R2S15902_DATA[i]=R2S15902_INIT_DATA[i];
}
R2S15902Init();
if(R2S15902SetReg())
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -