zoukankan      html  css  js  c++  java
  • 51串口通信

    #include <reg52.h>
    unsigned char m;
    unsigned char flag;
    unsigned char tvb;
    unsigned char xianshi;

    void main()
    {
    TMOD=0x20; //设置定时器1为方式2
    TH1=0xfd; //装入处初值
    TL1=0xfd;
    TR1=1; //启动定时器
    SM0=0;//
    SM1=1; // shezhifangshi1
    REN=1;//接收使能
    EA=1;
    ES=1;
    while(1)
    {
    if(tvb==1)
    {
    ES=0;
    tvb=0;
    SBUF=m;
    while(!TI);//等待数据发送结束
    TI=0;
    ES=1;
    }
    }
    }
    void chuakou() interrupt 4
    {
    m = SBUF;
    if(m > 0 && m <= 6)
    flag = 1;
    else if( m >= 7 && m <= 13)
    flag = 2;
    else if( m >= 14 && m <= 20)
    flag = 3;
    else
    flag = 0xff;

    switch( flag )
    {
    case 1:
    P1 = 0xfe;
    break;
    case 2:
    P1 = 0xfd;
    break;
    case 3:
    P1 = 0xfb;
    break;
    case 0xff:
    P1 = 0xff;
    break;
    default:
    P1 = 0xff;
    break;
    }
    RI = 0;
    tvb = 1;//标志
    }
  • 相关阅读:
    Oracle Golden Gate
    DNS
    RMAN 管理
    黄伟-RAC生产库现场调整本分策略实战
    Linux下RAID技术
    OCP之黄伟 2
    About NULL Value
    OCP之黄伟
    Table
    Perl的简单变量
  • 原文地址:https://www.cnblogs.com/tao560532/p/2315678.html
Copyright © 2011-2022 走看看