工作流程:AD7818采样模拟信号,12bits输出,串口将数据发送给PC。串口发送波特率57600Bd,数据位8位,停止位一位。每个数据分两次发送,高四位补零。设计GUI界面接收串口数据并显示波形。
GUI界面如下:
功能描述:
1.选择串口,点击START,即等待串口发送数据,数据缓存4000bytes。接收缓存区满后绘图,同时显示最大电压值和波形功率值。
2.File菜单下有Import Data 和
Export Data功能,可将电压数据保存到txt文件中,同时可读取txt中的数据并显示相关波形。
3.Image菜单下有Open Image 和
Save Image功能,可将波形保存成图片格式,同时可打开图片显示在绘图窗口。
Matlab源代码:
function varargout =
serial1(varargin)
% SERIAL1 M-file for serial1.fig
% SERIAL1, by itself, creates a new SERIAL1 or raises the
existing
% singleton*.
%
% H = SERIAL1 returns the handle to a new SERIAL1 or the handle
to
% the existing singleton*.
%
% SERIAL1('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in SERIAL1.M with the given input
arguments.
%
% SERIAL1('Property','Value',...) creates a new SERIAL1 or raises
the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before serial1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to serial1_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 serial1
% Last Modified by GUIDE
v2.5 18-Sep-2009 13:30:08
% Begin initialization
code - DO NOT EDIT
gui_Singleton = 1;
gui_State =
struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @serial1_OpeningFcn, ...
'gui_OutputFcn', @serial1_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
%global s selected_com selected_baud selected_databits
selected_stopbits selected_parity selected_flowctrl
% --- Executes just before
serial1 is made visible.
function serial1_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 seri