数码管实验——简易秒表

秒表的制作并非一帆风顺,中间遇到了许多问题

比如计数寄存器的位数设置

reg     [?:0]    c1;

参考别人的代码写为31了,虽然最后成功了,但却不知道原因。。。

基础Verilog知识还是有待学习啊~‘

最终代码:

//=======================================================
//  This code is generated by Terasic System Builder
//=======================================================

module myDT(

    //////////// CLOCK //////////
    CLOCK_50,
    RSTn,

    //////////// LED //////////
    LEDG,
    LEDR,

    //////////// SEG7 //////////
    HEX0,
    HEX1,
    HEX2,
    HEX3,
    HEX4,
    HEX5,
    HEX6,
    HEX7
);

//=======================================================
//  PARAMETER declarations
//=======================================================

parameter _0 = 7‘b100_000_0, _1 = 7‘b111_100_1, _2= 7‘b010_010_0, _3 = 7‘b011_000_0,
             _4 = 7‘b001_100_1, _5 = 7‘b001_001_0, _6= 7‘b000_001_0, _7 = 7‘b111_100_0,
             _8 = 7‘b000_000_0, _9 = 7‘b001_000_0;

//=======================================================
//  PORT declarations
//=======================================================

//////////// CLOCK //////////
input                          CLOCK_50;
input                          RSTn;

//////////// LED //////////
output             [8:0]        LEDG;
output            [17:0]        LEDR;

//////////// SEG7 //////////
output             [6:0]        HEX0;
output             [6:0]        HEX1;
output             [6:0]        HEX2;
output             [6:0]        HEX3;
output             [6:0]        HEX4;
output             [6:0]        HEX5;
output             [6:0]        HEX6;
output             [6:0]        HEX7;

//=======================================================
//  REG/WIRE declarations
//=======================================================
reg      [31:0]      C7;
reg      [31:0]      C6;
reg      [31:0]      C5;
reg      [31:0]      C4;
reg      [31:0]      C3;
reg      [31:0]      C2;
reg      [31:0]      C1;
reg      [31:0]      C0;

reg             [6:0]        rHEX0;
reg             [6:0]        rHEX1;
reg             [6:0]        rHEX2;
reg             [6:0]        rHEX3;
reg             [6:0]        rHEX4;
reg             [6:0]        rHEX5;
reg             [6:0]        rHEX6;
reg             [6:0]        rHEX7;

//=======================================================
//  Structural coding
//=======================================================

//----1MS定时器
parameter T1MS = 16‘d49_999;
reg   [16:0]     Count1;
[email protected](posedge CLOCK_50 or negedge RSTn)
    if(!RSTn)
        Count1 <= 16‘d0;
    else if(Count1 == T1MS)
        Count1 <= 16‘d0;
    else
        Count1 <= Count1 + 16‘d1;        

//----MS定时器
reg    [16:0]  Count_MS;
[email protected](posedge CLOCK_50 or negedge RSTn)
    if(!RSTn)
        Count_MS <= 16‘d0;
    else if(Count_MS == 10‘d1000)
        Count_MS <= 16‘d0;
    else if(Count1 == T1MS)
        Count_MS <= Count_MS + 16‘d1;

//----S定时器
reg  [16:0] Count_S;
[email protected](posedge CLOCK_50 or negedge RSTn)
    if(!RSTn)
        Count_S <= 16‘d0;
    else if(Count_S == 10‘d60)
        Count_S <= 16‘d0;
    else if(Count_MS == 16‘d1000)
        Count_S <= Count_S + 16‘d1;

//----M定时器
reg [16:0]    Count_M;
[email protected](posedge CLOCK_50 or negedge RSTn)
    if(!RSTn)
        Count_M <= 16‘d0;
    else if(Count_M == 10‘d60)
        Count_M <= 16‘d0;
    else if(Count_S == 10‘d60)
        Count_M <= Count_M + 16‘d1;

//----数码管显示

always @ (posedge CLOCK_50 or negedge RSTn)
    if(!RSTn)
        begin
            C7 = 31‘d0;
            C6 = 31‘d0;
            C5 = 31‘d0;
            C4 = 31‘d0;
            C3 = 31‘d0;
            C2 = 31‘d0;
            C1 = 31‘d0;
            C0 = 31‘d0;
        end
    else
        begin
            C7 = Count_M/10;
            C6 = Count_M%10;
            C5 = Count_S/10;
            C4 = Count_S%10;
            C3 = Count_MS/1000;
            C2 = Count_MS/100%10;
            C1 = Count_MS%100/10;
            C0 = Count_MS%10;
        end

