實驗目的:

1.掌握ARM 的串列口工作原理。

2.學習編程實現ARM UART 通訊。

3.掌握CPU 利用串口通訊的方法。

ARM 監視串列口,將接收到的字元再發送給串口(電腦與開發板是通過超級終端通訊的)

,即按PC 鍵盤通過超級終端發送資料,開發板將接收到的資料再返送給PC,在超級終端

上顯示,如果是小寫字母,則先轉換成大寫字母

#include <stdlib.h>

#include <string.h>

 

//Shin, On Pil

#include "def.h"

#include "option.h"

#include "2410addr.h"

#include "2410lib.h"

#include "2410slib.h"

#include "2410RTC.h"

 

 

//#include "cpuspeed.h"

 

 

 

void Isr_Init(void);

void HaltUndef(void);

void HaltSwi(void);

void HaltPabort(void);

void HaltDabort(void);

 

void * function[][2]=

{

 

    0,0

};

 

//===================================================================

void Main(void)

{

    int i;

    int uartch;

    Led_Display(15);

   

    MMU_Init();

  

#if ADS10  

    __rt_lib_init();                //for ADS 1.0

#endif

   

 

    ChangeClockDivider(1,1);          // 1:2:4   

 

 

    ChangeMPllValue(0xa1,0x3,0x1);    // FCLK=202.8MHz 

 

   

    Port_Init();

    Isr_Init();

    Rtc_Init();

    Uart_Init(0,115200);

    Uart_Select(0);

 

    //Check whether or not the POWER_OFF wake-up.

    Delay(0);   //calibrate Delay()

   

    Test_Rtc_Tick();

    /*Save the wasted power consumption on GPIO.

    rIISPSR=(2<<5)|(2<<0); //IIS_LRCK=44.1Khz @384fs,PCLK=50Mhz.

    rGPHCON = rGPHCON & ~(0xf<<18)|(0x5<<18);   //CLKOUT 0,1=OUTPUT to reduce the power consumption.

 

    Uart_Printf("Please input char\n");

    while(1)

    {

            uartch=Uart_Getch();

            if((uartch>='a')&&(uartch<='z'))

                uartch=uartch+'A'-'a';

            Uart_SendByte(uartch);

           

    }*/

}

 

//===================================================================

void Isr_Init(void)

{

    pISR_UNDEF  = (unsigned)HaltUndef;

    pISR_SWI    = (unsigned)HaltSwi;

    pISR_PABORT = (unsigned)HaltPabort;

    pISR_DABORT = (unsigned)HaltDabort;

   

    rINTMOD     = 0x0;                     //All=IRQ mode

    // rINTCON=0x5;                           //Non-vectored,IRQ enable,FIQ disable   

    rINTMSK     = BIT_ALLMSK;              //All interrupt is masked.

    rINTSUBMSK  = BIT_SUB_ALLMSK;          //All sub-interrupt is masked. <- April 01, 2002 SOP

 

 

}

 

//===================================================================

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);

}