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

📄 audio.c

📁 以ST公司CPU为核心的彩色电视机的完整源程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************* SGS-THOMSON MICROELECTRONICS ************************
FILENAME     : AUDIO.C
VERSION      : V1.0
DATE         : JAN 1999
AUTHOR(s)    : ASHISH RUDOLA / DEEPAK DOSHI
PROCESSOR    : ST92195
DESCRIPTION  : This module contains functions for handling miscellaneous
               audio control functions.
MODIFICATIONS:	
	-
*****************************************************************************/

#include "power.h"
#include "audio.h"
#include "menuctrl.h"
#include "i2c_bus.h"
#include "register.h"
#include "timer.h"
#include "video.h"
#include "eeprom.h"
#include "source.h"
#include "channel.h"
#include "utility.h"
#include "tuning.h"
#include "tv_glob.h"
#include "tuning.h"

unsigned char stereo_std;
unsigned char mono_sid;
unsigned char stereo_sid;
unsigned int read_status;
unsigned int zweiton_stat;

/*****************************************************************************
INPUTS     : 
OUTPUTS    : 
DESCRIPTION:
*****************************************************************************/
#ifdef NICAM
void init_nicam(void)
{
	write_nicam(0x09, 0x41);
	write_nicam(0x0E, 0xA4);
	write_nicam(0x0F, 0xF5);
}
#endif

void init_audio(void)
{
	video[VIDEO_INDEX[VOLUME]] = read_eeprom(EEPROM_VOLUME) | 0x80;
	volume = (0x7e - (video[VIDEO_INDEX[VOLUME]] & 0x7e))/2;
#ifdef NICAM
	if (misc3 & 0x01)
	{
		init_nicam(); 
	 	stereo_std = 0;
	}
#endif
pwmout = 0;
}

/**************************************************************
INIT_NICAM
****************************************************************/
#ifdef NICAM

void force_mono_standard(void)
{
	write_video_eeprom_data(VOLUME, 0x00);
	write_nicam(0x08, 0x10);
	user_flags = user_flags | MONO_FLAG;
}

void force_stereo_standard(void)
{
	write_nicam(0x08, 0x20);
	user_flags = user_flags & ~MONO_FLAG;
}

/********************************************************
********************************************************/

void write_SWD_control (void)
{
	unsigned char i,k;
		k = read_nicam (0x0D);
		k = k & 0x0E;
		if (k == 0x02) /*MONO */
			write_nicam(0x04, 0x05);
		else
		{
			if (k == 0x04) /*DUAL */
			{
				write_nicam(0x04, 0x06);
	  			i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & 0x80;
				if (i == 0x80)
			 		write_nicam(0x09, 0x41); /* LANGUAGE 2*/
				else
			 		write_nicam(0x09, 0x42); /* LANGUAGE 1*/
			}
			else
					write_nicam(0x04, 0x07);/*STEREO*/
		}
}

/*******************************************************************/
void write_zweiton_SWD_control (void)
{
	unsigned char i,k;
		zweiton_stat = read_nicam(0x0C);
		zweiton_stat = zweiton_stat & 0x03;
		if (zweiton_stat == 0x02) /*STEREO */
			write_nicam(0x04, 0x03);/*STEREO */
		else
		{
			if (zweiton_stat == 0x01) /*DUAL */
			{
				write_nicam(0x04, 0x02);
	  			i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & 0x80;
				if (i == 0x80)
			 		write_nicam(0x09, 0x41); /* LANGUAGE 2*/
				else
			 		write_nicam(0x09, 0x42); /* LANGUAGE 1*/
			}
			else
				write_nicam(0x04, 0x00);/*Mono */
		}
}

/***************************************************************************************/

void write_language_data (void)
{
	unsigned int i,j,k;
		k = read_nicam (0x0D);
		k = k & 0x8E; /* Check for NICAM DUAL*/
		j = read_nicam (0x0C);
		j = j & 0x41;/* Check for Zweiton Dual */

		if ((k == 0x84) || (j == 0x41)) /*DUAL */
		{
			display_request_flags = display_request_flags & ~(NICAM_ON_DISPLAY | NICAM_STANDARD_DISPLAY);
 			display_request_flags = display_request_flags | (LANGUAGE_DISPLAY | REFRESH_DISPLAY);
 			slow_timers[STATUS_TIMER] = STATUS_TIME_OUT;

			j = read_nicam (0x09);
			if (j == 0x02)
			{
				write_nicam (0x09 , 0x01);
				user_flags = user_flags &~ DUAL_1;
				j = EEPROM_START_NICAM_STANDARD + (channel-1);
				i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i | 0x80 ; /*LANGUAGE 2*/
				write_eeprom(j,i);
	
			}
			else
			{ 
				write_nicam (0x09 , 0x02);
				user_flags = user_flags | DUAL_1;
				j = EEPROM_START_NICAM_STANDARD + (channel-1);
				i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & ~0x80 ; /*LANGUAGE 1*/
				write_eeprom(j,i);
	
 		 	}
		}
}

