中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 用VC實(shí)現(xiàn)PC機(jī)與單片機(jī)的通信

        用VC實(shí)現(xiàn)PC機(jī)與單片機(jī)的通信

        作者: 時(shí)間:2012-03-19 來(lái)源:網(wǎng)絡(luò) 收藏

        控件ID 類型 數(shù)據(jù)成員
        IDC_EDIT1_SEND Cstring m_send
        IDC_EDIT2_RECV Cstring m_recv
        IDC_MSCOMM1 CMSComm m_comm
        IDCANCEL

        4)部分源程序代碼如下:
        BOOL CChatDlg::OnInitDialog( )
        {
        CDialog::OnInitDialog( );
        // TODO: Add extra initialization here
        m_comm.SetCommPort(1); //選擇串口1
        if(!m_comm.GetPortOpen( ))
        m_comm.SetPortOpen(TRUE); //打開(kāi)串口1
        m_comm.SetSettings(9600,n,8,1); //串口參數(shù)設(shè)置
        m_comm.SetRThreshold(1); //當(dāng)串口接收緩沖區(qū)內(nèi)接收字符多于或等于1將觸發(fā)一關(guān)于comEvReceive的OnComm事件。
        return TRUE; // return TRUE unless you set the focus to a control
        // EXCEPTION: OCX Property Pages should return FALSE
        }
        void CChatDlg::OnChangeEdit1Send( )
        { // TODO: Add your control notification handler code here
        int count;
        CString temp;
        UpdateData(TRUE); //獲取用戶輸入數(shù)據(jù)
        count=m_send.GetLength( ); //獲取編輯框內(nèi)字符數(shù)
        temp=m_send.GetAt(count-1); //取最新輸入字符
        if(!m_comm.GetPortOpen( ))
        m_comm.SetPortOpen(TRUE);
        m_comm.SetOutput(COleVariant(temp)); //發(fā)送數(shù)據(jù)
        if(count= =40) //如輸入字符超過(guò)40,清空發(fā)送編輯框
        { m_send.Empty( );
        UpdateData(FALSE); //更新編輯框
        }
        }
        void CChatDlg::OnOnCommMscomm 1( )
        {
        // TODO: Add your control notification handler code here
        VARIANT temp;
        int count;
        if(m_comm.GetCommEvent( )= =2) //串行口數(shù)據(jù)接收處理;
        { count=m_comm.GetInBufferCount( );
        m_comm.SetInputLen(count); //利用Input接收字符數(shù)為count
        temp=m_comm.GetInput( ); //接收字符
        m_recv+=temp.bstrVal; //將接收字符添加到接收框變量中
        if(m_recv.GetLength( )= =40) //如輸入字符超過(guò)40,清空發(fā)送編輯框
        m_recv.Empty( );
        UpdateData(FALSE); //更新編輯框
        }
        }

        4、串行程序設(shè)計(jì)

        在此作為演示,此程序功能只是簡(jiǎn)單將所收字符再發(fā)送出去,類似可各種復(fù)雜協(xié)議。將微機(jī)與相連后,微機(jī)運(yùn)行chat.exe,單片機(jī)運(yùn)行此程序即可兩機(jī)。

        下面是MC68HC908GP32為例的程序清單。



        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