function varargout = Gui_Datadisplay(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gui_Datadisplay_OpeningFcn, ...
'gui_OutputFcn', @Gui_Datadisplay_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 Gui_Datadisplay is made visible.
function Gui_Datadisplay_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 Gui_Datadisplay (see VARARGIN)
global COM;
global rate;
COM='COM3'
rate = 115200;
set(handles.ppCOM,'value', 3);
set(handles.ppBaudRates,'value',1);
set(handles.pbCloseSerial,'Enable','off');
% Choose default command line output for Gui_Datadisplay
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Gui_Datadisplay wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gui_Datadisplay_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 Value_Callback(hObject, eventdata, handles)
% hObject handle to Value (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 Value as text
% str2double(get(hObject,'String')) returns contents of Value as a double
% --- Executes during object creation, after setting all properties.
function Value_CreateFcn(hObject, eventdata, handles)
% hObject handle to Value (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 pbOpenSerial_Callback(hObject, eventdata, handles)
% hObject handle to pbOpenSerial (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
instrreset
global s;
global rate;
global COM;
global out;
global count
global num
global arrX;
global max
global min
global top
global gf
out=1;
max=0;min=5;top=0;
s=serial(COM);
set(s,'BaudRate',rate);
set(s,'DataBits',8);
set(s,'StopBits',1);
set(s,'InputBufferSize',1024000);
s.ReadAsyncMode='continuous';
set(handles.pbOpenSerial,'Enable','off');
set(handles.pbCloseSerial,'Enable','on');
s.BytesAvailableFcnMode='byte';
s.BytesAvailableFcnCount=4;%接收到4个字节中断
s.BytesAvailableFcn={@EveBytesAvailableFcn,handles};
fopen(s);%打开串口
fprintf('ceshi_dakaichuankou\n');
arrX=zeros(10000);
count=1;
num=1;
gf=0;
function EveBytesAvailableFcn( t,event,handles ) %#ok<*INUSL>
global s;
global arrX;
global count
global max
global min
global top
global gf
%串口接收数据
out=fread(s,4,'uint8');%读取 数据个数 与 类型
%因为串口传输的是ascii码,所以需要减去0x30
arrX(count+gf)=(((out(4)-48)+(out(3)-48)*10+(out(2)-48)*100+(out(1)-48)*1000)/1000)-1.25;
count = count+1;
if(count==600)
set(handles.editR,'string',arrX(1:600));
xlabel(handles.axes1,'TIME');
ylabel(handles.axes1,'ADC');
title(handles.axes1,'AD采集电压值');
for i=1:600
if(max<arrX(i));max=arrX(i);end
if(min>arrX(i));min=arrX(i);end
end
top=max-min;
for i = 0:500
plot(handles.axes1,arrX(1:600),'-r');
axis(handles.axes1,[1+i,100+i,min-0.2,max+0.2]);
pause(0.05);
end
set(handles.Value,'string',top);%输出峰峰值
set(handles.max,'string',max);%输出最大值
set(handles.min,'string',min);%输出最小值
%fft频谱图
fs=1000000;N=512; %采样频率为1Mhz和数据点数
y=fft(arrX(1:N),N);
realy=2*abs(y(1:N/2+1))/N;
realf=(0:N/2)*(fs/N);
xlabel(handles.axes2,'频率/Hz');
ylabel(handles.axes2,'振幅');title(handles.axes2,'N=128');
plot(handles.axes2,realf,realy);
a=0;b=0;
for i=1:256
if a<realy(i)
a=realy(i);
b=i;
end
end
set(handles.text4,'string',realy(b));%输出振幅
set(handles.cyc,'string',2*realy(b));%输出幅值
set(handles.fre,'string',realf(b));%输出频率
%复位,继续采集数据
% count=1;
% fwrite(s,(0x30+d),'uint8');%发送握手信息,AD继续采集
end
% --- Executes on selection change in ppCOM.
function ppCOM_Callback(hObject, eventdata, handles)
% hObject handle to ppCOM (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns ppCOM contents as cell array
% contents{get(hObject,'Value')} returns selected item from ppCOM
global COM;
% COM=1;
rate=1;
val=get(hObject,'value');
switch val
case 1
COM='COM1';
fprintf('ceshi_COM=1\n');
case 2
COM='COM2';
case 3
COM='COM3';
case 4
COM='COM4';
case 5
COM='COM5';
case 6
COM='COM6';
case 7
COM='COM7';
fprintf('ceshi_COM=7\n');
case 8
COM='COM8';
case 9
COM='COM9';
end
% --- Executes during object creation, after setting all properties.
function ppCOM_CreateFcn(hObject, eventdata, handles) %#ok<*INUSD>
% hObject handle to ppCOM (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 selection change in ppBaudRates.
function ppBaudRates_Callback(hObject, eventdata, handles)
% hObject handle to ppBaudRates (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns ppBaudRates contents as cell array
% contents{get(hObject,'Value')} returns selected item from ppBaudRates
global rate;
val=get(hObject,'value');
switch val
case 1
rate=115200;
case 2
rate=9600;
end
% --- Executes during object creation, after setting all properties.
function ppBaudRates_CreateFcn(hObject, eventdata, handles)
% hObject handle to ppBaudRates (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'de
Matalb Gui 示波器
需积分: 19 4 浏览量
2022-04-19
14:30:12
上传
评论 1
收藏 58KB ZIP 举报
weixin_58277261
- 粉丝: 1
- 资源: 5
最新资源
- 基于图像的三维模型重建C++源代码+文档说明(高分课程设计)
- 基于聚焦法的工件立体测量方案,根据数据进行三维重建 使用HALCON处理图像,MATLAB拟合数据+源代码+数据集+效果图
- 锄战三国村 修改:货币使用不减 v1.10(2) 原创 (中文).apk
- 基于python实现的单目双目视觉三维重建+源代码+图像图片(高分课程设计)
- 基于C+++OPENCV的全景图像拼接源码(课程设计)
- 基于Python+OpenCV对多张图片进行全景图像拼接,消除鬼影,消除裂缝+源代码+文档说明+界面截图(高分课程设计)
- 基于C++实现的全景图像拼接源码(课程设计)
- 基于SIFT特征点提取和RASIC算法实现全景图像拼接python源码+文档说明+界面截图+详细注释(95分以上课程大作业)
- 基于matlab实现眼部判别的疲劳检测系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的异常姿势识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0