欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2003|回復: 0
收起左側

定時計數器的Verilog代碼

[復制鏈接]
ID:420678 發表于 2018-11-4 20:12 | 顯示全部樓層 |閱讀模式
`timescale 1ns / 1ps
`define  ENABLE           1'b1
`define  DISABLE           1'b0
`define  HIGH              1'b1
`define  LOW               1'b0
`define  DATA_W     8
`define  EA      7
`define  TF      6
`define  ET0      0
`define  ET1      1
`define  OV      2
module timer_counter(
input wire         clk,
    input wire         reset,
input wire        count,
input   wire  [`DATA_W-1:0]     th,
input   wire  [`DATA_W-1:0]     tl,
input   wire  [`DATA_W-1:0]     tmod,
input   wire  [`DATA_W-1:0]     ie,
output  wire                    mul,
output reg            irq_timer0,
output reg            irq_timer1
   
);
reg [`DATA_W-1:0]   th0;
reg [`DATA_W-1:0]   tl0;
wire     flag;
reg     a,b;
always @(posedge clk)
begin
if(!reset)
begin
th0<=8'h0;
tl0<=8'h0;
irq_timer1<=`DISABLE;
end
else if(ie [`EA])
if(ie [`TF])
begin
if(tmod[1]==`LOW)
begin
  if((tmod [0]==`LOW)&&(ie [`ET0]==`ENABLE))
  begin
   if((16'hFFFF-{th,tl})=={th0,tl0})
   begin
    tl0<=8'h0;
    th0<=8'h0;
    irq_timer0<=`ENABLE;
//   ov       <=`ENABLE;
   end
   else  {th0,tl0}<={th0,tl0}+1;
   
  end
  else if((tmod [0]==`HIGH)&&(ie [`ET1]==`HIGH))
  begin
    if(tl0==8'hFF)
    begin
    tl0  <=8'h0;
    irq_timer1<=`ENABLE;
  //  ov          <=`ENABLE;
    end
    else  tl0<=tl0+1;   
  end
end
else if(tmod [1]==`HIGH)
begin
if((tmod [0]==`LOW)&&(ie [`ET0]==`ENABLE)&&flag)
  begin
   if((16'hFFFF-{th,tl})=={th0,tl0})
   begin
    tl0<=8'h0;
    th0<=8'h0;
    irq_timer0<=`ENABLE;
//   ov       <=`ENABLE;
   end
   else  {th0,tl0}<={th0,tl0}+1;
   
  end
  else if((tmod [0]==`HIGH)&&(ie [`ET1]==`HIGH))
  begin
    if({tl0}==8'hFF)
    begin
    irq_timer1  <=`ENABLE;
    tl0<=8'h0;
  //  ov          <=`ENABLE;
    end
    else  tl0<=tl0+1;   
  end
end
end
else begin
   irq_timer0<=`DISABLE;
   irq_timer1<=`DISABLE;
   tl0<=8'h0;
            th0<=8'h0;
   end
end
always @(*)
begin
a<=count;
b<=a;
end
//assign irq_timer0=c&&!d;
assign flag=a&&!b;
assign mul=tmod [0]&&ie [`ET1]&&ie [`EA]&&ie [`TF];
endmodule

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表