Beispiel #1
0
void Test_ADC(void)
{
    U8 ch, mode;
	
	Uart_Printf("Select ADC Chanel: 0 or 1");
	ch=Uart_Getch();
	Uart_Printf("\n%c\n\n", ch);
	
	if (ch!='0' && ch !='1')
	{
		Uart_Printf("you select wrong chanel!\n");
		return;
	}
	
    rADCDLY = 100;				//ADC转换延时	
//    rADCTSC = 0;				//设置ADC为普通模式
   								/* 进行ADC模块设置,其中x<<n表示第n位设置为x(若x超过一位,则向高位顺延) */
    rADCCON = (0 << 0)     |	// ADC转换设置 未设置
              (0 << 1)     |    // 读AD数据触发AD转换 未使用
              (0 << 2)     |    // StandBy模式选择 为普通操作模式
              (ch << 3)    |    // ADC通道选择 ch
              (49 << 6)    | 	// CLKDIV = Fpclk /49+1/5 ,即转换时钟为1MHz  Fpclk = 10M   ADC转换频率400K
              (1 << 14)   ;	    // 使能软件预设值
    
	Uart_Printf("Select ADC Mode: 1.Enable  2.Read");
	mode=Uart_Getch();
	Uart_Printf("\n%c\n\n", mode);
	
	if (mode!='1' && mode !='2')
	{
		Uart_Printf("you select wrong model!\n");
		return;
	}
	
	switch(mode)
	{
		case '1':
			Uart_Printf("ADC Enable-Convert Mode\n");
			while(Uart_GetKey() != ESC_KEY)
			{
				AD_ENABLE();
			}
			break;
		case '2':
			Uart_Printf("ADC Read-Convert Mode\n");
			while(Uart_GetKey() != ESC_KEY)
			{
				AD_READ();
			}
			break;
//		default:
//			break;
	}
}
//子main函数
void ADC_read_W1(){                     
    static U32 save_A, save_B, save_BD;
    int read_xpdata0;
     
//**********************保护现场************************** 
    save_A   = rADCCON;  
    save_B   = rGPBCON;
    save_BD  = rGPBDAT;
//********************************************************
    
    ADC_display();  
    LED_INIT();  //初始化LED
   
    //while(1)
    Delay(100);Uart_Printf("\n\nq:退出\n");
    while(Uart_GetKey() != 'q')
    {
     /*串口打印变阻器模拟信号数值*/
     W1_ADC( &read_xpdata0 );//传递read_xpdata0地址,改变read_xpdata0的值来给W1_LED函数使用
    
     /*****LED点亮函数*****/
     W1_LED(read_xpdata0);                 //LED函数
     
    }
    
//**********************还原现场**************************         
    rADCCON = save_A;
    rGPBCON = save_B;
    rGPBDAT = save_BD;
//********************************************************    

}
Beispiel #3
0
//==================================================================================
void RTC_Display(void) 
{
	U16 year ;
	U8 month, day ;		// week
	U8 hour, minute, second ;

	RTC_Time_Set() ;
	   
   	Uart_Printf( "RTC TIME Display, press ESC key to exit !\n" ) ;

    while( Uart_GetKey() != ESC_KEY )
    {
		rRTCCON = 1 ;		//RTC read and write enable

		year = 0x2000+rBCDYEAR  ;		//年
	    month = rBCDMON  ;		//月
	    day = rBCDDATE  ;		//日	
//		week = rBCDDAY  ;		//星期
		hour = rBCDHOUR  ;		//小时
	    minute = rBCDMIN  ;		//分
	    second = rBCDSEC  ;		//秒
		
		rRTCCON &= ~1 ;		//RTC read and write disable

	    Uart_Printf( "RTC time : %04x-%02x-%02x %02x:%02x:%02x\n", year, month, day, hour, minute, second );
		Delay( 900 ) ;
    }
}
Beispiel #4
0
/*********************************************************************************************
* name:		Test_Iis
* func:		Test IIS circuit
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Test_Iis(void)
{
	Uart_Printf("\n  CODEC: Philips UDA1341 (U5)\n");
	Uart_Printf("\n  Please listen to sound.");
	Uart_Printf("\n  Press any key to exit ...\n");
	IISInit();					// initialize IIS
    while(Uart_GetKey() == 0)
     {  Playwave();					// play wave
        Delay(5000); }
    IISClose();					// close IIS
}
Beispiel #5
0
void KeyScan_Test(void)
{
	Uart_Printf("\nKey Scan Test, press ESC key to exit !\n");	

	rGPBUP = rGPBUP & ~0x03f0|0x03f0;			//  LED [8:5] => PU En
	rGPBCON = rGPBCON & ~0x3d57fc|0x3d57fc;		//LED[8:5] => OUTPUT;
	rGPFCON = rGPFCON & (~((3<<4)|(3<<0)|(3<<8)|(3<<2))) | ((2<<4)|(2<<0)|(2<<8)|(2<<2)) ;		//GPF4,2,1,0 set EINT
	
	rEXTINT0 &= ~(7|(7<<4)|(7<<8)|(7<<16));	
	rEXTINT0 |= (0|(0<<4)|(0<<8)|(0<<16));		//set eint0,1,2,4 falling edge int


	rEINTPEND |= (1<<4);							//clear eint 4
	rEINTMASK &= ~(1<<4);						//enable eint 4
	ClearPending(BIT_EINT0|BIT_EINT1|BIT_EINT2|BIT_EINT4_7);
	pISR_EINT0 = pISR_EINT1 = pISR_EINT2 = pISR_EINT4_7 = (U32)Key_ISR;
	EnableIrq(BIT_EINT0|BIT_EINT1|BIT_EINT2|BIT_EINT4_7);	

	 while( Uart_GetKey() != ESC_KEY ) ;
	 DisableIrq(BIT_EINT0|BIT_EINT1|BIT_EINT2|BIT_EINT4_7);	
}
Beispiel #6
0
void Dvs_Test(void)
{
	volatile int i, n;

	Uart_Printf("Dvs test.\n");

	rGPGCON = (rGPGCON & ~(3<<22)) | (1<<22);	// set GPG11 output for idle state.
	
	rBANKSIZE = (rBANKSIZE & ~(3<<4)) | (0<<4) | (1<<7);	//SCKE_EN, SCLK_EN = disable.

	Uart_Printf("Change core speed to 266MHz.\n");
	#if FIN==12000000
	ChangeClockDivider(13, 12);	// 1:3:6
		#if CPU2440A==1
		ChangeMPllValue(127,2,1);	// 406MHz
		#else						// 2440X
		ChangeMPllValue(127,2,0);	// 406MHz
		#endif
	#else	// 16.9344Mhz
		ChangeClockDivider(13, 12);
		#if CPU2440A==1
		ChangeMPllValue(110,3,1);	// 400MHz
		#else						// 2440X
		ChangeMPllValue(110,3,0);	// 400MHz
		#endif
	#endif
	
	Calc_Clock(1);
	
	UPDATE_REFRESH(Hclk);
	Uart_Init(Pclk, 115200);

	Uart_Printf("Check Clkout0:FCLK, Clkout1:HCLK.\n");
	// Clkout0: FCLK.	
	Clk0_Enable(2);
	// Clkout1: HCLK.
	Clk1_Enable(3);
	
	
#if ADS10==TRUE	
	srand(0);
#endif
	Led_Display(0);	// clear all leds.
	
	Timer_Setting();
	Set_Lcd_Tft_16Bit_240320_Dvs();

	Uart_Printf("Tcnt, Vcnt, Idle_flag.\n");
	Uart_Printf("%8d,%8d,%1d\n", Timer_cnt0, Vcount, Idle_flag);
	
	while(1) {
		//Uart_Printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
		Uart_Printf("%8d,%8d,%1d\n", Timer_cnt0, Vcount, Idle_flag);
		for(i=0; i<1024*32; i+=4) {
			//*(U32 *)(XADDR+i) = i;
			//*(U32 *)(XADDR+i);
		}
		if(Uart_GetKey()==ESC_KEY) break;
	}

	rINTMSK = BIT_ALLMSK;
}
Beispiel #7
0
void comdownload(void)
{
	ULONG size;
	UCHAR *buf;
	USHORT checksum;

	puts("\nNow download file from uart0...\n");
	downloadAddress = _NONCACHE_STARTADDRESS;
	buf  = (UCHAR *)downloadAddress;
	temp = buf-4;

	Uart_GetKey();

#ifdef	USE_UART_INT
	pISR_UART0 = (ULONG)Uart0RxInt;		//串口接收数据中断
	ClearSubPending(BIT_SUB_RXD0);
	ClearPending(BIT_UART0);
	EnableSubIrq(BIT_SUB_RXD0);
	EnableIrq(BIT_UART0);
#endif

	while((ULONG)temp<(ULONG)buf)
    {
 #ifdef	USE_UART_INT
        Led_Display(0);
        Delay(1000);
        Led_Display(15);
        Delay(1000);
#else
		*temp++ = Uart_Getch();
#endif
    }							//接收文件长度,4 bytes

	size  = *(ULONG *)(buf-4);
	downloadFileSize = size-6;

#ifdef	USE_UART_INT
    printf("Download File Size = %d\n", size);
#endif

	while(((ULONG)temp-(ULONG)buf)<(size-4))
	{
#ifdef	USE_UART_INT
		Led_Display(0);
        Delay(1000);
        Led_Display(15);
        Delay(1000);
#else
		*temp++ = Uart_Getch();
#endif
	}

#ifdef	USE_UART_INT
	DisableSubIrq(BIT_SUB_RXD0);
	DisableIrq(BIT_UART0);
#endif

#ifndef	USE_UART_INT
	printf("Download File Size = %d\n", size);
#endif

	checksum = 0;
	for(size=0; size<downloadFileSize; size++)
		checksum += buf[size];
	if(checksum!=(buf[size]|(buf[size+1]<<8))) {
		puts("Checksum fail!\n");
		return;
	}

	puts("Are you sure to run? [y/n]\n");
	while(1)
	{
		UCHAR key = getch();
		if(key=='n')
			return;
		if(key=='y')
			break;
	}

	call_linux(0, 193, downloadAddress);
}
Beispiel #8
0
void RecordTest(void)
{
	int size, i, j, err;
	WAVEFORMATEX fmt;
	WAVEHDR hdr[2048];
	HWAVEIN hwi = 1;	
	
	Uart_Printf( "\nThe Frequency of record is 48KHz\n" );
	fmt.nSamplesPerSec = 48000;		//²ÉÑùƵÂÊΪ48KHz
	fmt.wBitsPerSample = 16;

	fmt.wFormatTag		= WAVE_FORMAT_PCM;
	fmt.nChannels		= 2;
	fmt.nBlockAlign     = fmt.wBitsPerSample*fmt.nChannels/8;	
	fmt.nAvgBytesPerSec	= fmt.nSamplesPerSec*fmt.nBlockAlign;
	
	downloadAddress  = 0x30800000;//_NONCACHE_STARTADDRESS;
	downloadFileSize = size = 16*1024*1024;	
	i = 0;
	
	while(size>0)
	{
		hdr[i].lpData = (LPSTR)(downloadAddress+0x2c+i*BUF_SIZE);
		hdr[i].dwBufferLength = (size>BUF_SIZE)?BUF_SIZE:size;	
		size -= BUF_SIZE;
		i++;
	}	
	
	*(U16 *)(downloadAddress+0x14) = fmt.wFormatTag;
	*(U16 *)(downloadAddress+0x16) = fmt.nChannels;
	*(U32 *)(downloadAddress+0x18) = fmt.nSamplesPerSec;
	*(U32 *)(downloadAddress+0x1c) = fmt.nAvgBytesPerSec;
	*(U16 *)(downloadAddress+0x20) = fmt.nBlockAlign;
	*(U16 *)(downloadAddress+0x22) = fmt.wBitsPerSample;
	*(U32 *)(downloadAddress+0x28) = downloadFileSize;
	
	err = waveInOpen(&hwi,
				0,
				&fmt,
				0,
				0,
				0);
	Uart_Printf("\nerr = %x\n", err);
	
	for(j=0;j<i;j++)
		if(waveInAddBuffer(hwi, &hdr[j], 0))
			Uart_Printf("Add buffer error!");
			
	Uart_Printf("Added %d buffer for record\n", i);
	Uart_Printf("Press any to Record\n");
	Uart_Getch();
	
	Uart_Printf("Now begin recording, Press 'ESC' to quit\n");	
	waveInStart(hwi);
	
	while(1)
	{
		U8 key;
		
		key = Uart_GetKey();
		if( key == ESC_KEY )
			break;
			
//		Uart_Printf("%x,%x,%x,%x,%x,%x,%x\n", rDISRC2, rDISRCC2, rDIDST2, rDIDSTC2, rDCON2, rDSTAT2, rDMASKTRIG2);		
//		Uart_Printf("%x,%x,%x,%x\n", rIISCON, rIISMOD, rIISPSR, rIISFCON);
	}		
	waveInClose(hwi);
}