📄 main.c
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#define KEY_BUFLEN 100
#define AFC_BUFLEN 0x100
#define IrDA_BUFLEN 0x100
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
char Uart_IntGetkey(void);
void __irq Uart0_TxFifoInt(void);
void __irq Uart0_RxFifoInt(void);
void __irq Uart0_RxFifoErrorInt(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;
void Main(void)
{
U8 aa;
int key=0;
int mm,ms;
rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
Isr_Init();
Port_Init();
Uart_Init(0,57600);
Uart_Select(0);
Uart_Printf("\n* 杭州莱顿电子 *");
Uart_Printf("\n* -S3C44B0X功能部件:串口0实验fifo测试- *");
Uart_Printf("\n* Version 1.1 *");
Uart_Printf("\n* COPYRIGHT OF JINJIE *");
Uart_Printf("\n* UART Config--COM:115.2kbps,8Bit,NP,UART0 *");
Uart_Printf("\n");
keyBufRdPt=keyBufWrPt=0;
pISR_UTXD0=(unsigned)Uart0_TxFifoInt;
pISR_URXD0=(unsigned)Uart0_RxFifoInt;
pISR_UERR01=(unsigned)Uart0_RxFifoErrorInt;
/*********** UART0 Rx FIFO test with interrupt ***********/
rUCON0=0x245|0x80; //tx:level,rx:edge,tx/rx:int,rcv_time_out enabled,error int enable
Uart_Printf("\n[Uart channel 0 FIFO 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_URXD0|BIT_UERR01);
while( (rUFSTAT0&0xf) >0 )
key=RdURXH0(); //To clear the Rx FIFO
while(1)
{
Led_Display(0x01);
for(mm=0;mm<2000;mm++)
for(ms=0;ms<400;ms++);
Led_Display(0x01<<1);
for(mm=0;mm<2000;mm++)
for(ms=0;ms<400;ms++);
}
}
void __irq Uart0_RxFifoInt(void)
{
rI_ISPC=BIT_URXD0;
while( (rUFSTAT0&0xf) >0 ) //until FIFO is empty
{
keyBuf[keyBufWrPt++]=rURXH0; //rx buffer->keyBuf[]
if(keyBufWrPt==KEY_BUFLEN)
keyBufWrPt=0;
}
Uart_SendByte(keyBuf[keyBufWrPt-1]); //Print the letter receive just now
Led_Display(0x07);
Delay(2000);
Led_Display(0x00);
Delay(2000);
Led_Display(0x07);
Delay(2000);
Led_Display(0x00);
Delay(2000);
Led_Display(0x07);
Delay(2000);
Led_Display(0x00);
Delay(2000);
Led_Display(0x07);
Delay(2000);
Led_Display(0x00);
Delay(2000);
}
void __irq Uart0_RxFifoErrorInt(void)
{
rI_ISPC=BIT_UERR01;
switch(rUERSTAT0) //to clear and check the status of register bits
{
case '1':
Uart_Printf("Overrun error\n");
break;
case '2':
Uart_Printf("Parity error\n");
break;
case '4':
Uart_Printf("Frame error\n");
break;
case '8':
Uart_Printf("Breake detect\n");
break;
default :
break;
}
while( (rUFSTAT0&0xf) >0 )
{
keyBuf[keyBufWrPt++]=rURXH0;
if(keyBufWrPt==KEY_BUFLEN)
keyBufWrPt=0;
}
}
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 + -