always @ (posedge CLOCK_50 or negedge RSTn)
        case(C7)
            0 : rHEX7 = _0;
            1 : rHEX7 = _1;
            2 : rHEX7 = _2;
            3 : rHEX7 = _3;
            4 : rHEX7 = _4;
            5 : rHEX7 = _5;
            6 : rHEX7 = _6;
            7 : rHEX7 = _7;
            8 : rHEX7 = _8;
            9 : rHEX7 = _9;
        endcase

always @ (posedge CLOCK_50 or negedge RSTn)
        case(C6)
            0 : rHEX6 = _0;
            1 : rHEX6 = _1;
            2 : rHEX6 = _2;
            3 : rHEX6 = _3;
            4 : rHEX6 = _4;
            5 : rHEX6 = _5;
            6 : rHEX6 = _6;
            7 : rHEX6 = _7;
            8 : rHEX6 = _8;
            9 : rHEX6 = _9;
        endcase

always @ (posedge CLOCK_50 or negedge RSTn)
        case(C5)
            0 : rHEX5 = _0;
            1 : rHEX5 = _1;
            2 : rHEX5 = _2;
            3 : rHEX5 = _3;
            4 : rHEX5 = _4;
            5 : rHEX5 = _5;
            6 : rHEX5 = _6;
            7 : rHEX5 = _7;
            8 : rHEX5 = _8;
            9 : rHEX5 = _9;
        endcase

always @ (posedge CLOCK_50 or negedge RSTn)
        case(C4)
            0 : rHEX4 = _0;
            1 : rHEX4 = _1;
            2 : rHEX4 = _2;
            3 : rHEX4 = _3;
            4 : rHEX4 = _4;
            5 : rHEX4 = _5;
            6 : rHEX4 = _6;
            7 : rHEX4 = _7;
            8 : rHEX4 = _8;
            9 : rHEX4 = _9;
        endcase
/*
always @ (posedge CLOCK_50 or negedge RSTn)
        case(C3)
            0 : rHEX3 = _0;
            1 : rHEX3 = _1;
            2 : rHEX3 = _2;
            3 : rHEX3 = _3;
            4 : rHEX3 = _4;
            5 : rHEX3 = _5;
            6 : rHEX3 = _6;
            7 : rHEX3 = _7;
            8 : rHEX3 = _8;
            9 : rHEX3 = _9;
        endcase

always @ (posedge CLOCK_50 or negedge RSTn)
        case(C2)
            0 : rHEX2 = _0;
            1 : rHEX2 = _1;
            2 : rHEX2 = _2;
            3 : rHEX2 = _3;
            4 : rHEX2 = _4;
            5 : rHEX2 = _5;
            6 : rHEX2 = _6;
            7 : rHEX2 = _7;
            8 : rHEX2 = _8;
            9 : rHEX2 = _9;
        endcase

always @ (posedge CLOCK_50 or negedge RSTn)
        case(C1)
            0 : rHEX1 = _0;
            1 : rHEX1 = _1;
            2 : rHEX1 = _2;
            3 : rHEX1 = _3;
            4 : rHEX1 = _4;
            5 : rHEX1 = _5;
            6 : rHEX1 = _6;
            7 : rHEX1 = _7;
            8 : rHEX1 = _8;
            9 : rHEX1 = _9;
        endcase

always @ (posedge CLOCK_50 or negedge RSTn)
        case(C0)
            0 : rHEX0 = _0;
            1 : rHEX0 = _1;
            2 : rHEX0 = _2;
            3 : rHEX0 = _3;
            4 : rHEX0 = _4;
            5 : rHEX0 = _5;
            6 : rHEX0 = _6;
            7 : rHEX0 = _7;
            8 : rHEX0 = _8;
            9 : rHEX0 = _9;
        endcase
*/

//输出赋值

/*assign HEX0 = rHEX0;
assign HEX1 = rHEX0;
assign HEX2 = rHEX0;
assign HEX3 = rHEX0;    */

assign HEX0 = 7‘b111_111_1;
assign HEX1 = 7‘b111_111_1;
assign HEX2 = 7‘b111_111_1;
assign HEX3 = 7‘b111_111_1;
assign HEX4 = rHEX4;
assign HEX5 = rHEX5;
assign HEX6 = rHEX6;
assign HEX7 = rHEX7;    

endmodule
时间: 2024-10-24 20:35:27

数码管实验——简易秒表的相关文章

数码管实验报告

