完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
小白第一篇文章见谅!
stm32与matlab通讯实验效果: 2.串口通信matlab代码 %与stm32串口通信实验 delete(instrfindall);%注销系统之前已经打开了串口资源 obj = serial('COM8','BaudRate',115200);%串口配置 fopen(obj);%打开串口 fprintf(obj,'hello12365'); %以ASCII格式发送 大小 = 20; acceptingdata = fscanf(obj,'%s',size);%以ASCII格式接收 data=sprintf('返回值=%s',acceptingdata); disp(data);%显示返回值 2.stm32统一用的野火指南者实验代码 3.matlab gui效果 4.matlab gui 全部代码 ni function varargout = untitled1(varargin) % UNTITLED1 MATLAB code for untitled1.fig % UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing % singleton*. % % H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to % the existing singleton*. % % UNTITLED1(‘CALLBACK’,hObject,eventData,handles,。..) calls the local % function named CALLBACK in UNTITLED1.M with the given input arguments. % % UNTITLED1(‘Property’,‘Value’,。..) creates a new UNTITLED1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled1_OpeningFcn via varargin. % % *See GUI Options on GUIDE‘s Tools menu. Choose “GUI allows only one % instance to run (singleton)”。 % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help untitled1 % Last Modified by GUIDE v2.5 19-Jun-2021 19:58:43 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct(’gui_Name‘, mfilename, 。.. ’gui_Singleton‘, gui_Singleton, 。.. ’gui_OpeningFcn‘, @untitled1_OpeningFcn, 。.. ’gui_OutputFcn‘, @untitled1_OutputFcn, 。.. ’gui_LayoutFcn‘, [] , 。.. ’gui_Callback‘, []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before untitled1 is made visible. function untitled1_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to untitled1 (see VARARGIN) % Choose default command line output for untitled1 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes untitled1 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = untitled1_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of edit1 as text % str2double(get(hObject,’String‘)) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of edit2 as text % str2double(get(hObject,’String‘)) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %与stm32串口通信实验 % delete(instrfindall);%注销系统之前已经打开的串口资源 % obj = serial(’COM8‘,’rate1‘,115200);%串口配置 % fopen(obj);%打开串口 global obj; data=get(handles.edit1,’string‘); fprintf(obj,data); %以ASCII格式发送 size = 20; acceptingdata = fscanf(obj,’%s‘,size);%以ASCII格式接收 data=sprintf(’%s‘,acceptingdata); set(handles.edit2,’string‘,data); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) delete(instrfindall);%注销系统之前已经打开的串口资源 %com=get(handles.serialcom,’string‘); global BD; global PD; global DD; global SD; global obj; global COMSERIAL; if(isempty(COMSERIAL)) COMSERIAL=’COM8‘; end if(isempty(BD)) BD=115200; end if(isempty(PD)) PD=’none‘; end if(isempty(DD)) DD=8; end if(isempty(SD)) SD=1; end COM=COMSERIAL; COM BaudRate=BD; BaudRate Parity=PD; Parity DataBits=DD; DataBits StopBits=SD; StopBits obj = serial(COM);%串口配置 obj.BaudRate =BD; obj.Parity =PD; obj.DataBits =DD; obj.StopBits =SD; fopen(obj);%打开串口 fprintf(’nr%snr‘,’打开串口成功‘); function rate1_Callback(hObject, eventdata, handles) % hObject handle to rate1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of rate1 as text % str2double(get(hObject,’String‘)) returns contents of rate1 as a double global BD; vall=get(handles.rate1,’value‘); switch vall case 1 BD=9600; case 2 BD=19200; case 3 BD=115200; end % --- Executes during object creation, after setting all properties. function rate1_CreateFcn(hObject, eventdata, handles) % hObject handle to rate1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end function serialcom_Callback(hObject, eventdata, handles) % hObject handle to serialcom (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of serialcom as text % str2double(get(hObject,’String‘)) returns contents of serialcom as a double global COMSERIAL; vall=get(handles.serialcom,’value‘); switch vall case 1 COMSERIAL=’COM1‘; case 2 COMSERIAL=’COM2‘; case 3 COMSERIAL=’COM3‘; case 4 COMSERIAL=’COM8‘; end % --- Executes during object creation, after setting all properties. function serialcom_CreateFcn(hObject, eventdata, handles) % hObject handle to serialcom (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end function parity_Callback(hObject, eventdata, handles) % hObject handle to parity (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of parity as text % str2double(get(hObject,’String‘)) returns contents of parity as a double global PD; vall=get(handles.parity,’value‘); switch vall case 1 PD=’none‘; end % --- Executes during object creation, after setting all properties. function parity_CreateFcn(hObject, eventdata, handles) % hObject handle to parity (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end |
|
|
|
function databit_Callback(hObject, eventdata, handles)
% hObject handle to databit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of databit as text % str2double(get(hObject,’String‘)) returns contents of databit as a double global DD; databits_data=get(handles.databit,’value‘); switch databits_data case 1 DD=8; end % --- Executes during object creation, after setting all properties. function databit_CreateFcn(hObject, eventdata, handles) % hObject handle to databit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end function stopbit_Callback(hObject, eventdata, handles) % hObject handle to stopbit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of stopbit as text % str2double(get(hObject,’String‘)) returns contents of stopbit as a double global SD; stopbits_data=get(handles.stopbit,’value‘); switch stopbits_data case 1 SD=1; end % --- Executes during object creation, after setting all properties. function stopbit_CreateFcn(hObject, eventdata, handles) % hObject handle to stopbit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) delete(instrfindall); fprintf(’nr%snr‘,’串口已关闭‘); function kj2_Callback(hObject, eventdata, handles) % hObject handle to kj2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of kj2 as text % str2double(get(hObject,’String‘)) returns contents of kj2 as a double % --- Executes during object creation, after setting all properties. function kj2_CreateFcn(hObject, eventdata, handles) % hObject handle to kj2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end % --- Executes on button press in kj1. function kj1_Callback(hObject, eventdata, handles) % hObject handle to kj1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,’Value‘) returns toggle state of kj1 value=get(handles.kj1,’value‘); set(handles.kj2,’string‘,num2str(value)); function brate_Callback(hObject, eventdata, handles) % hObject handle to brate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String‘) returns contents of brate as text % str2double(get(hObject,’String‘)) returns contents of brate as a double global BD; bdrate_data=get(handles.brate,’value‘); switch bdrate_data case 1 BD=9600; case 2 BD=19200; case 3 BD=115200; end % --- Executes during object creation, after setting all properties. function brate_CreateFcn(hObject, eventdata, handles) % hObject handle to brate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,’BackgroundColor‘), get(0,’defaultUicontrolBackgroundColor‘)) set(hObject,’BackgroundColor‘,’white‘); end |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1786 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1622 浏览 1 评论
1089 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
730 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1680 浏览 2 评论
1943浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
740浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
577浏览 3评论
600浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
562浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 00:34 , Processed in 0.861279 second(s), Total 47, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号