搜索
bottom↓
回复: 13

可调节电子钟

[复制链接]

出0入0汤圆

发表于 2013-4-28 13:38:31 | 显示全部楼层 |阅读模式
module shifenmiao(clk,seg,wei,key_in);
input clk;
input[3:0]key_in;
output[7:0] wei;
output[7:0] seg;
reg[23:0] hour;
reg[7:0] seg_r;
reg[7:0] wei_r;
reg[3:0] deg_r;
reg[24:0] FIV;reg sec;

assign seg=seg_r;
assign wei=wei_r;
always @(posedge clk)
begin       
        FIV=FIV+1'b1;
        if(FIV==24000000)
        begin
                FIV=25'd0;
                sec=~sec;
        end
end
always@(posedge clk)
begin
        case(FIV[17:15])
        3'b000:wei_r=8'b11111110;
        3'b001:wei_r=8'b11111101;
        3'b010:wei_r=8'b11111011;
        3'b011:wei_r=8'b11110111;
        3'b100:wei_r=8'b11101111;
        3'b101:wei_r=8'b11011111;
        3'b110:wei_r=8'b10111111;
        3'b111:wei_r=8'b01111111;
        default:wei_r=4'h4;
        endcase       
        case(FIV[17:15])
        3'b000:deg_r=hour[3:0];
        3'b001:deg_r=hour[7:4];
        3'b010:deg_r=4'hF;
        3'b011:deg_r=hour[11:8];
        3'b100:deg_r=hour[15:12];
        3'b101:deg_r=4'hF;
        3'b110:deg_r=hour[19:16];
        3'b111:deg_r=hour[23:20];
        default:deg_r=4'hF;
        endcase       
end
always@(posedge sec)
begin
        if(key_in[0]==0)
        hour=24'd0;
        else if(key_in[1]==0)
        begin
                hour[3:0]=hour[3:0]+4'd1;//秒的个位数
                if(hour[3:0]==10)
                begin
                        hour[3:0]=0;
                        hour[7:4]=hour[7:4]+4'd1;
                        if(hour[7:4]==6)hour[7:0]=8'd0;
                end
        end
        else if(key_in[2]==0)
        begin
                hour[11:8]=hour[11:8]+4'd1;//分的个位数
                if(hour[11:8]==10)
                begin
                        hour[11:8]=0;
                        hour[15:12]=hour[15:12]+4'd1;
                        if(hour[15:12]==6)hour[15:8]=8'd0;
                end
        end               
        else if(key_in[3]==0)
        begin
                hour[19:16]=hour[19:16]+4'd1;//小时的个位数
                if(hour[19:16]==10)
                begin
                        hour[19:16]=0;
                        hour[23:20]=hour[23:20]+4'd1;
                        if(hour[23:20]==2 && hour[19:16]==4)hour[23:0]=24'd0;
                end
        end
        else
        begin
                hour[3:0]=hour[3:0]+4'd1;//秒的个位数
                if(hour[3:0]==4'ha)
                begin
                        hour[3:0]=4'd0;
                        hour[7:4]=hour[7:4]+4'd1;//秒的十位数
                        if(hour[7:4]==4'h6)
                        begin
                                hour[7:4]=4'd0;
                                hour[11:8]=hour[11:8]+4'd1;//分的个位数
                                if(hour[11:8]==4'ha)
                                begin
                                        hour[11:8]=4'd0;
                                        hour[15:12]=hour[15:12]+4'd1;//分的十位数
                                        if(hour[15:12]==4'h6)
                                        begin
                                                hour[15:12]=4'd0;
                                                hour[19:16]=hour[19:16]+4'd1;//小时的个位数
                                                if(hour[19:16]==4'd10)
                                                begin
                                                        hour[19:16]=4'd0;
                                                        hour[23:20]=hour[23:20]+4'd1;//小时的十位数
                                                if(hour[23:20]==4'd2 && hour[19:16]==4'd4)hour[23:16]=8'd0;
                                                end
                                        end
                                end
                        end
                end
        end
end       
always@(deg_r)
begin
        case(deg_r)
        4'h0:seg_r=8'hc0;
        4'h1:seg_r=8'hf9;
        4'h2:seg_r=8'ha4;
        4'h3:seg_r=8'hb0;
        4'h4:seg_r=8'h99;
        4'h5:seg_r=8'h92;
        4'h6:seg_r=8'h82;
        4'h7:seg_r=8'hf8;
        4'h8:seg_r=8'h80;
        4'h9:seg_r=8'h90;
        default:seg_r=8'hbf;  
        endcase       
end
endmodule

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2013-4-28 13:39:13 | 显示全部楼层

出0入0汤圆

 楼主| 发表于 2013-4-28 13:39:44 | 显示全部楼层
顶顶顶

出0入0汤圆

 楼主| 发表于 2013-8-19 18:21:48 | 显示全部楼层

出0入0汤圆

 楼主| 发表于 2013-8-19 18:22:25 | 显示全部楼层
头像被屏蔽

出0入0汤圆

发表于 2013-8-19 18:26:56 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

 楼主| 发表于 2013-8-20 22:05:27 | 显示全部楼层

出0入0汤圆

发表于 2013-8-21 10:24:49 | 显示全部楼层
同步时钟里一大堆=号,楼主想干嘛

出0入0汤圆

 楼主| 发表于 2013-8-21 15:26:48 | 显示全部楼层
wildone 发表于 2013-8-21 10:24
同步时钟里一大堆=号,楼主想干嘛

有问题吗?这个我是验证通过的!

出0入0汤圆

发表于 2013-8-21 15:43:44 | 显示全部楼层
389704844 发表于 2013-8-21 15:26
有问题吗?这个我是验证通过的!

一堆毛刺。

出0入0汤圆

 楼主| 发表于 2013-8-21 21:34:28 | 显示全部楼层
wildone 发表于 2013-8-21 15:43
一堆毛刺。

谢谢您====

出0入0汤圆

发表于 2013-8-24 23:39:49 | 显示全部楼层
来顶一个

出0入0汤圆

发表于 2013-8-25 15:42:59 | 显示全部楼层
加油  !

出0入0汤圆

 楼主| 发表于 2013-8-28 10:32:45 | 显示全部楼层
Fourier00 发表于 2013-8-25 15:42
加油  !

谢谢您!加油
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 05:23

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表