zoukankan      html  css  js  c++  java
  • 利用VHDL读写file文件

    library ieee;
        use std.textio.all;
        use ieee.std_logic_textio.all;
        use ieee.std_logic_1164.all;
        use ieee.std_logic_unsigned.all;
    entity testin is
    end entity testin;
    architecture rtl of testin is
        begin
            process is
                file file_out1,filein: text; --定义text类型的文件句柄;
                variable fstatus1,fstatus2:FILE_OPEN_STATUS;   --定义文件状态指示变量;
                variable count:integer:=5;           --定义integer型写入数据;
                variable stringdata:string(5 downto 1):="whwnh";--定义string型写入数据;
                variable vectordata:bit_vector(5 downto 0):="001000";--定义bit_vector型的写入数据;
                variable value:std_logic_vector(3 downto 0):="1111";--定义std_logic_vector型的写入数据;
                variable BUF,BUF1:LINE;
                begin
                        file_open(fstatus1,file_out1,"datain.txt",write_mode);  --打开文件“datain.txt"
                        write(file_out1,string'("the first parameter is="));    --通过write()函数直接向文件中写入对应类型数据。
                        readline(input,buf);                                    --从控制台输入字符串输入文件;
                        write(buf,count);
                        writeline(file_out1,buf);                                      --向文件中输入integer类型
                        wait for 20 ns;
                        write(buf,string'("the second parameter is="));
                        write(buf,value);
                        writeline(file_out1,buf);   
                        wait for 20 ns;                                     --向文件中输入std_logic_vector类型数据;
                        write(buf,string'("the third parameter is="));
                        write(buf,vectordata);
                        writeline(file_out1,buf); 
                        wait for 20 ns;                                  --向文件中输入bit_vector类型数据;
                        write(buf,string'("the forth parameter is="));
                        write(buf,stringdata);                                  --向文件中输入string类型数据。
                        writeline(file_out1,buf);
                        write(file_out1,string'("end of file"));
                        file_close(file_out1); 
                        wait for 100 ns;                                --关闭文件
                        file_open(fstatus1,file_out1,"datain.txt",read_mode);  --以读取模式打开文件
                        readline(file_out1,buf);                               --读取文件数据并输出到控制台界面。
                        writeline(output,buf);               
                        file_close(file_out1);
                        wait for 100 ns;
                        file_open(fstatus1,filein,"STD_INPUT",read_mode);      --以控制台作为文件输入
                        file_open(fstatus2,file_out1,"STD_OUTPUT",write_mode);  --以控制台作为文件输出
                        readline(filein,BUF);
                        writeline(file_out1,BUF);
             wait;  
            end process;
        end rtl;

  • 相关阅读:
    使用TFS CI 又想保留服务运行状态的简单方法
    【知乎】二战中日本陆军的建制
    缓存你的BITMAP对象
    Android 多种方式正确的加载图像,有效避免oom
    GitHub进一步了解
    响应式编程,是明智的选择
    Android 主题动态切换框架:Prism
    Android Fragment使用(二) 嵌套Fragments (Nested Fragments) 的使用及常见错误
    ClassLoader工作机制
    Java——泛型(最易懂的方式讲解泛型)
  • 原文地址:https://www.cnblogs.com/rednodel/p/4056099.html
Copyright © 2011-2022 走看看