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

📄 mischard.c

📁 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS * OR IMPLIED WARRANTIES, INC
💻 C
字号:
/*
 * Copyright (c) 2002, Jan Szymanski.
 * All rights reserved. 
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met: 
 * 1. Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright 
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the distribution. 
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Jan Szymanski.
 * 4. The name of the author may not be used to endorse or promote
 *    products derived from this software without specific prior
 *    written permission.  
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 */
/*********************************************************/
/*                                                       */
/*  Module              : Mischard.C                     */
/*  Language used       : C for MSP430                   */
/*  Microprocessor      : MSP430F149                     */
/*                                                       */
/*  Function            : Miscellanous hardware functions*/
/* ------------------------------------------------------*/
/*  Revision History :                                   */ 
/*  Author				Date				      Reason               */
/*  Jan Szymanski 16 February 2002	Initial Design       */
/*                                                       */
/*********************************************************/
/*********************************************************/
/*  Name        : ST_OnOff                               */
/*  Parameters  : 0-off, 1-on                            */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : to turn on power to SmartMedia         */
/*-------------------------------------------------------*/
void ST_On(unsigned char command)
{
unsigned int temp;
if(command==1)  // turn on
  {

// return port pins to normal state
  P5SEL|=0x0e;  // P5,3, P5.2, P5.1 as SPI pins
  // do we need to reinitialise SPI here ???

  P3OUT &=0xfb;// keep RESET low

  P3OUT |= 0xc0;//SCL is P3.6, SDA is P3.7
  P3DIR &=0x3f;// make P3.6, P3.7 inputs 

  P1OUT &=0x7f;//P1.7 low is on

  P5OUT |= 0x10; /* P54 BIT_EN = 1 */

  }
else  // turn off
  {
  // port pins all = 0
  P3OUT &=0xfb;// RESET is P32

  P1OUT |=0x80;//P1.7 high is power off

  P3OUT &= 0x3f;//SCL is P3.6, SDA is P3.7
  P3DIR |=0xc0;// make P3.6, P3.7 outputs 

  P5OUT &= 0xef; /* P54 BIT_EN = 0 */
// make P5.1=SDI and P5.3=SCKR zero
  P5OUT &= 0xf1; // P5.3=0, P5.2=0, P5.1=0
  P5SEL &= 0xf1;
  //P5SEL|=0x0e;

  }
// some delay here
for(temp=0;temp<10000;temp++){}
}
/* End of ST_On ******************************************/
/*********************************************************/
/*  Name        : SM_On                                  */
/*  Parameters  : 0-off, 1-on                            */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : to turn on power to SmartMedia         */
/*-------------------------------------------------------*/
void SM_On(unsigned char command)
{
unsigned int temp;
if(command==1)  // turn on
  {
  P4OUT = 0x00;
  P4DIR = 0xff; /* D0-D7 outputs */
  P1OUT |=0x01; /* P1.0 is SMCS */
  P1OUT |=0x02; /* P1.1 is SMRD */
  P1OUT |=0x04; /* P1.2 is SMWR */
  P1OUT &=0xbf;//P1.6 low will turn on
  }
else  // turn off
  {
  P1OUT |=0x40;//P1.6 high will turn off
  P4OUT = 0x00;
  P4DIR = 0xff; /* D0-D7 outputs */
  P1OUT &=0xfe; /* P1.0 is SMCS */
  P1OUT &=0xfd; /* P1.1 is SMRD */
  P1OUT &=0xfb; /* P1.2 is SMWR */
  P1OUT &=0xf7; /* P1.3 is CLE */
  P1OUT &=0xef; /* P1.4 is ALE */
  }
// some delay here
for(temp=0;temp<10000;temp++){}
}
/* End of SM_On ******************************************/

