📄 usb 全套程序.cpp
字号:
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "option.h"
void D12Main(void);
void Isr_Init(void);
void DebugUNDEF(void);
void DebugSWI(void);
void DebugPABORT(void);
void DebugDABORT(void);
/************************************************************************/
/*时钟初始化*/
/************************************************************************/
#define EXT_OSC_CLK 10000000
struct{
U32 mclk;
U32 pclk;
U32 sclk;
U32 freq;
} ClkPara;
void set_pll(void)
{
U32 i, j;
if(ClkPara.mclk>255)
ClkPara.mclk = 255;
if(ClkPara.pclk>63)
ClkPara.pclk = 63;
if(ClkPara.sclk>3)
ClkPara.sclk = 3;
j = ClkPara.sclk;
i = 1;
while(j--)
i *= 2;
ClkPara.freq = (EXT_OSC_CLK*(ClkPara.mclk+8))/((ClkPara.pclk+2)*i);
if((ClkPara.freq>=90000000)||(ClkPara.freq<EXT_OSC_CLK)) {
ClkPara.mclk = 114;
ClkPara.pclk = 8;
ClkPara.pclk = 1;
ClkPara.freq = EXT_OSC_CLK*122/20;
}
rPLLCON = (ClkPara.mclk << 12) | (ClkPara.pclk << 4) | ClkPara.sclk;
}
void SystemClockInit(void)
{
ClkPara.mclk = 88;
ClkPara.pclk = 8;
ClkPara.sclk = 1;
set_pll();
}
U32 GetCpuClock(void)
{
return ClkPara.freq;
}
U32 GetMasterClock(void)
{
return GetCpuClock();
}
void TimerInit(U32 HZ)
{
rTCON &= ~(0xf<<24); //clear manual update bit, stop Timer5
rTCFG0 &= ~(0xff<<16); //set Timer 4&5 prescaler 1/2
rTCFG0 |= 1<<16;
rTCFG1 &= ~(0xf<<20); //set Timer 5 MUX 1/16
rTCFG1 |= 3<<20;
rTCNTB5 = GetCpuClock()/(HZ*2*16)-1;
rTCON |= 2<<24; //manual update
rTCON &= ~(2<<24); //clear manal update bit
153
rTCON |= (5<<24); //auto reload, inverter on, start Timer 5
}
/******************************************************************************
【功能说明】系统主函数
******************************************************************************/
void Main(void)
{
SystemClockInit();
TimerInit(1000);
rNCACHBE0=( (0xa000000>>12)<<16 )|((0x8000000>>12) ); //flash area(Bank0) must be
non-cachable area.
rSYSCFG=rSYSCFG & (~0x8); //write buffer has to be off for proper timing.
//rNCACHBE0=(((Non_Cache_End)>>12)<<16)|((Non_Cache_Start)>>12);
//Port_Init();
//Isr_Init();
Uart_Select(0);
Uart_Init(ClkPara.freq,115200);
//Uart_Printf( "PDIUSBD12 test!\n\n" ) ;
D12Main();
while(1);
}
//******************************************************************************
*************************
/*************************************************************************
【功能说明】Intterupt Initiate
*************************************************************************/
void DebugUNDEF(void)
{
Uart_Printf("Enter DebugUNDEF");
while(1)
{
Led_Display( 0xf ) ; Delay( 1000 ) ;
Led_Display( 0x0 ) ; Delay( 1000 ) ;
}
}
//************************************************************************
void DebugSWI(void)
{
Uart_Printf("Enter DebugSWI");
while(1)
{
Led_Display( 0xf ) ; Delay( 1000 ) ;
Led_Display( 0x0 ) ; Delay( 1000 ) ;
}
}
//************************************************************************
void DebugPABORT(void)
{
Uart_Printf("Enter DebugPABORT");
while(1)
{
Led_Display( 0xf ) ; Delay( 1000 ) ;
Led_Display( 0x0 ) ; Delay( 1000 ) ;
}
}
//************************************************************************
void DebugDABORT(void)
{
Uart_Printf("Enter DebugDABORT");
while(1)
{
Led_Display( 0xf ) ; Delay( 1000 ) ;
Led_Display( 0x0 ) ; Delay( 1000 ) ;
}
}
//************************************************************************
void DebugFIQ(void)
{
Uart_Printf("Enter DebugFIQ");
while(1)
{
Led_Display( 0xf ) ; Delay( 1000 ) ;
Led_Display( 0x0 ) ; Delay( 1000 ) ;
}
}
//************************************************************************
/*************************************************************************
【功能说明】
*************************************************************************/
void Isr_Init(void)
{
rINTMSK=BIT_GLOBAL; // All interrupt is masked.
//rINTCON=0x1; // Vectored Int. IRQ enable,FIQ disable
rINTCON=0x5; //Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; //All=IRQ mode
pISR_UNDEF=(unsigned)DebugUNDEF ;
pISR_SWI =(unsigned)DebugSWI ;
pISR_PABORT=(unsigned)DebugPABORT ;
pISR_DABORT=(unsigned)DebugDABORT ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -