C 與51微控制器串列埠通訊

2021-07-13 23:32:54 字數 1633 閱讀 5872

c#與51微控制器串列埠通訊

51接受資料,pc傳送資料。

通過微控制器的數碼管將pc傳送的16進製制資料顯示出來。

51接受資料**:

#include 

#include 

#include 

sbit ls138a = p2^2;     //定義138解碼器的輸入a腳由p2.2控制 

sbit ls138b = p2^3;     //定義138解碼器的輸入腳b由p2.3控制

sbit ls138c = p2^4;     //定義138解碼器的輸入腳c由p2.4控制

unsigned char

ch;  

bit read_flag= 0 ;  

//此表為 led 的字模, 共陰數碼管 0-9  - 

unsigned char

code disp_tab = ;   

void

delay(unsigned 

inti);  

void

init_serialcom( 

void

)    

//向串列埠傳送乙個字元

void

send_char_com( unsigned 

char

ch)  

//串列埠接收中斷函式

void

serial () interrupt 4 

using

3    

}  main()  

ledout[0]=disp_tab[lednumval / 100];  

ledout[1]=disp_tab[(lednumval / 10) % 10];  

ledout[2]=disp_tab[lednumval % 10]|0x80;  

for( i=0; i<3; i++)  

//實現8位動態掃瞄迴圈

delay(100);    

}  }  

}  void

delay(unsigned 

inti)    

c#傳送資料**:

using

system;  

using

system.collections.generic;  

using

system.componentmodel;  

using

system.data;  

using

system.drawing;  

using

system.linq;  

using

system.text;  

using

system.windows.forms;  

using

system.io;  

using

system.io.ports;  

namespace

交通燈串列埠通訊  

private

serialport com;  

private

void

button1_click(

object

sender, eventargs e)  

}  } or

51微控制器串列埠通訊

1 並行通訊 傳送方和接收方用多根資料線連線,多位資料同時傳送。傳輸線多,長距離傳輸時成本大。2 序列通訊 單根資料線傳送資料,逐位傳送。長距離傳送成本低,但控制相對複雜。序列通訊又可分為 非同步序列通訊和同步序列通訊。非同步序列通訊 所謂 非同步 指的是雙方裝置使用各自的時鐘,以字元為單位傳輸,採...

51微控制器 UART串列埠通訊

使用半雙工通訊 使用硬體uart模組和串列埠中斷 include typedef unsigned int uint void configuart uint baud void main void configuart uint baud 中斷型別碼為4,中斷向量的位址 中斷型別碼 8 3 voi...

51微控制器複習 串列埠通訊

計算機通訊是指計算機與外部裝置或計算機與計算機之間的資訊交換。比如電腦和微控制器 通訊有並行通訊和序列通訊兩種方式。在多微機系統以及現代測控系統中資訊的交換多採用序列通訊方式。並行通訊 通常是將資料位元組的各位用多條資料線同時進行傳送 比如這樣說,乙個位元組有八位,我有八根線,一根傳一位,八位同時傳...