/************************************************* 实验名称:数码管实验一 实验目的:利用动态扫描方法在六位数码管上显示出稳定 的654321 *************************************************/ #include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit DUAN = P2^6; sbit WEI =

用51单片机实现的简易秒表

设计思路:在main函数中不停的控制数码管显示时.分.秒,同时用定时器0控制时间的递增 代码如下: 1 #include "reg52.h" 2 #define led P0 3 typedef unsigned char u8; 4 typedef unsigned int u16; 5 6 sbit LSA = P2^2; 7 sbit LSB = P2^3; 8 sbit LSC = P2^4; 9 sbit k3 = P3^2; 10 sbit k4 = P3^3; 11 st

简易秒表

<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><script>function addZero(n){    if(n < 10){        return '0' + n;    }else{        return '' + n;        }}window.onload = functio

驱动数码管的实验

        课程名称:_单片机原理与应用 专业班级: 嵌入式14103班 姓    名:_赵存档       _ __ 学    号:_14160310317    __   2015--2016    学年第  1  学期         实验项目( 四 ) — 预习报告 项目 名称 驱动7段数码管实验 实验 目的 及 要求 1.掌握用proteus画电路图. 2.用Keil编写代码,进行调试. 3.进行仿真测试 4.将hex文件下载到单片机中,是否可以运行. 实验 内容 及 原理 实验内

深入理解BOM系列第三篇——定时器应用(时钟、倒计时、秒表和闹钟)

× 目录 [1]时钟 [2]倒计时 [3]秒表[4]闹钟 前面的话 本文属于定时器的应用部分,分别用于实现与时间相关的四个应用,包括时钟.倒计时.秒表和闹钟.与时间相关需要用到时间和日期对象Date,详细情况移步至此 时钟 最简单的时钟制作办法是通过正则表达式的exec()方法,将时间对象的字符串中的时间部分截取出来,使用定时器刷新即可 <div id="myDiv"></div> <script> myDiv.innerHTML = /\d\d:\

51单片机第三弹---数码管显示

先把定义拉过来: LED数码管是由多个发光二极管封装在一起组成"8"字型的器件,引线已在内部连接完成,只需引出它们的各个笔划,公共电极.LED数码管常用的段数一般为7段,有的另加一个小数点 .LED数码管根据LED的接法不同,分为共阴和共阳两类 . 贴原理图 其实就两点 :由于板子上有8个数码管,而每个数码管有8段,称选择显示哪一个数码管的东西为位选,称单个数码管显示数字几的东西为段选,位选由P2.2  p2.3 p2.4 控制 数码管IO口为P0 对于每一个数码管,显示数字几只要控制

N数码问题的启发式搜索算法--A*算法python实现

一.启发式搜索:A算法 1)评价函数的一般形式 : f(n) = g(n) + h(n) g(n):从S0到Sn的实际代价(搜索的横向因子) h(n):从N到目标节点的估计代价,称为启发函数(搜索的纵向因子); 特点: 效率高, 无回溯, 搜索算法 OPEN表 : 存放待扩展的节点. CLOSED表 : 存放已被扩展过的节点. 2)评价函数  f(x) = g(x) + h(x) 当f(x) = g(x)   时,为宽度优先搜索 当f(x) = 1/g(x)时,为深度优先搜索 当f(x) = h

深入理解定时器系列第三篇——定时器应用(时钟、倒计时、秒表和闹钟)

前面的话 本文属于定时器的应用部分,分别用于实现与时间相关的四个应用,包括时钟.倒计时.秒表和闹钟.与时间相关需要用到时间和日期对象Date,详细情况移步至此 时钟 最简单的时钟制作办法是通过正则表达式的exec()方法,将时间对象的字符串中的时间部分截取出来,使用定时器刷新即可 <div id="myDiv"></div> <script> myDiv.innerHTML = /\d\d:\d\d:\d\d/.exec(new Date().toS

第五篇:本人多年来积累的单片机程序 资料下载(绝对干货,内附下载链接)

首先打个广告:如果需要做毕设以及嵌入式项目合作,欢迎进入我们工作室:创想嵌入式设计工作室 本人搜集的大量单片机源码资料及毕业设计资料,足有1200+套,很多实用的demo源码和毕业设计参考方案,可用于做项目时借鉴,博尾附有下载链接.(内附本人联系方式,可一起交流探讨,交朋友) 为了方便 查找,我已将项目源码的目录整理出来了,方便 采用"ctrl +F"快速查找验证是否有需要的demo.可以一键打包下载,也可只下载需要的demo. 下载链接内附本人联系方式,如果在安装过程中遇到问题,可以