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

📄 main.c

📁 i2s usb audio demo lpc2138
💻 C
字号:
/*****************************************************************************
 *   main.c:  main entry file - for NXP LPC23xx/24xx Family Microprocessors
 *                                I2S Audio demo with UDA1341                  
 *
 *   Copyright(C) 2007, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2007.07.20  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************//* Demo Program main */

#include <stdio.h>                         /* standard I/O .h-file */
#include "LPC23xx.h"                       /* LPC23xx definitions  */
#include "type.h"
#include "target.h"                        /* LPC23xx common header  */
#include "irq.h"                           /* LPC23xx common header   */
#include "timer.h"                         /* LPC23xx common header   */

#include "../portLCD/inc/portlcd.h"        /* MCB23xx LCD header   */
#include "../EInt/inc/Eint.h"              /* LPC23xx External Interrupt header  */
#include "../fio/inc/fio.h"

#include "../i2s/inc/i2s.h"
#include "../L3/inc/l3.h"


#include "../application/inc/i2s_demo.h"

extern int freq; /* DSS frequency */

/* functions in this file */
int install_VIC_interrupts(void);
void identifyDemo(unsigned char * name);
void init_UART0 (unsigned long baudrate, unsigned long pclk);

/* Global Variables */
unsigned long forever =1;

/****************************************
 *  start demo; 
 						This demo uses direct digital synthesis to output
						a song thru the I2S interface to an UDA1341 audio codec. 
						Each time you press the INT0 push button the
						next note of the song will play the duration of
						all notes is about 270 ms. Timing is determined
						by the operator. This code is sample code only
						and is not meant to be production ready. It will
						help get you understand the I2S interface on the LPC2378
						No attempt at efficient code use or memory allocation
						was made. one would need to remove unused code and
						remove lots of wasted space in arrays etc....
 ****************************************/ 


int main (void)
{

/* 
 *   Initialize LCD Display to let user know demo installed 
 */																						   
    identifyDemo(" DSS 4 I2S Demo");

 	freq = 440;		/* set default frequency 440 Hz	= 'A' */ 

    GPIOInit(2, FAST_PORT, 0xff, 0xff);	/* set led0-7 GPIO as ouput pins *//* for Debug */
	FIO2CLR = 0xff;	/* turn off led's */

	install_VIC_interrupts();		 /* init Vector Interrupt Controller */


/******************************************
	*  initialize L3 Interface to the I2S ; 
	**************************************/ 
 
    init_timer1(4-1); /* timer 1 for I2S bitclk interface timing */
	enable_timer1();  /* enable Timer 1 */
    printf("init timer 1\n\r");

    init_timer0(32-1); /* timer 0 for L3 interface and I2S LRCLK; divide by 512=44.1k*/
    enable_VIC_irq(TIMER0_INT);	  /* peripheral interrupt for L3 interface*/
	enable_timer0();  /* enable Timer 0  */
    printf("init timer 0\n\r");

    L3_init_GPIO(); /* configure GPIO to support L3 interface */
    printf("init L3 GPIO\n\r");

    UDA1341_init(); /* initalize the UDA1341 audio CODEC using L3 interface*/
    printf("init UDA1341 \n\r");


/*********************
	*  initialize i2s; 
	*****************/ 


    i2s_init(); /*  clock divider 1:1, power on, configure pins P0.4-P0.9 */

/****************************************
	*  	initialize external interrrupt 0
	************************************/ 

    init_EINT(0, EINT_EDGE_TRIG, EINT_FALLING_EDGE ); /* configure external interrrupt Push Button on MCB2300 */
	enable_VIC_irq(EINT0_INT);


/****************************************
	 * I2S_Demo_main
	************************************/ 

	I2S_Demo_main();							 

    while (forever); {}  /* code never reached */

 return (0);
}
 
int install_VIC_interrupts(void)
{
	install_irq(EINT0_INT, (void *)IRQ_EINT0_HandlerDSS, 5 );
	install_irq(TIMER0_INT, (void *)IRQ_L3_Handler, 7 );
    return 0;
}

void identifyDemo(unsigned char * name)
{
    init_UART0(115200, Fpclk);
    printf("%s\n\r",name);

 	LCD_init();
    LCD_write_line1("   NXP Semi     ");
    LCD_write_line2(name);
}


void init_UART0 (unsigned long baudrate, unsigned long pclk)
{               
  unsigned long UnDL;

  PCONP |= (1 << 3);                     /* enable power to UART0 */  PINSEL0 &= ~0x000000F0;                /* Clear P0.2 and P0.3     */
  PINSEL0 |= 0x00000050;                 /* Enable RxD0 and TxD0 on P0.2 and P0.3            */
  U0LCR = 0x83;                          /* 8 bits, no Parity, 1 Stop bit     */

  UnDL = pclk/(baudrate*16);
  U0DLM = ((UnDL>>8) & 0x0ff);           /* set middle baud rate register  */
  U0DLL = (UnDL & 0x0ff);                /* set lower baud rate register */

  U0LCR = 0x03;                          /* DLAB = 0   */
}

⌨️ 快捷键说明

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