久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7114|回復(fù): 7
打印 上一主題 下一主題
收起左側(cè)

關(guān)于stm32f4與Matlab串口通信 Matlab文件

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:202249 發(fā)表于 2017-5-18 16:54 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
關(guān)于stm32f4與Matlab串口通信 Matlab文件


源程序如下:
  1. function varargout = Gui_Datadisplay(varargin)
  2. % GUI_DATADISPLAY MATLAB code for Gui_Datadisplay.fig
  3. %      GUI_DATADISPLAY, by itself, creates a new GUI_DATADISPLAY or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = GUI_DATADISPLAY returns the handle to a new GUI_DATADISPLAY or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      GUI_DATADISPLAY('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in GUI_DATADISPLAY.M with the given input arguments.
  11. %
  12. %      GUI_DATADISPLAY('Property','Value',...) creates a new GUI_DATADISPLAY or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before Gui_Datadisplay_OpeningFcn gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to Gui_Datadisplay_OpeningFcn via varargin.
  17. %
  18. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19. %      instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES

  22. % Edit the above text to modify the response to help Gui_Datadisplay

  23. % Last Modified by GUIDE v2.5 17-Jun-2015 14:11:40

  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name',       mfilename, ...
  27.                    'gui_Singleton',  gui_Singleton, ...
  28.                    'gui_OpeningFcn', @Gui_Datadisplay_OpeningFcn, ...
  29.                    'gui_OutputFcn',  @Gui_Datadisplay_OutputFcn, ...
  30.                    'gui_LayoutFcn',  [] , ...
  31.                    'gui_Callback',   []);
  32. if nargin && ischar(varargin{1})
  33.     gui_State.gui_Callback = str2func(varargin{1});
  34. end

  35. if nargout
  36.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38.     gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT


  41. % --- Executes just before Gui_Datadisplay is made visible.
  42. function Gui_Datadisplay_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject    handle to figure
  45. % eventdata  reserved - to be defined in a future version of MATLAB
  46. % handles    structure with handles and user data (see GUIDATA)
  47. % varargin   command line arguments to Gui_Datadisplay (see VARARGIN)

  48. global COM;
  49. global rate;
  50. COM='COM7'
  51. rate = 115200;
  52. set(handles.ppCOM,'value', 7);
  53. set(handles.ppBaudRates,'value',1);
  54. set(handles.pbCloseSerial,'Enable','off');

  55. % Choose default command line output for Gui_Datadisplay
  56. handles.output = hObject;

  57. % Update handles structure
  58. guidata(hObject, handles);

  59. % UIWAIT makes Gui_Datadisplay wait for user response (see UIRESUME)
  60. % uiwait(handles.figure1);


  61. % --- Outputs from this function are returned to the command line.
  62. function varargout = Gui_Datadisplay_OutputFcn(hObject, eventdata, handles)
  63. % varargout  cell array for returning output args (see VARARGOUT);
  64. % hObject    handle to figure
  65. % eventdata  reserved - to be defined in a future version of MATLAB
  66. % handles    structure with handles and user data (see GUIDATA)

  67. % Get default command line output from handles structure
  68. varargout{1} = handles.output;



  69. function Value_Callback(hObject, eventdata, handles)
  70. % hObject    handle to Value (see GCBO)
  71. % eventdata  reserved - to be defined in a future version of MATLAB
  72. % handles    structure with handles and user data (see GUIDATA)

  73. % Hints: get(hObject,'String') returns contents of Value as text
  74. %        str2double(get(hObject,'String')) returns contents of Value as a double


  75. % --- Executes during object creation, after setting all properties.
  76. function Value_CreateFcn(hObject, eventdata, handles)
  77. % hObject    handle to Value (see GCBO)
  78. % eventdata  reserved - to be defined in a future version of MATLAB
  79. % handles    empty - handles not created until after all CreateFcns called

  80. % Hint: edit controls usually have a white background on Windows.
  81. %       See ISPC and COMPUTER.
  82. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  83.     set(hObject,'BackgroundColor','white');
  84. end


  85. % --- Executes on button press in pbOpenSerial.
  86. function pbOpenSerial_Callback(hObject, eventdata, handles)
  87. % hObject    handle to pbOpenSerial (see GCBO)
  88. % eventdata  reserved - to be defined in a future version of MATLAB
  89. % handles    structure with handles and user data (see GUIDATA)
  90. clc
  91. instrreset
  92. global s;
  93. global rate;
  94. global COM;
  95. global out;
  96. out=1;

  97. s=serial(COM);
  98. set(s,'BaudRate',rate);%%%Baud初始化
  99. set(s,'DataBits',8);%%%設(shè)置數(shù)據(jù)長度
  100. set(s,'StopBits',1);%%%設(shè)置停止位長度
  101. set(s,'InputBufferSize',1024000);%%%設(shè)置輸入緩沖區(qū)大小為1M
  102. set(handles.pbOpenSerial,'Enable','off');
  103. set(handles.pbCloseSerial,'Enable','on');

  104. %串口事件回調(diào)設(shè)置
  105. s.BytesAvailableFcnMode='terminator';
  106. s.BytesAvailableFcnCount=10; %輸入緩沖區(qū)存在10個字節(jié)觸發(fā)回調(diào)函數(shù)
  107. s.BytesAvailableFcn={@EveBytesAvailableFcn,handles};%回調(diào)函數(shù)的指定
  108. fopen(s);%打開串口

  109. global count;
  110. count=1;
  111. fprintf('ceshi_dakaichuankou\n');

  112. %回調(diào)函數(shù)
  113. function EveBytesAvailableFcn( t,event,handles )
  114. global s;
  115. global a;
  116. global d;
  117. global arrX;
  118. global arrY;
  119. global arrZ;
  120. global count;

  121. arrX=zeros([1,100]);
  122. % arrY=[1,1000];
  123. % arrZ=[1,1000];
  124. % fprintf('Receive callback');
  125. a=fscanf(s);
  126. M=textscan(a,'%s%d%d%d','delimiter',' ');
  127. % data = [data , '\n'];
  128. [Name,x,y,z] = deal(M{:});
  129. arrX(1,count) = x;
  130. % arrY(1,count) = y;
  131. % arrZ(1,count) = z;
  132. a = strcat(a ,char(10), get(handles.editR,'string'));
  133. set(handles.editR,'string',a);
  134. set(handles.text4,'string',x);
  135. plot(arrX);
  136. hold on;
  137. count=count+1;
  138. if count==100
  139.     count=1;
  140.     clf;
  141. end

  142. % --- Executes on selection change in ppCOM.
  143. function ppCOM_Callback(hObject, eventdata, handles)
  144. % hObject    handle to ppCOM (see GCBO)
  145. % eventdata  reserved - to be defined in a future version of MATLAB
  146. % handles    structure with handles and user data (see GUIDATA)

  147. % Hints: contents = cellstr(get(hObject,'String')) returns ppCOM contents as cell array
  148. %        contents{get(hObject,'Value')} returns selected item from ppCOM
  149. global COM;
  150. % COM=1;
  151. rate=1;
  152. val=get(hObject,'value');
  153. switch val
  154.     case 1
  155.         COM='COM1';
  156.         fprintf('ceshi_COM=1\n');
  157.     case 2
  158.         COM='COM2';
  159.     case 3
  160.         COM='COM3';
  161.     case 4
  162.         COM='COM4';
  163.     case 5
  164.         COM='COM5';
  165.     case 6
  166.         COM='COM6';
  167.     case 7
  168.         COM='COM7';
  169.         fprintf('ceshi_COM=7\n');
  170.     case 8
  171.         COM='COM8';
  172.     case 9
  173.         COM='COM9';
  174. end

  175. % --- Executes during object creation, after setting all properties.
  176. function ppCOM_CreateFcn(hObject, eventdata, handles)
  177. % hObject    handle to ppCOM (see GCBO)
  178. % eventdata  reserved - to be defined in a future version of MATLAB
  179. % handles    empty - handles not created until after all CreateFcns called


  180. % Hint: popupmenu controls usually have a white background on Windows.
  181. %       See ISPC and COMPUTER.
  182. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  183.     set(hObject,'BackgroundColor','white');
  184. end


  185. % --- Executes on selection change in ppBaudRates.
  186. function ppBaudRates_Callback(hObject, eventdata, handles)
  187. % hObject    handle to ppBaudRates (see GCBO)
  188. % eventdata  reserved - to be defined in a future version of MATLAB
  189. % handles    structure with handles and user data (see GUIDATA)

  190. % Hints: contents = cellstr(get(hObject,'String')) returns ppBaudRates contents as cell array
  191. %        contents{get(hObject,'Value')} returns selected item from ppBaudRates
  192. global rate;
  193. val=get(hObject,'value');
  194. switch val
  195.     case 1
  196.         rate=115200;
  197.     case 2
  198.         rate=9600;
  199. end

  200. % --- Executes during object creation, after setting all properties.
  201. function ppBaudRates_CreateFcn(hObject, eventdata, handles)
  202. % hObject    handle to ppBaudRates (see GCBO)
  203. % eventdata  reserved - to be defined in a future version of MATLAB
  204. % handles    empty - handles not created until after all CreateFcns called

  205. % Hint: popupmenu controls usually have a white background on Windows.
  206. %       See ISPC and COMPUTER.
  207. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  208.     set(hObject,'BackgroundColor','white');
  209. end


  210. % --- Executes on button press in pbCloseSerial.
  211. function pbCloseSerial_Callback(hObject, eventdata, handles)
  212. % hObject    handle to pbCloseSerial (see GCBO)
  213. % eventdata  reserved - to be defined in a future version of MATLAB
  214. % handles    structure with handles and user data (see GUIDATA)
  215. global s;
  216. fclose(s);
  217. delete(s);
  218. set(handles.pbOpenSerial,'Enable','on');
  219. set(handles.pbCloseSerial,'Enable','off');
  220. fprintf('Close_COM');


  221. function editR_Callback(hObject, eventdata, handles)
  222. % hObject    handle to editR (see GCBO)
  223. % eventdata  reserved - to be defined in a future version of MATLAB
  224. % handles    structure with handles and user data (see GUIDATA)

  225. % Hints: get(hObject,'String') returns contents of editR as text
  226. %        str2double(get(hObject,'String')) returns contents of editR as a double


  227. % --- Executes during object creation, after setting all properties.
  228. function editR_CreateFcn(hObject, eventdata, handles)
  229. % hObject    handle to editR (see GCBO)
  230. % eventdata  reserved - to be defined in a future version of MATLAB
  231. % handles    empty - handles not created until after all CreateFcns called

  232. % Hint: edit controls usually have a white background on Windows.
  233. %       See ISPC and COMPUTER.
  234. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  235.     set(hObject,'BackgroundColor','white');
  236. end


  237. % --- Executes on button press in pbClearR.
  238. function pbClearR_Callback(hObject, eventdata, handles)
  239. % hObject    handle to pbClearR (see GCBO)
  240. % eventdata  reserved - to be defined in a future version of MATLAB
  241. % handles    structure with handles and user data (see GUIDATA)
  242. set(handles.editR,'string','');
  243. set(handles.Value,'string','');
  244. set(handles.text4,'string','');


  245. % --- Executes on button press in pbClearT.
  246. function pbClearT_Callback(hObject, eventdata, handles)
  247. ……………………

  248. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
