1. #include "exynos_4412.h"
    2. void UART_Init(void)
    3. {
    4. /*1.将GPA1_0和GPA1_1设置成UART2的接收和发送引脚 GPA1CON[7:0]*/
    5. GPA1.CON = GPA1.CON & (~(0xFF << 0)) | (0x22 << 0);
    6. /*2.设置UART2的帧格式 8位数据位 1位停止位 无校验 正常模式 ULCON2[6:0]*/
    7. UART2.ULCON2 = UART2.ULCON2 & (~(0x7F << 0)) | (0x3 << 0);
    8. /*3.设置UART2的接收和发送模式为轮询模式 UCON2[3:0]*/
    9. UART2.UCON2 = UART2.UCON2 & (~(0xF << 0)) | (0x5 << 0);
    10. /*4.设置UART2的波特率为115200 UBRDIV2/UFRACVAL2*/
    11. UART2.UBRDIV2 = 53;
    12. UART2.UFRACVAL2 = 4;
    13. }
    14. void UART_Send_Byte(char Dat)
    15. {
    16. /*等待发送寄存器为空,即上一个数据已经发送完成 UTRSTAT2[1]*/
    17. while(!(UART2.UTRSTAT2 & (1 << 1)));
    18. /*将要发送的数据写入发送寄存器 UTXH2*/
    19. UART2.UTXH2 = Dat;
    20. }
    21. char UART_Rec_Byte(void)
    22. {
    23. char Dat = 0;
    24. /*判断接收寄存器是否接收到了数据 UTRSTAT2[0]*/
    25. if(UART2.UTRSTAT2 & 1)
    26. {
    27. /*从接收寄存器中读取接收到的数据 URXH2*/
    28. Dat = UART2.URXH2;
    29. return Dat;
    30. }
    31. else
    32. {
    33. return 0;
    34. }
    35. }
    36. void UART_Send_Str(char * pstr)
    37. {
    38. while(*pstr != '\0')
    39. UART_Send_Byte(*pstr++);
    40. }
    41. int main()
    42. {
    43. char RecDat = 0;
    44. UART_Init();
    45. while(1)
    46. {
    47. /*
    48. RecDat = UART_Rec_Byte();
    49. if(RecDat == 0)
    50. {
    51. }
    52. else
    53. {
    54. RecDat = RecDat + 1;
    55. UART_Send_Byte(RecDat);
    56. }
    57. */
    58. /*
    59. UART_Send_Str("Hello World\n");
    60. */
    61. printf("Hello World\n");
    62. }
    63. return 0;
    64. }