利用inout 寫法 wire , reg , <= 則GPIO_0 每一支Pin 皆可以是In 或 Out
原來是GPIO_0 , GPIO_1 各為Out 及 In 現在則僅需要用一個GPIO即可
// inout [35:0]GPIO_1;
// reg [35:0]GPIO_1;
// GPIO_1 [0],[1] input , GPIO_1 [35:2] INOUT
// wire KEY0,KEY1;
// reg rKEY0,nKEY1;
// assign KEY0= GPIO_1[0]; Change display Mode KEY0 ? cnt : {32{cnt[26]}};
// assign KEY1= GPIO_1[1]; Reset Conuter
module EX_3 (GPIO_0 ,GPIO_1 , SW, LEDR, LEDG , CLOCK_27 ,KEY );
input [17:0] SW; // toggle switches
input [7:0] KEY; // Push bottom
input CLOCK_27; //Clock 27MHz , 50Mhz
output [17:0] LEDR; // red LEDS
output [7:0] LEDG; // green LEDs
output [35:0]GPIO_0;
inout [35:0]GPIO_1;
reg [35:0]GPIO_1;
reg [31:0] cnt;
wire KEY0,KEY1;
reg rKEY0,nKEY1;
assign KEY0= GPIO_1[0];
assign KEY1= GPIO_1[1];
always @(posedge CLOCK_27 or negedge KEY1)
begin
if (!KEY1)
cnt<=0;
else
cnt <= cnt + 1;
rKEY0 <= KEY0;
end
always @(posedge CLOCK_27 )
begin
if (KEY0)
GPIO_1[33:2] <=cnt;
else
GPIO_1[33:2] <={32{cnt[26]}};
end
// assign GPIO_1[31:16] = KEY0 ? cnt : {32{cnt[26]}};
assign LEDR[15:0] = GPIO_1[31:16]; //31-16+1=16 {15:0]=18
assign LEDG[3:0] = {4{KEY0}};
assign LEDG[7:4] = {4{KEY1}};
endmodule
沒有留言:
張貼留言