zoukankan      html  css  js  c++  java
  • 串口 S3C2440A

    电路图
    1


    寄存器
    2

    #define TXD0READY   (1<<2)
    #define RXD0READY   (1)
    
    #define PCLK            50000000    // init.c中的clock_init函数设置PCLK为50MHz
    #define UART_CLK        PCLK        //  UART0的时钟源设为PCLK
    #define UART_BAUD_RATE  115200      // 波特率
    #define UART_BRD        ((UART_CLK  / (UART_BAUD_RATE * 16)) - 1)
    
    /*
     * 初始化UART0
     * 115200,8N1,无流控
     */
    void uart0_init(void)
    {
        GPHCON  |= 0xa0;    // GPH2,GPH3用作TXD0,RXD0
        GPHUP   = 0x0c;     // GPH2,GPH3内部上拉
    
        ULCON0  = 0x03;     // 8N1(8个数据位,无较验,1个停止位)
        UCON0   = 0x05;     // 查询方式,UART时钟源为PCLK
        UFCON0  = 0x00;     // 不使用FIFO
        UMCON0  = 0x00;     // 不使用流控
        UBRDIV0 = UART_BRD; // 波特率为115200
    }
    
    /*
     * 发送一个字符
     */
    void putc(unsigned char c)
    {
        /* 等待,直到发送缓冲区中的数据已经全部发送出去 */
        while (!(UTRSTAT0 & TXD0READY));
    
        /* 向UTXH0寄存器中写入数据,UART即自动将它发送出去 */
        UTXH0 = c;
    }
    
    /*
     * 接收字符
     */
    unsigned char getc(void)
    {
        /* 等待,直到接收缓冲区中的有数据 */
        while (!(UTRSTAT0 & RXD0READY));
    
        /* 直接读取URXH0寄存器,即可获得接收到的数据 */
        return URXH0;
    }
  • 相关阅读:
    luogu P1340 兽径管理
    luogu P2828 Switching on the Lights(开关灯)
    luogu P1462 通往奥格瑞玛的道路
    codevs 2596 售货员的难题
    luogu P1145 约瑟夫
    luogu P1395 会议
    luogu P1041 传染病控制
    luogu P1198 [JSOI2008]最大数
    codevs 1191 数轴染色
    [POJ1082]Calendar Game
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709433.html
Copyright © 2011-2022 走看看