| 
 
| 上电后,用于显示采样数据的8个led灯先全亮,然后最高位灭,下来全灭。 程序是这样的——
 module amyad(clk,din,clk_ad,cs,dout);
 input clk;
 input din;
 output     clk_ad;
 output reg cs;
 output reg [7:0]dout;
 
 reg [5:0]cnt_fre;
 reg clk1M;
 reg attach;
 reg [4:0]cnt_ad;
 reg [7:0]temp;
 
 parameter period_fre = 6'd49;
 parameter period_ad = 5'd27;
 
 always@(negedge clk)
 if(cnt_fre != period_fre)  begin
 cnt_fre <= cnt_fre + 6'd1;
 clk1M   <= 1'b0;                     end
 else begin  cnt_fre <= 5'd0;
 clk1M   <= 1'b1;                      end
 
 always@(negedge clk)
 if(clk1M)begin
 if(cnt_ad != period_ad)
 cnt_ad <= cnt_ad + 5'd1;
 else     cnt_ad <= 5'd0;                  end
 
 always@(negedge clk)
 if(clk1M)begin
 if(cnt_ad >= 5'd20 && cnt_ad <= 5'd27)
 attach <= 1'b1;
 else  attach <= 1'b0;                                end
 
 assign clk_ad = (attach && clk1M);
 
 always@(negedge clk)
 if(clk1M)
 case(cnt_ad)
 5'd0:   cs <= 1'b1;
 5'd1:   dout <= temp;
 5'd18:   cs <= 1'b0;
 5'd20:   temp[7] <= din;
 5'd21:   temp[6] <= din;
 5'd22:   temp[5] <= din;
 5'd23:   temp[4] <= din;
 5'd24:   temp[3] <= din;
 5'd25:   temp[2] <= din;
 5'd26:   temp[1] <= din;
 5'd27:   temp[0] <= din;
 endcase
 endmodule
 高手们,指点一下吧!谢谢!
 | 
 |