Gui_Data_display.zip (13.3 KB, 下載次數(shù): 108)



評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:91907 發(fā)表于 2017-11-25 17:00 | 只看該作者
不錯,有用
回復(fù)

使用道具 舉報

板凳
ID:295119 發(fā)表于 2018-3-21 17:01 | 只看該作者
學(xué)習(xí)學(xué)習(xí)!!!
回復(fù)

使用道具 舉報

地板
ID:186122 發(fā)表于 2018-6-9 21:26 | 只看該作者
希望有用
回復(fù)

使用道具 舉報

5#
ID:186122 發(fā)表于 2018-6-9 21:32 | 只看該作者
樓主用的單片機(jī)型號是什么呀
回復(fù)

使用道具 舉報

6#
ID:414005 發(fā)表于 2018-10-23 16:35 | 只看該作者
希望有用 正在研究gui實時繪制
回復(fù)

使用道具 舉報

7#
ID:414065 發(fā)表于 2018-10-23 19:32 | 只看該作者
很強(qiáng)勢
回復(fù)

使用道具 舉報

8#
ID:224496 發(fā)表于 2019-4-22 20:12 | 只看該作者
感謝分享,學(xué)習(xí)中。
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 9999在线视频 | 国产欧美精品一区二区三区 | 亚洲精品乱码久久久久久9色 | 亚洲国产一区二区三区在线观看 | 九九久久免费视频 | 亚洲视频在线看 | 久久一区二区三区四区 | 成人av一区二区三区 | 免费观看黄网站 | 久久久亚洲一区 | 国产精品一区二区久久 | 国产偷录视频叫床高潮对白 | 久久九九99 | 精品视频 免费 | 欧美精品tv | 91久久久久久久 | 亚洲激情第一页 | 综合久久av| 国产视频久久久久 | 韩国欧洲一级毛片 | 国产高清无av久久 | aaaa一级毛片 | 免费国产一区二区视频 | 亚洲视频三区 | 国产成人精品久久二区二区 | 国产精品一级 | 国产九九精品 | 成人免费一区二区三区牛牛 | 亚洲第1页| 国产精品久久久 | 亚洲一区中文字幕 | 久久久久亚洲精品国产 | 久久久久91 | 久久国产欧美日韩精品 | 亚洲伊人精品酒店 | 欧美黄色一区 | 亚洲视屏| a级在线免费 | 毛片视频观看 | 国产精品久久久久久久久免费樱桃 | 九色网址|