用MATLAB產生VIVADO可用的coe檔案

huxibin發表於2018-05-10
%**************************************************************************
% Generate MIF file
%
%                               resevered by 
%                                   2015.11.09
%**************************************************************************


[FileName,PathName] = uigetfile('*.bmp','Select the *.bmp file'); 
f = fullfile(PathName,filesep,FileName);
fid = fopen(f,'r');
im=imread(f);
%fr=dec2bin(im(:),8);


[r,c,d]=size(im)
red=im;


red(:,:,1)= red(:,:,1);
red(:,:,2)= zeros(r,c);
red(:,:,3)= zeros(r,c);
red=uint8(red);
subplot(1,4,1)
imshow(red);


depth =64; %儲存器的單元數
width =64;%資料寬度為8位
%N = 0 :255;
%s =sin(2*pi *N/256);%計算0 ~2*pi之間的sin值
fidc = fopen('64r.coe','wt')
%fprintf(fidc , 'depth = %d;\n',depth);
%fprintf(fidc, 'width = %d;\n',width);
fprintf(fidc, 'MEMORY_INITIALIZATION = 16;\n');
fprintf(fidc,'MEMORY_INITIALIZATION_VECTOR= \n');
%fprintf(fidc,'content begin\n');
%for x = 1 : depth
%    for y=1: width
%   fprintf(fidc,'%d:',(x-1));
%   fprintf(fidc,'%d',im(x,:));
%  fprintf(fidc,'%s,',dec2bin(im(x,y)));
%  fprintf(fidc,'\n');
%   fprintf(fidc,'%d:',(x-1));
%  fprintf(fidc,';\n');
%    end
%end


fprintf(fidc,'%x,\n',red(:,:,1));
%fprintf(fidc, 'end;');
fclose(fidc);
%imshow(uint8(im));

相關文章