程式如下,管腳怎么分配
module responder1323(rst,clk,ina,inb,inc,ind,judge,clk_1hz,wei,duan,beep,wei1,duan1,sec,nrst);
input clk,clk_1hz,nrst;
input ina,inb,inc,ind,judge;
input rst;
output sec;
output[3:0] wei;
output[7:0] duan;
output [3:0] wei1;
output [7:0] duan1;
output beep;
wire[3:0] wei;
wire[7:0] duan;
reg flag,beep,yu;
reg [5:0] shi,ge,data;
reg [4:0] count;
wire [3:0] wei1;
wire [7:0] duan1;
reg [1:0] count3;
fp1323 (nrst,clk,sec);
qd1323 (clk,rst,judge,wei,duan,ina,inb,inc,ind,clk_1hz);
fmq1323(clk_1hz);
ym1323(clk,rst,wei1);
endmodule
module fp1323(nrst,clk,sec);
input clk,nrst;
output sec;
reg sec;
reg [25:0]cnt;
always @(posedge clk or negedge nrst)
begin
if(!nrst)//電路總開關
begin
cnt<=0;
sec<=0;
end
else if(cnt==26'd24999999)//打開總開關時
begin
cnt<=0;
sec<=~sec;
end
else
cnt<=cnt+1;
end
endmodule
module qd1323(clk,rst,judge,wei,duan,ina,inb,inc,ind,clk_1hz);
input clk,clk_1hz,rst;
input ina,inb,inc,ind,judge;
output [3:0] wei;
output[7:0] duan;
reg [3:0] wei;
reg [7:0]duan;
reg flag;
reg [5:0] shi,ge;
reg [4:0] count;
reg yu;
always @(posedge clk)
begin
if(!rst) //系統復位
begin
yu = 0;
end
if(!judge) //主持人控制按鍵
begin
flag=0; //允許搶答
wei=4'b1111; //數碼管全不亮
duan=8'hff;
yu=1; //重新開始倒計時
end
else
begin
if(ge==6'b000000&&shi==6'b000000) //處于等待狀態
;
else
begin
if(!ina) //若a搶答
begin
if(!flag) //若無人搶答成功
begin
wei=4'b1101;
duan=8'hf9; //數碼管顯示1,代表a搶答成功
flag=1; //搶答標志位有效
end
end
else if(!inb) //b搶答處理電路
begin
if(!flag)
begin
wei=4'b1101;
duan=8'ha4; //數碼管顯示2,代表b搶答成功
flag=1;
end
end
else if(!inc)
begin
if(!flag)
begin
wei=4'b1101;
duan=8'hb0; //數碼管顯示3
flag=1;
end
end
else if(!ind)
begin
if(!flag)
begin
wei=4'b1101;
duan=8'h99; //數碼管顯示4
flag=1;
end
end
end
end
end
always@(posedge clk_1hz or negedge rst)
begin
if(!rst)
begin
count = 0;
end
else if(count >= 5'd30) //計時達到30秒,停止計時
count = count;
else if(yu==1) //觸發條件yu=1時
count = count+5'b1;
end //以下always程序塊為shi和ge的譯碼電路,完成倒計時功能
always @(count)
begin
if(count>=5'b10101) //count>20時
begin
shi = 5'b00000; //shi=0
ge = 5'b11110-count; //ge = 30-count
end
else if(count>=5'b01011) //10<count<=20時
begin
shi=5'b00001; //shi=1
ge=5'b10100-count; //ge = 20-count
end
else if(count>=5'b00001) //0<count<=10時
begin
shi=5'b00010; //shi=2
ge=5'b01010-count; //ge = 10-count
end
else //其它情況,i.e. count = 0
begin
shi=5'b00011; //shi=3
ge=5'b0; //ge = 0
end
end
endmodule
module fmq1323(clk_1hz);
input clk_1hz;
reg flag,beep;
reg [5:0] shi,ge;
reg [1:0] count3;
always@(posedge clk_1hz)
if(flag|(shi==0&&ge==0)) //flag==1,有人搶答成功,shi==0&&ge==0,倒計時結束
begin //上述兩種情況下蜂鳴器響一秒
if(count3==2'b1)
begin
beep<=0;
count3<=count3;
end
else
begin
beep<=1;
count3<=count3+2'b1;
end
end
else
begin
beep<=0;
count3<=0;
end
endmodule
module ym1323(clk,rst,wei1);
input clk,rst;
output [3:0] wei1;
reg [3:0] wei1;
reg [5:0] shi,ge,data;
reg [7:0] duan1;
always @(clk)
begin
if(!rst)
wei1 = 4'b0000;
else if(clk)
begin
wei1=4'b0111;
data=https://bbs.csdn.net/topics/ge;
end
else
begin
wei1=4'b1011;
data=https://bbs.csdn.net/topics/shi;
end
end
always @(data) //數字顯示譯碼,共陽極數碼管(duan1)
begin
case(data)
6'b000000: duan1=8'b1100_0000;
6'b000001: duan1=8'b1111_1001;
6'b000010: duan1=8'b1010_0100;
6'b000011: duan1=8'b1011_0000;
6'b000100: duan1=8'b1001_1001;
6'b000101: duan1=8'b1001_0010;
6'b000110: duan1=8'b1000_0010;
6'b000111: duan1=8'b1111_1000;
6'b001000: duan1=8'b1000_0000;
6'b001001: duan1=8'b1001_0000;
default:duan1=8'b1111_1111;
endcase
end
endmodule
uj5u.com熱心網友回復:
選定了器件,就可以用它的管腳分配工具搞了啊。。。uj5u.com熱心網友回復:
時鐘和復位用專用管腳會比較節省,其它管腳按布線方便就可以。轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/274603.html
標籤:單片機/工控
下一篇:關于CAN上位機協議