?? main.c
字號:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#define KEY_BUFLEN 100
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void __irq Uart1_RxInt(void);
void __irq Uart1_TxInt(void);
char Uart_IntGetkey(void);
static unsigned char keyBuf[KEY_BUFLEN];
volatile static int IrDA_BAUD,keyBufRdPt=0;
volatile static int keyBufWrPt=0;
volatile char out=1;
static char *uart0TxStr;
static char *uart1TxStr;
void Main(void)
{
U8 aa;
int key;
rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
Isr_Init();
Port_Init();
Uart_Init(0,115200);
Uart_Select(0);
Delay(0); //calibrate Delay()
Led_Display(7);
Delay(1000); //calibrate Delay()
Led_Display(0);
Delay(5000); //calibrate Delay()
Led_Display(7);
keyBufRdPt=keyBufWrPt=0;
pISR_UTXD1=(unsigned)Uart1_TxInt;
pISR_URXD1=(unsigned)Uart1_RxInt;
/*********** UART1 Tx test with interrupt ***********/
Uart_Printf("[Uart channel 1 tx Interrupt Test]\n");
Uart_Printf("Plug the serial cable into ch1 connector!!! \n");
Uart_Printf("Then, press any key through UART ch1.\n");
Uart_Select(1);
Uart_Getch();
uart1TxStr="UART1 Tx interrupt test is good!!!!\r\n";
rINTMSK=~(BIT_GLOBAL|BIT_UTXD1);
// rUCON1 &= 0x3f3;
// rUCON1 |= 0x4; //needed to set the UTXD0 pending bit.
rUCON1 = 0x244; //rx:edge,tx:level,error int,normal*2,interrupt(Start)
Delay(3000);
/*********** UART1 Tx test with BDMA1 ***********/
rUCON1 = 0x245;
Uart_Printf("\n[Uart1 Tx Test by BDMA1]\n");
uart1TxStr="UART1 Tx Test by BDMA1 is good!!!!\r\n";
Uart_TxEmpty(1);
rUCON1=0x4c; //tx:BDMA0 rx:disable
rBDICNT1=0x0;
rBDCON1 =0x0;
rBDISRC1=(unsigned int)uart1TxStr|(0<<30)|(1<<28); // byte,inc
rBDIDES1=UTXH1 |(1<<30)|(3<<28); //L/B endian,M2IO,fix
rBDICNT1=strlen(uart1TxStr)|(1<<31)|(1<<26)|(1<<20); //UART1,
while(!((rBDCON1&0x30)==0x20));
Uart_TxEmpty(1);
/*********** UART1 Rx test with interrupt ***********/
rUCON1=0x45; //tx:int rx:int
Uart_Printf("\n[Uart channel 1 Rx Interrupt Test]:Type any key!!!\n");
Uart_Printf("You have to see the typed character. To quit, press Enter key.\n");
rINTMSK=~(BIT_GLOBAL|BIT_URXD1);
keyBufRdPt=keyBufWrPt=0;
while((key=Uart_IntGetkey())!='\r')
Uart_SendByte(key);
rINTMSK=~BIT_GLOBAL;
Uart_Printf("\n");
Uart_Printf("Plug the serial cable into ch0 as before this test!!!\n");
Uart_Printf("Then, press any key through UART ch 0.\n");
Uart_Select(0);
Uart_Getch();
}
void __irq Uart1_RxInt(void)
{
rI_ISPC=BIT_URXD1;
keyBuf[keyBufWrPt++]=RdURXH1();
if(keyBufWrPt==KEY_BUFLEN)
keyBufWrPt=0;
}
void __irq Uart1_TxInt(void)
{
// rI_ISPC=BIT_UTXD1;
if(*uart1TxStr != '\0')
{
WrUTXH1(*uart1TxStr++);
rI_ISPC=BIT_UTXD1;
}
else
{
rUCON1 &= 0x3f3;//workaround
rI_ISPC=BIT_UTXD1;
rINTMSK|=BIT_UTXD1;
}
}
char Uart_IntGetkey(void)
{
if(keyBufRdPt==KEY_BUFLEN)
keyBufRdPt=0;
while(keyBufWrPt==keyBufRdPt); //until FIFO is triggered
return keyBuf[keyBufRdPt++];
}
void Isr_Init(void)
{
U32 i;
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
{
*((volatile unsigned *)i)=0xEA000000+0x1FFE;
}
//rINTCON=0x1; // Vectored Int. IRQ enable,FIQ disable
rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; // All=IRQ mode
rINTMSK|=BIT_GLOBAL|BIT_EINT3; // All interrupt is masked.
}
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -