RenHao

20130515_DigitalDesign_Test

May 15th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module counter(input ck,re,output [7:0]seg,led);
  2.  
  3. reg [24:0]div;
  4. reg [2:0]count ;
  5. reg ck_1;
  6.  
  7.  
  8. always @(posedge ck,negedge re)
  9. begin
  10.     if(!re) begin div <= 0 ; ck_1 <= 0 ; end
  11.     else if(div == 24999999) begin div <= 0 ; ck_1 <= ~ck_1 ; end
  12.     else div <= div + 1 ;
  13. end
  14.  
  15. always @(posedge ck_1,negedge re)
  16. begin
  17.     if(!re) count <= 3'b111 ;
  18.     else if(count == 0) count <= 3'b111;
  19.     else count <= count - 1 ;
  20. end
  21.  
  22. assign led[7:0] = (count==0) ? 8'b11111110 :
  23.                   (count==1) ? 8'b11111101 :
  24.                   (count==2) ? 8'b11111011 :
  25.                   (count==3) ? 8'b11110111 :
  26.                   (count==4) ? 8'b11101111 :
  27.                   (count==5) ? 8'b11011111 :
  28.                   (count==6) ? 8'b10111111 :
  29.                   8'b01111111 ;
  30.                  
  31. assign seg[7:0] = (count==0) ? 8'b00000010 :
  32.                   (count==1) ? 8'b10011110 :
  33.                   (count==2) ? 8'b00100100 :
  34.                   (count==3) ? 8'b00001100 :
  35.                   (count==4) ? 8'b10011000 :
  36.                   (count==5) ? 8'b01001000 :
  37.                   (count==6) ? 8'b01000000 :
  38.                   8'b00011110 ;
  39.  
  40.  
  41.  
  42. endmodule
Advertisement
Add Comment
Please, Sign In to add comment