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

📄 tea5763.c

📁 调频收音机芯片5763的驱动代码,C语言编写,直接移植即可,代码已经验证OK
💻 C
字号:
/*-------------------------------------------------------

	Property of Synergy Digital Technology Ltd.

	Question/comment : chifai.cheung@synergytech.cn

	Complier : Keil uvision C-51

-------------------------------------------------------*/


#include "tea5763.h"
#include "i2c.h"

//
// Adjust ONEMS to delay around 1ms
//

void delay_ms(unsigned CYCLE)
{
	unsigned i, j;

	for (i=0; i<CYCLE; i++)
		for (j=0; j<ONEMS; j++);
}


//
// Write writebuf into all 7 registers
//


void fm_write()
{
	unsigned i;

	i2c_start();
	i2c_out(I2C_ADDR & 0xFE);
	for (i=0; i<7; i++)
		i2c_out(writebuf[i]);
	i2c_stop();
}


//
// Read all 16 registers into readbuf
//

void fm_read()
{
	unsigned i;

	i2c_start();
	i2c_out(I2C_ADDR | 0x01);
	for (i=0; i<16; i++)
	{
		readbuf[i] = i2c_in();
		if (i<15) i2c_ack();
		else i2c_nak();
	}
	i2c_stop();
}


//
// Wait until the state machine is ready
//

void fm_wait()
{
	do fm_read();
        while (!(readbuf[0] & 0x02));
}


//
// Convert PLL value to frequency
//

unsigned long pll2frq(unsigned PLL)
{
	unsigned long FRQ;

	if (WBUF4 & 0x10)
		FRQ = ((unsigned long)(PLL-9304)<<13)+75993368;		// high-side
	else
		FRQ = ((unsigned long)(PLL+9304)<<13)-75993368;		// low-side

	return FRQ;
}


//
// Convert frequency to PLL value
//

unsigned frq2pll(unsigned long FRQ)
{
	unsigned PLL;

	if (WBUF4 & 0x10)
		PLL = ((unsigned long)((FRQ-75993368)>>13)+9304) & 0xFFFF;		// high-side
	else
		PLL = ((unsigned long)((FRQ+75993368)>>13)-9304) & 0xFFFF;		// low-side

	return PLL;
}


//
// Tune to a specific PLL value
//

void fm_tune(unsigned PLL)
{
	writebuf[0] = 0x00;
	writebuf[1] = PLL>>8;
	writebuf[2] = PLL & 0xFF;
	writebuf[3] = WBUF3;
	writebuf[4] = WBUF4;
	writebuf[5] = 0x00;
	writebuf[6] = 0x00;

	fm_write();
	delay_ms(15);
	fm_wait();
}


//
//  UP = 1 - scan up, UP = 0 - scan down
//

void fm_scan(unsigned UP)
{
	unsigned PLL;

	fm_read();

	PLL = (unsigned)(readbuf[6]<<8) | readbuf[7];
	if (UP) PLL = (PLL+10) | 0xC000;		// scan up
	else PLL = (PLL-10) | 0x4000;			// scan down

	fm_tune(PLL);
	
	fm_read();
	if (readbuf[0] & 0x10)
	{										// if IF count is not correct,
		writebuf[4] ^= 0x10;				// try to improve reception
		fm_write();							// by toggling injection
		delay_ms(20);
		writebuf[4] ^= 0x10;
		fm_write();
		delay_ms(20);
	}

	PLL = (unsigned)(readbuf[6]<<8) | readbuf[7];
	if (PLL<LLIMIT) PLL = LLIMIT;
	if (PLL>ULIMIT) PLL = ULIMIT;

	fm_tune(PLL);
}

⌨️ 快捷键说明

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