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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2083|回復(fù): 0
收起左側(cè)

MPU6050在STC51的代碼

[復(fù)制鏈接]
ID:259587 發(fā)表于 2017-12-9 21:21 | 顯示全部樓層 |閱讀模式
  1. function varargout = Serial_Port(varargin)
  2. % SERIAL_PORT M-file for Serial_Port.fig
  3. %      SERIAL_PORT, by itself, creates a new SERIAL_PORT or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = SERIAL_PORT returns the handle to a new SERIAL_PORT or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      SERIAL_PORT('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in SERIAL_PORT.M with the given input arguments.
  11. %
  12. %      SERIAL_PORT('Property','Value',...) creates a new SERIAL_PORT or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before Serial_Port_OpeningFcn gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to Serial_Port_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 Serial_Port

  23. % Last Modified by GUIDE v2.5 17-Jun-2015 10:13:45

  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', @Serial_Port_OpeningFcn, ...
  29.                    'gui_OutputFcn',  @Serial_Port_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 Serial_Port is made visible.
  42. function Serial_Port_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 Serial_Port (see VARARGIN)


  48. % Choose default command line output for Serial_Port
  49. handles.output = hObject;

  50. % Update handles structure
  51. guidata(hObject, handles);
  52. %{
  53. 關(guān)閉、刪除已打開的串口對象
  54. scoms=instrfind;
  55. fclose(scoms);
  56. delete(scoms);
  57. clear scoms;

  58. %}
  59. %獲取可用串口
  60. global getcom
  61. getcom=instrhwinfo('serial');
  62. set(handles.popupmenu1,'string',char(getcom.AvailableSerialPorts));
  63. global a
  64. a=clock;

  65. % UIWAIT makes Serial_Port wait for user response (see UIRESUME)
  66. % uiwait(handles.figure1);


  67. % --- Outputs from this function are returned to the command line.
  68. function varargout = Serial_Port_OutputFcn(hObject, eventdata, handles)
  69. % varargout  cell array for returning output args (see VARARGOUT);
  70. % hObject    handle to figure
  71. % eventdata  reserved - to be defined in a future version of MATLAB
  72. % handles    structure with handles and user data (see GUIDATA)




  73. function edit1_Callback(hObject, eventdata, handles)
  74. % hObject    handle to edit1 (see GCBO)
  75. % eventdata  reserved - to be defined in a future version of MATLAB
  76. % handles    structure with handles and user data (see GUIDATA)

  77. % Hints: get(hObject,'String') returns contents of edit1 as text
  78. %        str2double(get(hObject,'String')) returns contents of edit1 as a double


  79. % --- Executes during object creation, after setting all properties.
  80. function edit1_CreateFcn(hObject, eventdata, handles)
  81. % hObject    handle to edit1 (see GCBO)
  82. % eventdata  reserved - to be defined in a future version of MATLAB
  83. % handles    empty - handles not created until after all CreateFcns called

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



  89. function edit2_Callback(hObject, eventdata, handles)
  90. % hObject    handle to edit2 (see GCBO)
  91. % eventdata  reserved - to be defined in a future version of MATLAB
  92. % handles    structure with handles and user data (see GUIDATA)

  93. % Hints: get(hObject,'String') returns contents of edit2 as text
  94. %        str2double(get(hObject,'String')) returns contents of edit2 as a double


  95. % --- Executes during object creation, after setting all properties.
  96. function edit2_CreateFcn(hObject, eventdata, handles)
  97. % hObject    handle to edit2 (see GCBO)
  98. % eventdata  reserved - to be defined in a future version of MATLAB
  99. % handles    empty - handles not created until after all CreateFcns called

  100. % Hint: edit controls usually have a white background on Windows.
  101. %       See ISPC and COMPUTER.
  102. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  103.     set(hObject,'BackgroundColor','white');
  104. end


  105. % --- Executes on button press in pushbutton1.
  106. function pushbutton1_Callback(hObject, eventdata, handles)
  107. % hObject    handle to pushbutton1 (see GCBO)
  108. % eventdata  reserved - to be defined in a future version of MATLAB
  109. % handles    structure with handles and user data (see GUIDATA)

  110. %獲取當(dāng)前按鈕的名字
  111. string=get(handles.pushbutton1,'string');
  112. if(strcmp(string,'打開串口')==1)
  113.     set(handles.pushbutton1,'string','關(guān)閉串口');
  114.     %禁止修改串口號和波特率
  115.     set(handles.popupmenu1,'Enable','off');
  116.     set(handles.popupmenu2,'Enable','off');
  117.     %getcom=instrhwinfo('serial');
  118.     global getcom
  119.     global scom
  120.     %選擇串口號
  121.     if size(getcom.AvailableSerialPorts)==0
  122.         errordlg('無有效COM口','提示','replace');
  123.     else if size(getcom.AvailableSerialPorts)==1
  124.            scom=serial(char(getcom.AvailableSerialPorts));
  125.         else
  126.             for i=1:size(getcom.AvailableSerialPorts)
  127.                 if i==get(handles.popupmenu1,'Value')
  128.                     scom=serial(char(getcom.AvailableSerialPorts(i)));
  129.                     break;
  130.                 end;
  131.             end;
  132.         end;
  133.     end;
  134.     %設(shè)置串口波特率
  135.     switch get(handles.popupmenu2,'Value')
  136.         case 1
  137.             scom.BaudRate=115200;
  138.         case 2
  139.             scom.BaudRate=57600;
  140.         case 3
  141.             scom.BaudRate=56000;
  142.         case 4
  143.             scom.BaudRate=43000;
  144.         case 5
  145.             scom.BaudRate=38400;
  146.         case 6
  147.             scom.BaudRate=19200;
  148.         case 7
  149.             scom.BaudRate=9600;
  150.         case 8
  151.             scom.BaudRate=4800;
  152.         case 9
  153.             scom.BaudRate=2400;
  154.         case 10
  155.             scom.BaudRate=1200;
  156.         case 11
  157.             scom.BaudRate=600;
  158.         case 12
  159.             scom.BaudRate=300;
  160.     end;
  161.     %scom.terminator='CR';
  162.     scom.BytesAvailableFcnMode='terminator';
  163.     scom.BytesAvailableFcn={@mycallback,handles};
  164.     fopen(scom);
  165. else
  166.     %按鍵的名字設(shè)為‘打開串口’
  167.     set(handles.pushbutton1,'string','打開串口');
  168.     %禁止修改串口號和波特率
  169.     set(handles.popupmenu1,'Enable','on');
  170.     set(handles.popupmenu2,'Enable','on');
  171.     %查找串口對象
  172.     scoms = instrfind;
  173.     %嘗試停止、關(guān)閉刪除串口對象
  174.     stopasync(scoms);
  175.     fclose(scoms);
  176.     delete(scoms);
  177. end;
  178. % --- Executes on button press in pushbutton2.
  179. function pushbutton2_Callback(hObject, eventdata, handles)
  180. % hObject    handle to pushbutton2 (see GCBO)
  181. % eventdata  reserved - to be defined in a future version of MATLAB
  182. % handles    structure with handles and user data (see GUIDATA)
  183. global scom;
  184. %得到發(fā)送區(qū)的數(shù)據(jù)
  185. send_data=get(handles.edit2,'string');
  186. global a;
  187. a=GetSecs;
  188. fprintf(scom,send_data);


  189. % --- Executes on selection change in popupmenu1.
  190. function popupmenu1_Callback(hObject, eventdata, handles)
  191. % hObject    handle to popupmenu1 (see GCBO)
  192. % eventdata  reserved - to be defined in a future version of MATLAB
  193. % handles    structure with handles and user data (see GUIDATA)

  194. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
  195. %        contents{get(hObject,'Value')} returns selected item from popupmenu1


  196. % --- Executes during object creation, after setting all properties.
  197. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  198. % hObject    handle to popupmenu1 (see GCBO)
  199. % eventdata  reserved - to be defined in a future version of MATLAB
  200. % handles    empty - handles not created until after all CreateFcns called

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


  206. % --- Executes on selection change in popupmenu2.
  207. function popupmenu2_Callback(hObject, eventdata, handles)
  208. % hObject    handle to popupmenu2 (see GCBO)
  209. % eventdata  reserved - to be defined in a future version of MATLAB
  210. % handles    structure with handles and user data (see GUIDATA)

  211. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
  212. %        contents{get(hObject,'Value')} returns selected item from popupmenu2



  213. % --- Executes during object creation, after setting all properties.
  214. function popupmenu2_CreateFcn(hObject, eventdata, handles)
  215. % hObject    handle to popupmenu2 (see GCBO)
  216. % eventdata  reserved - to be defined in a future version of MATLAB
  217. % handles    empty - handles not created until after all CreateFcns called

  218. % Hint: popupmenu controls usually have a white background on Windows.
  219. %       See ISPC and COMPUTER.
  220. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  221.     set(hObject,'BackgroundColor','white');
  222. end

  223. %串口接收顯示程序
  224. function mycallback(scom,BytesAvailable,handles)
  225. n_bytes=get(scom,'BytesAvailable');
  226. if n_bytes>0
  227.     char=fscanf(scom);
  228. end;
  229. original=get(handles.edit1,'string');
  230. char=strcat(original,char);
  231. set(handles.edit1,'string',char);
  232. global a;
  233. set(handles.edit1,'string',num2char(GetSecs-a));



  234. function edit3_Callback(hObject, eventdata, handles)
  235. % hObject    handle to edit3 (see GCBO)
  236. % eventdata  reserved - to be defined in a future version of MATLAB
  237. % handles    structure with handles and user data (see GUIDATA)

  238. % Hints: get(hObject,'String') returns contents of edit3 as text
  239. %        str2double(get(hObject,'String')) returns contents of edit3 as a double


  240. % --- Executes during object creation, after setting all properties.
  241. function edit3_CreateFcn(hObject, eventdata, handles)
  242. % hObject    handle to edit3 (see GCBO)
  243. % eventdata  reserved - to be defined in a future version of MATLAB
  244. % handles    empty - handles not created until after all CreateFcns called

  245. % Hint: edit controls usually have a white background on Windows.
  246. %       See ISPC and COMPUTER.
  247. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  248.     set(hObject,'BackgroundColor','white');
  249. end
復(fù)制代碼


回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日本在线免费视频 | 亚洲精品日韩综合观看成人91 | 国产成人精品在线 | 国产高清视频一区 | 中文字幕av在线 | 亚洲精品国产电影 | 亚洲一区二区三区乱码aⅴ 四虎在线视频 | www.日韩高清 | 一区二区三区精品视频 | 在线观看涩涩视频 | 欧美高清一区 | 久久精品国产一区二区三区 | 91精品国产一区二区三区香蕉 | 一区二区三区在线 | 午夜免费电影 | 国产综合在线视频 | 免费视频一区 | 国产精品久久久久aaaa九色 | 亚洲视频国产视频 | 欧美一级电影免费观看 | 一区欧美| 午夜免费福利影院 | 伊人激情综合网 | 久久精品aaa | 国产色 | 日韩有码一区 | 在线看中文字幕 | 免费一级大片 | 黄色欧美 | 国产精品久久久久久久久久尿 | 午夜不卡一区二区 | 日本aaaa| 精品一区二区三区视频在线观看 | 日本精品视频 | 少妇黄色 | av中文字幕在线播放 | 盗摄精品av一区二区三区 | 久久精品国产亚洲 | 夜夜爽99久久国产综合精品女不卡 | 欧美一区二区视频 | 午夜欧美 |