/***************************************************************************************/

void configure_NICAM_LL1 (void)
{
	write_nicam(0x0E, 0x28);	
	write_nicam(0x11, 0x91);/* AGC off*/	
	write_nicam(0x12, 0x20);/*set value of AGC*/
	write_nicam(0x15, 0x03);	
}
/***********************************************************/

void inc_mono_sid(void)
{
	if (tv_flags & INIT_MONO)
		mono_sid =0;
	else
		mono_sid++;
	tv_flags = tv_flags & ~INIT_MONO ;
}

void inc_stereo_sid(void)
{
	if (tv_flags & INIT_STEREO)
		stereo_sid = 0;
	else
	{
	 	if (stereo_sid ==0)
			stereo_sid = 1;
		else
			stereo_sid = 0;
	}
	tv_flags = tv_flags & ~INIT_STEREO ;
}


/***************************************************************************************/
void configure_zweiton_DK (void)
{
 	write_nicam(0x08, 0x00);/*Mute as we have to switch from Auto to Manual*/
	write_nicam(0x0E, 0xA2);/* same as ZWEITON BG except carrier 2 freq change*/
 	user_flags = user_flags & ~MONO_FLAG;
	write_nicam(0x0E, 0xA0);/* Manual mode */
	write_nicam(0x39, 0x0C);/* COFQ1 */
	write_nicam(0x3A, 0xB4);/* FIFQ1 */
	write_nicam(0x2B, 0x0B);/* COFQ2 */
	write_nicam(0x2C, 0x15);/* FIFQ2 */
	write_nicam(0x18, 0x0E);  
}
/***************************************************************************************/

unsigned char decide_mono_standard(void)
{
unsigned char i;

	if (mono_sid == 0) /*BG*/
		write_nicam(0x0E, 0x92);/*try 0x94*/

	if (mono_sid == 1)/*I*/
		write_nicam(0x0E, 0x91);
	
	if (mono_sid == 2)/*DK*/
	{
		write_nicam(0x0E, 0x98);/* same as L*/
		write_nicam(0x0E, 0x90);		
		write_nicam(0x18, 0x2E);		
		write_nicam(0x39, 0x0C);/* Freq 6.5 Mhz*/		
		write_nicam(0x3A, 0xB4);		
	}
	
	write_nicam(0x01, 0x80);/* Reset lock detectors*/
	millisecond_delay(200);/* Problems with 160ms*/
	i = read_nicam(0x0C);
	i = i & 0x30;
	if (i == 0x30)
		i = 1;
	else 
		i = 0;
	return i;
}
	
/***************************************************************************************/

unsigned char decide_stereo_standard(void)
{

unsigned char i;
	
	if ((mono_sid == 0) && (stereo_sid == 0))/* NICAM BG*/
		write_nicam(0x0E, 0xA4);

	if ((mono_sid == 0) && (stereo_sid == 1))/* ZWEITON BG*/
	{
		write_nicam(0x0E, 0xA2);

#ifndef AUTO_ZWEITON
		millisecond_delay(10);
		write_nicam(0x08, 0x00);
	 	write_nicam(0x0E, 0xA0); 
		write_nicam(0x18, 0x0E);
#endif
	}		

	if (mono_sid == 1) /* NICAM I*/
		write_nicam(0x0E, 0xA1);

	if ((mono_sid == 2) && (stereo_sid == 0))/* NICAM DK same as NICAM BG*/
		write_nicam(0x0E, 0xA4);/* Try with NICAM LL1 0x58*/

	if ((mono_sid == 2) && (stereo_sid == 1))/* ZWEITON DK*/
	{
		configure_zweiton_DK();

	}		

	if (stereo_sid == 1)
	{
		millisecond_delay(500);
		millisecond_delay(500);
		millisecond_delay(500);
		i = read_nicam(0x0C);
		i = i & 0x07;
		if ((i == 5) || (i == 6)) /* Zweiton Det & (Stereo or Dual)*/
			i = 1;
		else 
			i = 0;
	}	
	else
	{
		millisecond_delay(160);
		i = read_nicam(0x0D);
		i = i & 0x80;
		if (i == 0x80)
			i = 1;
		else 
			i = 0;
	}	
	return i;
}

