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

📄 func_abcd_flip.c

📁 2.4G无线音箱的接收程序,采用ATMEGA8单片机和STS公司的无线模块完成
💻 C
字号:
/******************************************************************************
*
* Purpose:      Func_Volume.c
*
* Creator:      Paul v/d Linden
*
* Version:		$Revision: 5 $
*
* File Name:	$Workfile: Func_ABCD_Flip.c $
*
* Author:		Paul v/d Linden
*
* Check in:		$Author: Chong.cheeleong $
*
* The information is provided 揳s is" without any express or implied warranty  
* of any kind, * including warranties of merchantability, noninfringement of   
* intellectual property, or fitness for any particular purpose. In no event sha
* Wireless Sound Solutions and/or its affiliate companies, or its suppliers be 
* liable for any damages whatsoever arising out of the use of or inability to  
* use the information or the materials. Wireless Sound Solutions, its affiliate
* companies, and its suppliers further do not warrant the accuracy or          
* completeness of information, text, graphics, or other items contained within 
* materials. Wireless Sound Solutions, Inc., may make changes to materials, or 
* the products described within, at any time, without notice.                  
* 2007 Wireless Sound Solutions. All rights reserved. Wireless Sound Solutions
* STS and STS-wireless are trademarks of Wireless Sound Solutions.        
******************************************************************************/
/*
** Include files
** -------------
*/
#include <stdio.h>
#include "defines.h"

unsigned char prev_FLIP_ABCD_SW = 1;
unsigned char Flip_Status = 0;

long x;


/******************************************************************************
*
* Function Name :   Handle_ABCD_Flip_MainLoop
*
* Purpose       :   This is a function that will flip a MU to the next audio Source (Stream)
*		    		Audio interface W is sequencialy connected to Stream A,B,C or D. 
*					Astream is only connected to Pipe W when when Stream status is insync.
*					This info is read from register SNCD.
*					So 4 possitions are possible:
*						A>W, B>X, C>Y, D>Z RS2P=E4			//228
*						A>X, B>Y, C>Z, D>W RS2P=93			//147
*						A>Y, B>Z, C>W, D>X RS2P=4E			//78
*						A>Z, B>W, C>X, D>Y RS2P=39			//57
                    This make is possbile to connect a stereo speaker to Pipe W and do 
                    source select of the availeble Streams.
*
* Arguments     :	none
*
* Return value  :	none
*
******************************************************************************/
void Handle_ABCD_Flip_MainLoop (void)
{
#ifdef Target_MU
	unsigned char sncd;
	unsigned char rs2p, stac;

	/* Check if Button is Pressed */
	if (prev_FLIP_ABCD_SW != FLIP_ABCD_SW)
	{
		/* Change prev_... to Handle this Button only Once */
		prev_FLIP_ABCD_SW = FLIP_ABCD_SW;

		/* Check if Button is Pressed Down and not Released */
		if (FLIP_ABCD_SW == 0x00)	
		{
          
            I2C_Write_Byte(STAC_ADDR, 0xF0);  /* enable all RX streams to check for In Sync*/          
            
            Wait_For_mSec(100); 
            
			/* Read Sync status Down Register */
			sncd = I2C_Read_Byte(SNCD_ADDR);
			
//			printf("sncd 0x%X\r",sncd);
            
			/* search for next insync Stream */
			for (int i = 0; i < 4; i++)
			{
				/* Select Next Possible Stream */
				Flip_Status++;
				if (Flip_Status == 4) Flip_Status = 0;
				
				/* Check if Stream is In Sync */
				if (((sncd  >> (Flip_Status * 2)) & 0x03) == 0x03)
				{
					/* Next In Sync Channel Found */
					break;
				}
			}
//			printf("Next Stream %d\r",Flip_Status);
            
            I2C_Write_Byte(STAC_ADDR, 0x00);  /* disable all RX streams */
            Wait_For_mSec(20);   /* Wait until stream have been fadout */
            I2C_Write_Byte(PIAC_ADDR, 0x00);  /* disable all pipes */

//PIAC=0x07, STAC=0x70, RS2P=0xE4, TP2S=0xE4
	
			/* Set Stream to Pipe Mux RS2P */
                #ifndef FLIP_CD
                    /* default Flip_ABCD setting */
				switch (Flip_Status)
				{							 
                    case 0: rs2p = 0xE4; //printf("Stream A RX on Pipe W\r"); 
                            stac = 0x10; // stream A active
                            break;
                    case 1: rs2p = 0x93; //printf("Stream A RX on Pipe X\r"); 
                            stac = 0x20; // streams B active
                            break;
                    case 2: rs2p = 0x4E; //printf("Stream A RX on Pipe Y\r"); 
                            stac = 0x40; // streams C active
                            break;
                    case 3: rs2p = 0x39; //printf("Stream A RX on Pipe Z\r"); 
                            stac = 0x80; // streams D active
                            break;  
					}
                #else
				// no used Allan
                    /* Flip CD only */
					switch (Flip_Status)
					{							 

                    case 0: rs2p = 0x4E; //printf("Stream C RX on Pipe W\r"); 
                            stac = 0x40; // streams C active
                            break;
                    case 1: rs2p = 0x39; //printf("Stream D RX on Pipe W\r"); 
                            stac = 0x80; // streams D active
                            break;
                    case 2: rs2p = 0x4E; //printf("Stream C RX on Pipe W\r"); 
                            stac = 0x40; // streams C active
                            break;
                    case 3: rs2p = 0x39; //printf("Stream D RX on Pipe W\r"); 
                            stac = 0x80; // streams D active
                            break;
						
						}
                #endif                               
            
            I2C_Write_Byte(RS2P_ADDR, rs2p);  /* configure RX streams to pipes */
            I2C_Write_Byte(PIAC_ADDR, 0x01);  /* enable pipe W */                
            I2C_Write_Byte(STAC_ADDR, stac);  /* enable selected streams */
              
		} /* End Switch Down First Time */
	}
#endif /*Target_MU*/
}

⌨️ 快捷键说明

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