通过FPGA将图片信息通过RS232串口发送到PC端,使用MATLAB进行图片显示
生活随笔
收集整理的這篇文章主要介紹了
通过FPGA将图片信息通过RS232串口发送到PC端,使用MATLAB进行图片显示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.仿真預覽
2.部分核心代碼
FPGA部分代碼
module uarttx(clk,reset,datain,wrsig,tx);input clk; input reset; input [7:0] datain; input wrsig; output tx; reg idle; reg tx; reg send; reg wrsigbuf; reg wrsigrise; reg presult; reg [7:0] cnt; parameter paritymode=1'b0;always @(posedge clk) beginwrsigbuf<=wrsig;wrsigrise<=(~wrsigbuf) & wrsig; endalways @(posedge clk or negedge reset) beginif(reset==1'b0)beginsend<=1'b0; endelsebeginsend<=1'b1; end endalways @(posedge clk or negedge reset) beginif(reset==1'b0)begincnt<=8'd0;tx<=1'b1;end else begincase(cnt) 8'd0:begintx<=1'b0; idle<=1'b1;cnt<=cnt+8'd1;end8'd16:begintx<=datain[0];presult<=datain[0]^paritymode;idle<=1'b1;cnt<=cnt+8'd1;end8'd32:begintx<=datain[1];presult<=datain[1]^presult;idle<=1'b1;cnt<=cnt+8'd1;end8'd48:begintx<=datain[2];presult<=datain[2]^presult;idle<=1'b1;cnt<=cnt+8'd1;end8'd64:begintx<=datain[3];presult<=datain[3]^presult;idle<=1'b1;cnt<=cnt+8'd1;end8'd80:begintx<=datain[4];presult<=datain[4]^presult;idle<=1'b1;cnt<=cnt+8'd1;end8'd96:begintx<=datain[5];presult<=datain[5]^presult;idle<=1'b1;cnt<=cnt+8'd1;end8'd112:begintx<=datain[6];presult<=datain[6]^presult;idle<=1'b1;cnt<=cnt+8'd1;end8'd128:begintx<=datain[7];presult<=datain[7]^presult;idle<=1'b1;cnt<=cnt+8'd1;end8'd144:begintx<=presult;presult<=datain[0]^paritymode;idle<=1'b1;cnt<=cnt+8'd1;end8'd160:begintx<=1'b1;idle<=1'b1;cnt<=cnt+8'd1;end8'd176:begintx<=1'b1;idle<=1'b0;cnt<=cnt+8'd1;enddefault:begincnt<=cnt+8'd1;endendcaseendend endmoduleMATLAB部分代碼
global FileName; global RR; global CC;RR=250; CC=250;C1=str2num(get(handles.edit1,'String'));if C1==1Serial_obj=serial('COM1'); end if C1==2Serial_obj=serial('COM2'); end if C1==3Serial_obj=serial('COM3'); end if C1==4Serial_obj=serial('COM4'); endSerial_obj.BaudRate=str2num(get(handles.edit2,'String')); Serial_obj.DataBits=str2num(get(handles.edit3,'String')); Serial_obj.Parity='none'; Serial_obj.StopBits=str2num(get(handles.edit4,'String')); % Serial_obj.Terminator=0; Serial_obj.InputBufferSize=RR*CC; %保存掃描的5000*1行數據,保存1000個 % Serial_obj.timeout=20; %% 創建txt文檔。 Name = clock; FileName=[num2str(Name(5)),num2str(round(Name(6))),'.txt']; FileID1=fopen(FileName,'a+'); %% 打開串口,讀寫串口內容。 fopen(Serial_obj); Temp_2 = [fscanf(Serial_obj,'%d')]'; fprintf(FileID1,'%d\n',Temp_2); % Write data to text file fprintf(FileID1,'\n');%% 關閉串口,清理緩存區 fclose(FileID1); fclose(Serial_obj); delete(Serial_obj); clear Serial_obj msgbox('讀取結束'); % --- 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) global FileName; global RR; global CC;I = load(FileName); %讀取標志信號 start = []; for i = 5001:length(I)tmps = I(i-5000:i-1);cnt = 0;for j = 1:length(tmps)if tmps(j) == 153 cnt = cnt + 1; endendif cnt==5000start = [start,i+1];end endpix_bigen = start(end);if isempty(pix_bigen)==0 II = I(pix_bigen:end); else II = I; endif length(II) < RR*CCIII = [II;zeros(RR*CC-length(II),1);]; elseIII = II; endI2= [reshape(III,[RR,CC])]'; I3 = zeros(size(I2));axes(handles.axes1);KK=10; for i = 1:RR/KKI3(KK*(i-1)+1:KK*i,:) = I2(KK*(i-1)+1:KK*i,:);imshow(uint8(I3));hold offdrawnow; endA38-09
總結
以上是生活随笔為你收集整理的通过FPGA将图片信息通过RS232串口发送到PC端,使用MATLAB进行图片显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Simulink的高速跳频通信系统抗
- 下一篇: 超声相控阵合成孔径成像FPGA设计介绍