/************************************************************/


/****************************************************************/
void auto_stereo_std_minusLL1(void)
{
unsigned char i,j;
		inc_mono_sid();
		if (mono_sid <= 2)
		{
			i = decide_mono_standard();
			if (i == 1)
			{
				inc_stereo_sid();
				j = decide_stereo_standard();
				if (j ==1)					
				{
					write_SWD_control(); /*Also switch to Stereo*/			
					force_stereo_standard();
				}
				else
				{
					inc_stereo_sid();
					j = decide_stereo_standard();
					if (j ==1)					
					{
						write_zweiton_SWD_control(); /*Also switch to Stereo*/			
						force_stereo_standard();
						
					}
					else
						auto_stereo_std_minusLL1(); 
				}

			}
			else
			{
				auto_stereo_std_minusLL1(); 
			
			}
		}
		else
		{
			force_mono_standard();
 			write_nicam(0x0E, 0x21);
		}
}

/***********************************************************************
***********************************************************************/
void auto_stereo_standard (void)
{
	unsigned char j;

	j = read_channel_info(SETTINGS);
    AUDIO_system = get_value(j,AUDIO_SYSTEM_MASK);

	write_nicam(0x11, 0x11);/* AGC on*/	
	tv_flags = tv_flags | (INIT_MONO);
	tv_flags = tv_flags | (INIT_STEREO);
	auto_stereo_std_minusLL1();		
}

/**********************************************************************/
void write_stereo_standard(void)
{
	unsigned int i,j;
	switch (stereo_std)
	{

		case 0: /* AUTO*/
			user_flags = user_flags & ~MONO_FLAG;
			user_flags = user_flags & ~FORCED_NICAM_FLAG;
			auto_stereo_standard();	

			if (!(tuning_flags & TUNING_REQUEST))
			{
				j = EEPROM_START_NICAM_STANDARD + (channel-1);
				i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & 0x80;
				i = i | 0x00;
				write_eeprom(j,i);
			}
		break;
#ifdef NICAM_FORCED

		case 1:/* MONO*/

			force_mono_standard();
			if (!(tuning_flags & TUNING_REQUEST))
			{
				j = EEPROM_START_NICAM_STANDARD + (channel-1);
				i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & 0x80;
				i = i | 0x01;
				write_eeprom(j,i);
			}
		break;

		case 2:/* NICAM_BG*/
	 		write_nicam(0x0E, 0xA4);
			force_stereo_standard();
			millisecond_delay(160);
			write_SWD_control();

			if (!(tuning_flags & TUNING_REQUEST))
			{
				j = EEPROM_START_NICAM_STANDARD + (channel-1);
				i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & 0x80;
				i = i | 0x02;
				write_eeprom(j,i);

			}	
		 	if (!(display_request_flags & MUTE_DISPLAY))
		 		write_nicam(0x0E, 0x24);

		break;

		case 3:/* NICAM_I*/
	 		write_nicam(0x0E, 0xA1);
			force_stereo_standard();

/*			write_nicam(0x18, 0x6E);*/
			millisecond_delay(160);
			write_SWD_control();
			if (!(tuning_flags & TUNING_REQUEST))
			{	
				j = EEPROM_START_NICAM_STANDARD + (channel-1);
				i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & 0x80;
				i = i | 0x03;
				write_eeprom(j,i);
			}	
	 	if (!(display_request_flags & MUTE_DISPLAY))
		 		write_nicam(0x0E, 0x21);

		break;

		case 4:/* NICAM_DK*/
		 	write_nicam(0x0E, 0xA4);/* same as BG*/
			force_stereo_standard();

/*			write_nicam(0x18, 0x2E);*/
			millisecond_delay(160);
			write_SWD_control();
			if (!(tuning_flags & TUNING_REQUEST))
			{
				j = EEPROM_START_NICAM_STANDARD + (channel-1);
				i = read_eeprom(EEPROM_START_NICAM_STANDARD + (channel-1));
				i = i & 0x80;

⌨️ 快捷键说明

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