新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > AVR的uart串口通信程序

        AVR的uart串口通信程序

        作者: 時間:2018-09-14 來源:網絡 收藏

        //1、使用ICC的終端調試窗口(Terminal),進行通信調試。
        //2、對ICC的終端調試窗口進行設置,設置串口為com1或com2
        //通信波特率為19200(Tools->EnvironmentOptions...)。
        //3、將PC屏幕光標定位于調試窗口中。
        #include
        #definefosc8000000//晶振8MHZ
        #definebaud19200//波特率
        #defineosc_address0x1ff0
        externunsignedcharread_flash(unsignedintadd);

        voidputchar(unsignedcharc)
        {
        while(!(UCSRA(1UDR=c;
        }

        unsignedchargetchar(void)
        {
        while(!(UCSRA(1returnUDR;
        }

        intputs(char*s)
        {
        while(*s)
        {
        putchar(*s);
        s++;
        }
        putchar(0x0a);//回車換行
        putchar(0x0d);
        return1;
        }

        voidputstr(char*s)
        {
        while(*s)
        {
        putchar(*s);
        s++;
        }
        }

        void_init(void)
        {
        OSCCAL=read_flash(osc_address);
        UCSRB=(1UBRRL=(fosc/16/(baud+1))%6;
        UBRRH=(fosc/16/(baud+1))/256;
        UCSRC=(1}

        voidmain(void)
        {
        unsignedchari;
        _init();
        puts(廣州天河雙龍電子公司RS232通信演示程序);
        puts(HTTP://WWW.SL.COM.CN);
        puts(MAILTsllg@sl.com.cn);
        while(1)
        {
        i=getchar();
        if(i!=0)//按PC鍵盤開始測試
        {
        putstr(當前按鍵是:);
        putchar(i);
        putchar(0x0a);
        putchar(0x0d);
        puts(廣州天河雙龍電子公司RS232通信演示程序);
        puts(HTTP://WWW.SL.COM.CN);
        puts(MAILTsllg@sl.com.cn);
        putchar(0x0a);
        putchar(0x0d);
        }
        }
        }

        本文引用地址:http://www.104case.com/article/201809/389164.htm


        關鍵詞: AVR uart 串口通信

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 平阳县| 嘉荫县| 宣汉县| 三都| 惠州市| 南阳市| 工布江达县| 南城县| 兰州市| 邢台县| 红安县| 平江县| 南木林县| 宕昌县| 靖边县| 图片| 宁城县| 土默特右旗| 当阳市| 龙川县| 偃师市| 五指山市| 驻马店市| 峨眉山市| 临武县| 南通市| 饶阳县| 贡嘎县| 宁陵县| 英超| 渝中区| 鹰潭市| 灵寿县| 洛阳市| 东乌| 石家庄市| 禹州市| 清新县| 周至县| 馆陶县| 河曲县|