www.pudn.com > USBdiskRW.rar > 44btest.c


#include "def.h" 
#include "44b.h" 
#include "utils.h" 
 
 
#define	BAUD_RATE	115200 
 
extern void SL811Main(void); 
 
volatile char which_int_key = 0 ; 
void __irq Key_Interrupt(void) 
{	 
    which_int_key = rEXTINTPND ; 
    rEXTINTPND = 0xf ;		//clear EXTINTPND reg.		 
    rI_ISPC = BIT_EINT4567 ;		//clear pending_bit 
 
    rPCONG = rPCONG & (~(0x3f<<10));		//GPC567 is input 
 
    switch(which_int_key) 
   { 
        	case 1: 
        	    //printf("\nEINT4 had been occured...\n"); 
				LedSet(0x2); 
        	    which_int_key=0; 
        	    break; 
        	case 2: 
        	    printf("\nEINT5 had been occured...\n"); 
				LedSet(0x4); 
        	    which_int_key=0; 
        	    break; 
        	case 4: 
        	    printf("\nEINT6 had been occured...\n"); 
				LedSet(0x8); 
        	    which_int_key=0; 
        	    break; 
        	case 8: 
        	    printf("\nEINT7 had been occured...\n"); 
				LedSet(0x1); 
        	    which_int_key=0; 
        	    break; 
        	default : 
        	    break; 
    } 
  
 	while( (rPDATG&0x00e0) != 0x00e0  ) ; 
 	Delay( 50 ) ;		// 
    rPCONG = rPCONG | ( 0x3f<<10 );		//EINT7~5 
} 
 
void HaltUndef(void) 
{ 
    printf("Undefined instruction exception!!!\n"); 
    while(1) 
    { 
    	LedSet( 0x00 )	;		// 
    	Delay(500) ;		// 
    	LedSet( 0x0f )	;		// 
    	Delay(500) ;		// 
    } 
} 
 
void HaltSwi(void) 
{ 
    printf("SWI exception!!!\n"); 
    while(1) 
    { 
    	LedSet( 0x00 )	;		// 
    	Delay(500) ;		// 
    	LedSet( 0x0f )	;		// 
    	Delay(500) ;		// 
    } 
} 
 
void HaltPabort(void) 
{ 
    printf("Pabort exception!!!\n"); 
    while(1) 
    { 
    	LedSet( 0x00 )	;		// 
    	Delay(500) ;		// 
    	LedSet( 0x0f )	;		// 
    	Delay(500) ;		// 
    } 
} 
 
void HaltDabort(void) 
{ 
    printf("Dabort exception!!!\n"); 
    while(1) 
    { 
    	LedSet( 0x00 )	;		// 
    	Delay(500) ;		// 
    	LedSet( 0x0f )	;		// 
    	Delay(500) ;		// 
    } 
} 
 
void Isr_Init(void) 
{ 
    pISR_UNDEF=(unsigned)HaltUndef; 
    pISR_SWI  =(unsigned)HaltSwi; 
    pISR_PABORT=(unsigned)HaltPabort; 
    pISR_DABORT=(unsigned)HaltDabort; 
 
    rINTMSK = BIT_GLOBAL;	  // All interrupt is masked. 
 
	rINTCON = 0x5 ;		//无向量中断模式 
	rINTMOD = 0x0 ;		//All=IRQ mode 
} 
 
void Eint567_Test( void ) 
{ 
	printf( "\nInterrupt Test!\n" ); 
	 
    printf("\n\n注意由于本项测试使用了中断,所以必须将本项目的目标代码烧写入Flash的0地址\n"); 
    printf("这样Flash中才有中断向量,不过只需要烧入一次就行了,以后JTAG调试或网口下载运行本程序就没有问题了\n"); 
    printf("可以使用netload或者是comload下载本目标代码到SDRAM,然后用Prog 0烧写代码到Flash(不覆盖0地址跳转指令)\n\n"); 
 
    pISR_EINT4567 = (unsigned)Key_Interrupt ; 
 
	rINTCON = 0x5 ;		//无向量中断模式 
	rINTMOD = 0x0 ;		//All=IRQ mode 
 
    rPCONG = rPCONG | ( 0x3f<<10 );		//EINT7~5 
    rPUPG = rPUPG & (~(7<<5)) ;		//pull up resister is enable 
	rEXTINT = rEXTINT & (~(0xfff<<20)) ;		//EINT567低电平触发中断 
	 
    pISR_EINT4567 = (unsigned)Key_Interrupt ; 
    rINTMSK = ~( BIT_GLOBAL | BIT_EINT4567 ) ;		//start INT 
 
	printf( "\nPlease press the button key2,key3,key4!   Press ESC to Exit!\n" ); 
	 
    while( !( kbhit && (getkey()==ESC_KEY) ) )  
    { 
		LedSet(0x05);		//LED点亮/熄灭状态设置 
		Delay(160); 
		LedSet(0x0a);		//LED点亮/熄灭状态设置 
		Delay(160); 
    } 
 
    rINTMSK = BIT_GLOBAL ;	//disable INT 
} 
 
void LedDisp(void) 
{ 
	LedSet(0x08);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x04);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x02);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x01);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x02);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x04);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x08);		//LED点亮/熄灭状态设置 
	Delay(150); 
	LedSet(0x00);		//LED点亮/熄灭状态设置 
} 
 
TIME_STRUC SysTime; 
char *WeekDay[7] = {"MON", "TUES", "WED", "THURS","FRI", "SAT", "SUN"}; 
 
void Main(void) 
{ 
	SystemClockInit(); 
	 
	TimerInit(1000); 
	 
	MemCfgInit(); 
	 
	PortInit(); 
	 
	Isr_Init(); 
	 
	NandFlashInit();	 
		 
	CacheDisable(); 
	CacheFlush(); 
	CacheEnable(); 
 
	SerialSwitch(0); 
	SerialChgBaud(BAUD_RATE); 
	ShowBootInfo(); 
	NandFlashStatusRep(); 
 
	printf("Build  date : %s--%s\n", __DATE__, __TIME__); 
	printf("Serial baud : %d\n", BAUD_RATE); 
	printf("CPU clock is %dHz, Master clock is %dHz\n", GetCpuClock(), GetMasterClock()); 
	 
	RtcGetTime(&SysTime); 
	printf("Current date is %x-%x-%x [%s]\n", SysTime.year, SysTime.month, SysTime.day, WeekDay[(SysTime.weekday-1U)%7U]); 
	printf("Current time is %2x:%2x:%2x\n", SysTime.hour, SysTime.min, SysTime.sec); 
	//while(1) 
	//{ 
	SL811Main(); 
  
	//} 
}