a->b->c->d->e->f->e->d->c->b->a->b....................
// Ch08 pili_1.v
// 七段顯示霹靂燈
module pili_ex1(SW, LEDR, LEDG , CLOCK_50 ,
CLOCK_27 ,KEY ,HEX0 ,HEX1 ,
HEX2,HEX3 ,HEX4,HEX5 ,HEX6,HEX7 );
input [17:0] SW; // toggle switches
input [3:0] KEY; // Push bottom
input CLOCK_27; //Clock 27MHz
input CLOCK_50; //Clock 50Mhz
output [17:0] LEDR; // red LEDS
output [7:0] LEDG; // green LEDs
output [6:0] HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6 ,HEX7; //7-segment display
//set original program input , output
wire sys_clk;
wire rst_n;
reg [3:0] L;
wire HZ_1; //1HZ Clock
reg [7:0] seg;
//assign to DE2-70 hardware
assign sys_clk = CLOCK_50;
assign rst_n = KEY[0];
// reg A,B,C,D,E,F;
//module _1HZ (CLK, RSTn, LED_Out);
_1HZ UUT01
(.CLK(sys_clk),
.RSTn(rst_n),
.LED_Out(HZ_1));
always @(posedge HZ_1 or negedge rst_n )
begin
begin
if(!rst_n)
L[3:0]=0;
else if (L>=4'b1100)
L[3:0]=4'b1;
else
L=L+1'b1;
end
case (L)
// Dot point is always disable
4'b0001 : seg = 8'b1111_1110; //1 = a
4'b0010 : seg = 8'b1111_1101; //2 = b
4'b0011 : seg = 8'b1111_1011; //3 = c
4'b0100 : seg = 8'b1111_0111; //4 = d
4'b0101 : seg = 8'b1110_1111; //5 = e
4'b0110 : seg = 8'b1101_1111; //6 = f
4'b0111 : seg = 8'b1111_1110; //7 = a
4'b1000 : seg = 8'b1101_1111; //8 = f
4'b1001 : seg = 8'b1110_1111; //9 = e
4'b1010 : seg = 8'b1111_0111; //A = d
4'b1011 : seg = 8'b1111_1011; //B = c
4'b1100 : seg = 8'b1111_1101; //C = b
default : seg = 8'b11111111; //OFF
endcase
end
// assign {A,B,C,D,E,F} = L[6:1];
assign HEX0=seg[6:0];
assign HEX1=seg[6:0];
assign HEX2=seg[6:0];
assign HEX3=seg[6:0];
assign HEX4=seg[6:0];
assign HEX5=seg[6:0];
assign HEX6=seg[6:0];
assign HEX7=seg[6:0];
assign LEDG[5:0]=seg[5:0];
endmodule
/*
module pili_1
(Clk,Clr,A,B,C,D,E,F);
input Clk,Clr; // 一位元輸入
output A,B,C,D,E,F; // 一位元輸出
reg [6:0] L; // 宣告為暫存器資料
// 上緣觸發時脈, 上緣同步清除
always@ (posedge Clk)
if (Clr) L = 7'b1000000; // A, 順時針
else if (L == 7'b1000000) L = 7'b0100000; // B, 順時針
else if (L == 7'b0100000) L = 7'b0010000; // C, 順時針
else if (L == 7'b0010000) L = 7'b0001000; // D, 順時針
else if (L == 7'b0001000) L = 7'b0000100; // E, 順時針
else if (L == 7'b0000100) L = 7'b0000010; // F, 順時針
else if (L == 7'b0000010) L = 7'b1000001; // A, 逆時針
else if (L == 7'b1000001) L = 7'b0000011; // F, 逆時針
else if (L == 7'b0000011) L = 7'b0000101; // E, 逆時針
else if (L == 7'b0000101) L = 7'b0001001; // D, 逆時針
else if (L == 7'b0001001) L = 7'b0010001; // C, 逆時針
else if (L == 7'b0010001) L = 7'b0100001; // B, 逆時針
else if (L == 7'b0100001) L = 7'b1000000; // A, 順時針
else L = 7'b0000000; // 不顯示
assign {A,B,C,D,E,F} = L[6:1];
endmodule
*/
//====================================
//Clock input 50MHZ
//====================================
module _1HZ (CLK, RSTn, LED_Out);
input CLK;
input RSTn;
output LED_Out;
/*************************************/
parameter T1S = 24'd50_000_000; //50MHZ
/*************************************/
reg [23:0]Count1;
always @ ( posedge CLK or negedge RSTn )
begin
if( !RSTn )
Count1 <= 24'd0;
else if( Count1 == T1S )
Count1 <= 24'd0;
else
Count1 <= Count1 + 1'b1;
end
/*************************************/
reg rLED_Out;
always @ ( posedge CLK or negedge RSTn )
begin
if( !RSTn )
rLED_Out <= 1'b0;
else if( Count1 >= 24'd0 && Count1 < 24'd25_000_000 )
//0.5sec ON , o.5sec OFF
rLED_Out <= 1'b1;
else
rLED_Out <= 1'b0;
end
/***************************************/
assign LED_Out = rLED_Out;
/***************************************/
endmodule
沒有留言:
張貼留言