Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1965184
  • 博文数量: 356
  • 博客积分: 8284
  • 博客等级: 中将
  • 技术积分: 4580
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-15 20:25
个人简介

天行健,君子以自强不息

文章分类

全部博文(356)

文章存档

2018年(1)

2016年(4)

2015年(13)

2014年(14)

2013年(2)

2012年(25)

2011年(43)

2010年(65)

2009年(189)

分类:

2009-09-23 22:04:27

/*心得与体会:
在写程序的时候有的时候的语法错误,编译环境检测不出来,编译后提示没有错误,但下载到目标板后达不到预期的效果。像这种错误有的时候很难发现。但确实存在。例如:
reg [2:0]  buffer;       (1)
always @(buffer)
 begin
  case(buffer)
   4'b0000: led=26'b00000000000000000000000000;
   4'b1000: led=26'b11111111111111111111111111;
  endcase
 end
定义的buffer是三位的,但是case语句中却是四位,这种问题编译环境发现不了。下载到目标板后,发光二极管并不闪烁。但是把(1)改为  reg  [3:0]   buffer后,问题就可以解决。
还有就是注意initial和always的区别。
 
*/
module clock(key,clk,segdat1,segdat2,segdat3,segdat4,segdat5,segdat6,segdat7,segdat8,led);
input key,clk;
output [6:0] segdat1,segdat2,segdat3,segdat4,segdat5,segdat6,segdat7,segdat8;
output [25:0] led;
reg [25:0] led;
reg [24:0]  count;
reg [7:0]  sec,min,hour;
reg [6:0]  segdat1,segdat2,segdat3,segdat4,segdat5,segdat6,segdat7,segdat8;
reg [3:0]  dispdat1,dispdat2,dispdat3,dispdat4,dispdat5,dispdat6;
reg [2:0]  count_reg;
reg second;
reg [1:0] count1;
reg cn,cm;
////////////////////fen ping///////////////////////////
/////////////////////////////////////////////////////////////
always @(posedge clk)
 begin
 count=count+1;
  if(count==25'd25000000)//2500'0000;
   begin
   count=25'b0000000000000000000000000;
   second=~second;
   count1=count1+1;
   end
 end
////////////////////display////////////////////////////
////////////////////////////////////////////////////////
always @(count[2:0])
 begin
  count_reg=count[2:0];
  segdat7=7'b1111111;
  segdat8=7'b1111111;
  if(count_reg==3'b110)
   begin
    count_reg=3'b000;
   end
  case(count_reg)
  3'b000: dispdat1=sec[3:0];    // miao  de ge wei
  3'b001: dispdat2=sec[7:4];   //miao  de shi wei
  3'b010: dispdat3=min[3:0];    //fen   de ge  wei
  3'b011: dispdat4=min[7:4];    //fen   de shi wei
  3'b100: dispdat5=hour[3:0];   //shi   de ge  wei
  3'b101: dispdat6=hour[7:4];   //shi   de shi wei
     endcase
    end
/////////////////////////miao  de  ge  wei///////////////////////////////////////
always @(dispdat1)
 begin
  case(dispdat1)
  4'h0:         segdat1=7'b1000000;//0
  4'h1:   segdat1=7'b1111001;//1
  4'h2:   segdat1=7'b0100100;//2
  4'h3:   segdat1=7'b0110000;//3
  4'h4:   segdat1=7'b0011001;//4
  4'h5:   segdat1=7'b0010010;//5
  4'h6:   segdat1=7'b0000010;//6
  4'h7:   segdat1=7'b1111000;//7
  4'h8:   segdat1=7'b0000000;//8
  4'h9:   segdat1=7'b0010000;//9
  endcase
 end
/////////////////////////miao  de  shi  wei///////////////////////////////////////
always @(dispdat2)
 begin
  case(dispdat2)
  4'h0:         segdat2=7'b1000000;//0
  4'h1:   segdat2=7'b1111001;//1
  4'h2:   segdat2=7'b0100100;//2
  4'h3:   segdat2=7'b0110000;//3
  4'h4:   segdat2=7'b0011001;//4
  4'h5:   segdat2=7'b0010010;//5
  4'h6:   segdat2=7'b0000010;//6
  4'h7:   segdat2=7'b1111000;//7
  4'h8:   segdat2=7'b0000000;//8
  4'h9:   segdat2=7'b0010000;//9
  endcase
 end
 
/////////////////////////fen   de  ge  wei///////////////////////////////////////
always @(dispdat3)
 begin
  case(dispdat3)
  4'h0:         segdat3=7'b1000000;//0
  4'h1:   segdat3=7'b1111001;//1
  4'h2:   segdat3=7'b0100100;//2
  4'h3:   segdat3=7'b0110000;//3
  4'h4:   segdat3=7'b0011001;//4
  4'h5:   segdat3=7'b0010010;//5
  4'h6:   segdat3=7'b0000010;//6
  4'h7:   segdat3=7'b1111000;//7
  4'h8:   segdat3=7'b0000000;//8
  4'h9:   segdat3=7'b0010000;//9
  endcase
 end
 
 
 
///////////////////////// fen  de  shi   wei///////////////////////////////////////
always @(dispdat4)
 begin
  case(dispdat4)
  4'h0:         segdat4=7'b1000000;//0
  4'h1:   segdat4=7'b1111001;//1
  4'h2:   segdat4=7'b0100100;//2
  4'h3:   segdat4=7'b0110000;//3
  4'h4:   segdat4=7'b0011001;//4
  4'h5:   segdat4=7'b0010010;//5
  4'h6:   segdat4=7'b0000010;//6
  4'h7:   segdat4=7'b1111000;//7
  4'h8:   segdat4=7'b0000000;//8
  4'h9:   segdat4=7'b0010000;//9
  endcase
 end
 
/////////////////////////shi  de    ge   wei///////////////////////////////////////
always @(dispdat5)
 begin
  case(dispdat5)
  4'h0:         segdat5=7'b1000000;//0
  4'h1:   segdat5=7'b1111001;//1
  4'h2:   segdat5=7'b0100100;//2
  4'h3:   segdat5=7'b0110000;//3
  4'h4:   segdat5=7'b0011001;//4
  4'h5:   segdat5=7'b0010010;//5
  4'h6:   segdat5=7'b0000010;//6
  4'h7:   segdat5=7'b1111000;//7
  4'h8:   segdat5=7'b0000000;//8
  4'h9:   segdat5=7'b0010000;//9
  endcase
 end

/////////////////////////shi  de    shi   wei///////////////////////////////////////
always @(dispdat6)
 begin
  case(dispdat6)
  4'h0:         segdat6=7'b1000000;//0
  4'h1:   segdat6=7'b1111001;//1
  4'h2:   segdat6=7'b0100100;//2
  4'h3:   segdat6=7'b0110000;//3
  4'h4:   segdat6=7'b0011001;//4
  4'h5:   segdat6=7'b0010010;//5
  4'h6:   segdat6=7'b0000010;//6
  4'h7:   segdat6=7'b1111000;//7
  4'h8:   segdat6=7'b0000000;//8
  4'h9:   segdat6=7'b0010000;//9
  endcase
 end

//////////////////////////////ji  shi  chu li////////////////////////////////
////////////////////////////////////////////////////////////////////////////
 
////////////////////////////miao  de  chu  li///////////////////////////////////////////////////
always @(posedge second)
 begin
  if(!key)
   begin
    sec[7:0]=8'h0;
    cn=0;
   end
  else
   begin
    cn=0;
    sec[3:0]=sec[3:0]+1;
    if(sec[3:0]==4'd10)
     begin
      sec[3:0]=4'd0;
      sec[7:4]=sec[7:4]+1;
      if(sec[7:4]==4'd6)
      begin
       sec[7:4]=4'd0;
       cn=1;
      end
      
     end
   end
 end
//////////////////////////fen  de   chu  li//////////////////////////////////////////
always @(posedge cn)
 begin
  if(!key)
   begin
   min[7:0]=8'h0;
   cm=0;
   end
  else
   begin
    min[3:0]=min[3:0]+1;
    cm=0;
    if(min[3:0]==4'd10)
     begin
      min[3:0]=4'd0;
      min[7:4]=min[7:4]+1;
      if(min[7:4]==4'd6)
      begin
       min[7:4]=4'd0;
       cm=1;
      end
     end
   end
 end
/////////////////////shi   de   chu      li //////////////////////////////////////////////////////////////////
 
always @(posedge cm)
  begin
     begin
           if(hour[7:4]==4'd2)
          if(hour[3:0]>=4'd3)
             begin
        hour[7:4]=4'd0;
        hour[3:0]=4'd0;
              end
     end
     
   if(!key)
   begin
   hour[7:0]=8'h0;
   end
   else
    begin
     hour[3:0]=hour[3:0]+1;
     if(hour[3:0]==4'd10)
      begin
       hour[3:0]=4'd0;
       hour[7:4]=hour[7:4]+1;
      end
    end
  end
reg  [3:0] buffer;  
always
 begin
  buffer=count1[1:0];
  //led=26'b00000000000000000000000000;
 end
  
  
/////////////////////////////led fa guang  shan shuo////////////////////////////////
always @(buffer)
 begin
  case(buffer)
   2'b00: led=26'b00000000000000000000000000;
   2'b10: led=26'b11111111111111111111111111;
  endcase
 end
 
endmodule
   
 
文件: clock.rar
大小: 608KB
下载: 下载

 
 
 
 
 
 
 
 
阅读(7741) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~