/*********************************************************/
/*  Name        : m_sleep                                */
/*  Parameters  : none                                   */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : to put uC into LPM4                    */
/*-------------------------------------------------------*/
void m_sleep(void)
{
unsigned int i;
//play_stop=0;
//LED_state=0x0000;
Red_LED_state=0x0000;
Green_LED_state=0x0000;
//P3OUT &= 0xfe; // Clear P3.0 for LED
P3OUT |= 0x01;  // LED1 off
P3OUT |= 0x08;  // LED2 off
SM_On(0x00);

/* turn the out port lines from Micro- to low level */
P3OUT &= 0xfb;  // 1111 1011 P32=RESET
P3OUT &= 0x3f;  // 0011 1111 P36=SCL, P37=SDA
P6OUT &= 0xfd;  // 1111 1101 P61=xCS
P5OUT &= 0xef;  // 1110 1111 P54=BIT_EN (BSYNC)

ST_On(0x00);

putchar_uart0(0x0a);
putchar_uart0(0x0d);
putstring_uart0("Sleep Mode");
P2IFG=0x00;
P2IE=0x01;  /* enable INT from P2.0 PLAY/STOP key */

// switch clock to LFXT1 so we can turn off XT2
//BCSCTL2=0xc0;   /* 11000000 */
                /* ||||||||____ DCOR=0 */ 
                /* |||||||_____ DIVS.1 DIVS.0 =0 SMCLK divided by 1 */
                /* |||||_______ SELS=0 do not use XT2CLK for SMCLK */
                /* ||||________ DIVM.1 DIVM.0 MCLK divided by 1 */
                /* ||__________ SELM.1 SELM.0 =3 use XT1CLK */ 
//BCSCTL1=0x84;   /* 10000100 */
                /* ||||||______ Rsel.2 Rsel.1 Rsel.0 */
                /* |||||_______ XT5V always 0 */
                /* ||||________ DIVA.1 DIVA.0 = 0 ACLK divided by 1 */
                /* ||__________ XTS=0, low frequency for LFXT1 */
                /* |___________ XT2Off=1, XT2 is off */ 

//_SR |= 0x00f0;  /* go into LPM4 */
LPM4;
}
/* End of m_sleep ******************************************/

/*********************************************************/
/*  Name        : m_awake                                */
/*  Parameters  : none                                   */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : action after awake INT                 */
/*-------------------------------------------------------*/

void m_awake(void)
{
//_SR &= 0xff0f;
P2IFG=0x00; /* clear all INT flag from the keys */
P2IE=0x00;  /* no INT in normal mode */

// turn XT2 on again
//IFG1=0; /* clear Interrupt Flags */
//IFG2=0; /* clear Interrupt Flags */

//BCSCTL1=0x04;   /* 00000100 */
                /* ||||||______ Rsel.2 Rsel.1 Rsel.0 */
                /* |||||_______ XT5V always 0 */
                /* ||||________ DIVA.1 DIVA.0 = 0 ACLK divided by 1 */
                /* ||__________ XTS=0, low frequency for LFXT1 */
                /* |___________ XT2Off=0, XT2 is on */
//BCSCTL2=0x88;   /* 10001000 */
                /* ||||||||____ DCOR=0 */ 
                /* |||||||_____ DIVS.1 DIVS.0 =0 SMCLK divided by 1 */
                /* |||||_______ SELS use XT2CLK for SMCLK */
                /* ||||________ DIVM.1 DIVM.0 MCLK divided by 1 */
                /* ||__________ SELM.1 SELM.0 =2 use XT2CLK */  
/* wait in loop until crystal is stable */
//do
//  {
//  IFG1 &= 0xfd; //IFG1&=~OFIFG;
//  }while(IFG1 & 0x02); //(IFG1&OFIFG);

putchar_uart0(0x0a);
putchar_uart0(0x0d);
putstring_uart0("Let us Play MP3");  

SM_On(0x01);
SM_reset();

ST_On(0x01);// turn power on to MP3 decoder and audio
putchar_uart0('P');
v_init();
//play_stop=1;
//LED_state=0x0101;
Red_LED_state=0x0000;
Green_LED_state=0x0101;
key=1;  // force to play from any key
}
/* End of m_awake ****************************************/

/*********************************************************/
/* END OF FILE Mischard.c                                */
/*********************************************************/

⌨️ 快捷键说明

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