1、准备 目前用到以下工具和硬件:
  开发工具 Quartus II 13.0 
  仿真工具 Modelsim Altera 
  开发板型号 Cyclone EP1C3 
 
2、建立初始工程 2.1 建立简单LED示例 在Quartus开发工具中,新建项目,硬件型号选择 Cyclone EP1C3T144C8。
2.2 编写rtl代码 新建verilog文件mcu_top,并添加到工程rtl目录,代码内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 module  mcu_top(    clk,     rst,     led ); input  clk;input  rst;output  led;reg  led;reg  [15 :0 ] counter;always @(posedge  clk)begin     if (rst)begin          led <= 0 ;         counter <= 0 ;     end  else  begin          counter <= counter +1 ;         if (counter >= 16'h8 ) begin              counter <= 0 ;             led <= ~led;         end      end  end  endmodule 
编写好后,将该文件设置为set as top-level entity,然后点击Start compilation进行编译排除错误。
3、仿真验证 3.1 编写仿真文件 编写testbench文件放到工程tb目录,仿真文件中主要产生一个100MHz的时钟,即周期10ns,再产生一个复位信号,具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 `timescale  1ns/10ps module  testbench();reg  clk;reg  rst;wire  led;initial  begin     clk = 0 ;     rst = 0 ;               #500  rst = 1 ;     #500  rst = 0 ;          #1000000 ;     $finishe(); end always  begin     #5  clk = ~clk; end mcu_top u_mcu(     .clk     (clk),     .rst     (rst),     .led     (led) ); endmodule 
3.2 仿真 在Settings窗口中设置仿真工具和仿真文件,然后运行RTL simulation,结果如下: