新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 串行通信UART及PROTEUS仿真設計

        串行通信UART及PROTEUS仿真設計

        作者: 時間:2010-06-26 來源:網絡 收藏

        atmega64的程序:

        兩個文件,一個是將函數模塊化,別一個是主函數,調用(- -!最近習慣將程序模塊化。。。)

        //------------------uart.c---------------------

        //----這里將函數模塊化------------

        #include iom64v.h>

        void uart0_init(void)
        {
        UCSR0B = 0x00; //disable while setting baud rate
        UCSR0A = 0x00;
        UCSR0C = 0x06;
        UBRR0L = 0x33; //set baud rate lo
        UBRR0H = 0x00; //set baud rate hi
        UCSR0B = 0x18;
        }


        void uart0_Transmit( unsigned char data )
        {
        /* Wait for empty transmit buffer */
        while ( !( UCSR0A (1UDRE0)) )
        ;
        /* Copy ninth bit to TXB8 */
        UCSR0B = ~(1TXB80);
        //if ( data 0x0100 )
        //UCSR0B |= (1TXB80);
        /* Put data into buffer, sends the data */
        UDR0 = data;
        }

        unsigned char uart0_Receive( void )
        {
        /* 等待接收數據*/
        while ( !(UCSR0A (1RXC0)) )
        ;
        /* 從緩沖器中獲取并返回數據*/
        return UDR0;
        }

        //--------------main.c-----------

        //--------------------------------

        #include iom64v.h>
        #include spi.h
        #define commun_symbol 0x31

        //-----------send a commun_symbol-----
        //-----------receive a commun_symbol--
        // --no,continue receive||||||yes-->receive the data and send
        void main()
        {
        unsigned char bybuff;
        DDRB=0xff;
        PORTB=0xff;
        uart0_init();
        {

        do
        {
        bybuff=uart0_Receive();
        }
        while (bybuff!=commun_symbol);//commun_symbol);
        while(1)
        {

        uart0_Transmit(bybuff);
        bybuff=uart0_Receive();
        PORTB=(0xff|bybuff);
        }
        }
        }

        ok,任務完成了,改天實驗一下!


        上一頁 1 2 下一頁

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 垫江县| 漳浦县| 原平市| 黑水县| 广水市| 米泉市| 浏阳市| 永寿县| 开原市| 桃源县| SHOW| 天全县| 孝义市| 乐业县| 黎城县| 夏津县| 虞城县| 津南区| 抚宁县| 错那县| 张家界市| 上饶县| 绥滨县| 漳平市| 青龙| 天峨县| 依安县| 中卫市| 镇平县| 疏附县| 长沙县| 隆子县| 吉林市| 永定县| 青浦区| 上饶市| 郁南县| 苍梧县| 广南县| 石柱| 宁河县|