?? uart_test.c
字號(hào):
#define LPCEB2000_I
/*********************************************************************************************
* File: uart_test.c
* Author: Embest w.h.xie
* Desc: test uart0 port
* History:
*********************************************************************************************/
#include "target.h"
extern void irq_uart0(void);
uint8 ucNewData,ucDataBuf[8];
/*********************************************************************************************
* name: time_dly
* func: display code
* para: dly --in, delay value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void time_dly(uint32 dly)
{
uint32 i;
for(; dly>0; dly--)
for(i=0; i<500; i++);
}
/*********************************************************************************************
* name: irq_uart0_srv
* func: uart0 interrupt code
* para: none
* ret: none
* modify:
* comment: receive 8 byte then send data
*********************************************************************************************/
void irq_uart0_srv(void)
{
uint8 i;
if ( 0x04==(UART0_IIR&0x0F) )
{
ucNewData = 1;
for(i=0; i<8; i++)
ucDataBuf[i] = UART0_RBR;
}
//interrupt finish
VICVectAddr = 0x00;
}
/*********************************************************************************************
* name: sys_init
* func: init the sys
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void sys_init()
{
// allow PLL
PLLCON = 1;
VPBDIV = PLL_VPBDIV;
PLLCFG = PLL_CFG;
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
// set MAM 2 CCLK
MAMCR = 0;
MAMTIM = MAM_TIM;
MAMCR = 2;
// init all interrupt
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
}
/*********************************************************************************************
* name: Main
* func: main fun
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int Main(void)
{
uint8 i;
uint16 bauddiv;
// init GPIO, open uart0
PINSEL0 = 0x00000005;
PINSEL1 = 0x00000000;
sys_init();
// init interrupt
VICIntSelect = 0x00000000;
VICVectCntl0 = 0x26;
VICVectAddr0 = (int)irq_uart0;
VICIntEnable = 0x00000040;
// init uart0
UART0_LCR = 0x80;
bauddiv = (10000000>>4)/9600;
UART0_DLM = bauddiv>>8;
UART0_DLL = bauddiv&0xff;
UART0_LCR = 0x03;
UART0_FCR = 0x81;
UART0_IER = 0x01;
ucNewData = 0;
do
{
if (ucNewData == 1)
{
ucNewData = 0;
for(i=0; i<8; i++)
UART0_THR = ucDataBuf[i];
while( (UART0_LSR&0x20)==0 );
}
}
while(1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -