頁:
[1]
用xilinx ISE寫簡易計算機的問題
想寫一個簡易型只有加減功能的計算機在板子上不過問題一堆阿,現在正在解決七段顯示錯誤的問題,想請問各路高手們可不可以指教一下程式碼:
module keyboard(clk,rst,kb_in,kb_out,seg,t,sscom,in,w,a,r,r1,r2,r3,r4);
input clk,rst,in;
inputkb_in; //橫向Row(列) (如1,2,3為一列,共4列)
output regkb_out;
output reg w,a,r,r1,r2,r3,r4; //縱向column(行) (如1,4,7,*為一行,共3行)
output regseg;
output reg sscom;
regstate=2'b00;
output t;
assign t={kb_in,kb_out};
reg divclk;
reg count;
always @(posedge clk)
begin
if(count==24'h00ffff) //除頻
begin
count<=0;
divclk<=~divclk;
end
else
count<=count+1;
end
always@(posedge divclk)
begin
case(state) //state0,1,2會在按下數字鍵時觸發,數字鍵未按下時12個鍵盤皆為高電位'1',當按下數字鍵時, 該數字鍵為接地'0'
0: //state0,1,2因判斷皆相同,會不停執行
if(kb_in==4'b1111) //當按下數字鍵(例如'9')時,kb_in=1101,kb_out=011,此時case0,1,2皆不滿足條件,利用在'if'的條件下,
begin //系統會將{kb_in,kb_out}1101011存起來.
state<=1;
kb_out=3'b110;
end
1:
if(kb_in==4'b1111)
begin
state<=2;
kb_out=3'b101;
end
2:
if(kb_in==4'b1111)
begin
state<=0;
kb_out=3'b011;
end
default:;
endcase
end
always@(posedge clk) //當clk正緣觸發時,會將存起來的{kb_in,kb_out}依照數值顯示至七段顯示器
begin
case({kb_in,kb_out})
//左邊為{kb_in,kb_out}目前數值,右邊則是輸出七段顯示之數字
7'b0111110:a=a*10+1;//1
7'b0111101:a=a*10+2;//2
7'b0111011:a=a*10+3;//3
7'b1011110:a=a*10+4;//4
7'b1011101:a=a*10+5;//5
7'b1011011:a=a*10+6;//6
7'b1101110:a=a*10+7;//7
7'b1101101:a=a*10+8;//8
7'b1101011:a=a*10+9;//9
7'b1110110:begin //+
r=r+a;
a=a*0;
end
7'b1110101:a=a*10;//0
7'b1110011:begin//-
r=r-a;
a=a*0;
end
endcase
div_rill d1(r,1000,r1,w);
div_rill d2(r,100,w,r2);
div_rill d3(w,10,w,r2);
div_rill d4(r,10,w,r3);
div_rill d5(w,10,w,r3);
div_rill d6(r,10,w,r4);
case(in)
0:r=0;
endcase
sscom=sscom+1;
if(sscom==4'b0111)
begin
case(r1)
1:seg=8'b1111001;//1
2:seg=8'b0100100;//2
3:seg=8'b0110000;//3
4:seg=8'b0011001;//4
5:seg=8'b0010010;//5
6:seg=8'b0000010;//6
7:seg=8'b1111000;//7
8:seg=8'b0000000;//8
9:seg=8'b0010000;//9
0:seg=8'b1000000;//0
endcase
end
if(sscom==4'b1011)
begin
case(r2)
1:seg=8'b1111001;//1
2:seg=8'b0100100;//2
3:seg=8'b0110000;//3
4:seg=8'b0011001;//4
5:seg=8'b0010010;//5
6:seg=8'b0000010;//6
7:seg=8'b1111000;//7
8:seg=8'b0000000;//8
9:seg=8'b0010000;//9
0:seg=8'b1000000;//0
endcase
end
if(sscom==4'b1101)
begin
case(r3)
1:seg=8'b1111001;//1
2:seg=8'b0100100;//2
3:seg=8'b0110000;//3
4:seg=8'b0011001;//4
5:seg=8'b0010010;//5
6:seg=8'b0000010;//6
7:seg=8'b1111000;//7
8:seg=8'b0000000;//8
9:seg=8'b0010000;//9
0:seg=8'b1000000;//0
endcase
end
if(sscom==4'b1110)
begin
case(r4)
1:seg=8'b1111001;//1
2:seg=8'b0100100;//2
3:seg=8'b0110000;//3
4:seg=8'b0011001;//4
5:seg=8'b0010010;//5
6:seg=8'b0000010;//6
7:seg=8'b1111000;//7
8:seg=8'b0000000;//8
9:seg=8'b0010000;//9
0:seg=8'b1000000;//0
endcase
end
end
endmodule
module div_rill(input a,input b,output reg yshang,output reg yyushu);
reg tempa;
reg tempb;
reg temp_a;
reg temp_b;
integer i;
always @(a or b)
begin
tempa <= a;
tempb <= b;
end
always @(tempa or tempb)
begin
temp_a = {32'h00000000,tempa};
temp_b = {tempb,32'h00000000};
for(i = 0;i < 32;i = i + 1)
begin
temp_a = {temp_a,1'b0};
if(temp_a >= tempb)
temp_a = temp_a - temp_b + 1'b1;
else
temp_a = temp_a;
end
yshang <= temp_a;
yyushu <= temp_a;
end
endmodule
實驗結果:
板子上的七段全部都只顯示 r4 的資料,想請問可否指點一下,感謝!
...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div><div></div> always @(posedge clk)
內部訊號全都沒有reset 兩大問題:
1.沒有fully synchronous design.
2.blocking and non-blocking assign 完全誤用
當然還有樓上說的reset~~~
頁:
[1]