• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 通信波特率115.2K的串行通信C語言示例

    通信波特率115.2K的串行通信C語言示例

    作者: 時間:2012-02-19 來源:網(wǎng)絡 收藏

    unsigned char time_out;

    本文引用地址:http://www.czjhyjcfj.com/article/172057.htm

    void init_com1(void) {
    outportb(0x3fb,0x80);
    outportb(0x3f8,1);
    outportb(0x3f9,0x0);
    outportb(0x3fb,0x3);
    }
    void sen_com1(unsigned char d) {
    long i;
    time_out=0;
    while (!(inportb(0x3fd)0x20));
    outportb(0x3fd,0x0);
    outportb(0x3f8,d);
    i=clock();
    while (1) {
    if (clock()>(i+8)) {time_out=1;return;}
    if ((inp(0x3fd)0x1)==1) break;
    }
    if (inp(0x3f8)!=d) {time_out=2;return;}
    }
    unsigned char rec_com1(void) {
    long i;
    unsigned char d;
    time_out=0;
    i=clock();
    while (1) {
    if (clock()>(i+8)) {time_out=1;return(0);}
    if ((inp(0x3fd)1)==1) break;
    }
    d=inp(0x3f8);
    while (!(inportb(0x3fd)0x20));
    outportb(0x3fd,0x0);
    outportb(0x3f8,d);
    return(d);
    }
    void main(void) {
    int i;
    long st;
    init_com1();
    st=clock();
    sen_com1(0xaa);
    if (time_out) {printf(CPU not ready!);exit(-1);}
    sen_com1(0xaa);
    if (time_out) {printf(CPU not ready!);exit(-1);}
    for (i=0;i1000;i++) {
    sen_com1(i);
    if (time_out) {printf(CPU not ready!);exit(-1);}
    }
    printf(Total use %3.2f S.,(clock()-st)/18.2);
    exit(1);
    }


    上一頁 1 2 下一頁

    評論


    相關推薦

    技術專區(qū)

    關閉
    主站蜘蛛池模板: 林口县| 崇文区| 五指山市| 社会| 乌恰县| 玛纳斯县| 晋中市| 黔东| 襄城县| 涡阳县| 临沧市| 青浦区| 雅安市| 旅游| 阿拉善右旗| 濮阳县| 奎屯市| 凌海市| 成武县| 弥勒县| 木兰县| 太仓市| 永吉县| 普兰店市| 双城市| 洛扎县| 德州市| 临潭县| 耒阳市| 新乐市| 通江县| 定陶县| 玉门市| 中西区| 陇川县| 湟源县| 乌恰县| 乌鲁木齐县| 德化县| 汪清县| 隆德县|