2021-06-30

https://www.bilibili.com/video/BV1wy4y1u7RN/
本实验是24秒篮球计时实验
实验设计代码
module digital(TimerH, TimerL, over, Reset,Stop,clk);
output [6:0] TimerH;
output [6:0] TimerL;
output over;
input Reset;
input Stop;
input clk;
wire [1:0]H;
wire [3:0]L;
wire clk_1;
fenpin U0(.clk(clk),.clk_old(clk_1));
basketballtimer U1(over, H[1:0], L[3:0], Reset, Stop, clk_1);
CD4511 U2(TimerH[6:0], {2’b00,H[1:0]});
CD4511 U3(TimerL[6:0], L[3:0]);
endmodule
module fenpin(clk_old,clk);
output clk_old;
input clk;
reg [24:0] count;
reg clk_old;
always @ (posedge clk)
begin
if (count==25’b1_1001_0000_0000_0000_0000_0000)
begin
clk_old<=~clk_old;
count<=0;
end
else
count<=count+1;

end

endmodule

module basketballtimer(Over, TimerH, TimerL, Reset,Stop,clk_1);

output Over;

output [1 :0] TimerH;

output [3:0] TimerL;

input Reset;

input Stop;

input clk_1;

reg [4:0]Q;
assign Over =(Q == 5’d0);
assign TimerH=Q/10;

assign TimerL=Q%10;

always @ (posedge clk_1 or negedge Reset or negedge Stop)

begin

if (~Reset)

Q <=5’d23;

else

begin

if (~Stop)

Q<=Q;

else

begin

if (Q>5’d0)

Q <= Q-1 'b1;

else

Q <=Q;

end

end

end

endmodule

module CD4511(Y,A);

output reg[6:0]Y;

input [3:0]A;

always @ (*)

begin
case (A)

4’d0: Y<=7’b1000_000;
4’d1: Y<=7’b1111_001;
4’d2: Y<=7’b0100_100;
4’d3: Y<=7’b0110_000;
4’d4: Y<=7’b0011_001;
4’d5: Y<=7’b0010_010;
4’d6: Y<=7’b0000_010;
4’d7: Y<=7’b1111_000;
4’d8: Y<=7’b0000_000;
4’d9: Y<=7’b0010_000;

default: Y<=7’b1000_000;
endcase

end

endmodule
测试代码
module tbdigital;
wire [6:0]TimerH;
wire [6:0]TimerL;
wire over;
reg Reset;
reg Stop;
reg clk;
initial
begin
clk=0;
Reset=1;
Stop=1;
#10 Reset=0;
#20 Reset=1;
#200 Stop=0;
#50 Stop=1;
@ (posedge over);
#10 $stop;
end

always #5 clk=~clk;
digital idigital (TimerH, TimerL, over,Reset, Stop, clk);
endmodule

以下是一个更复杂的 SQL 查询语句,它使用了多个子查询和窗口函数: WITH -- 定义一个子查询,获取销售额排名前10的产品 top_products AS ( SELECT product_id, SUM(sales) AS total_sales FROM orders WHERE order_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY product_id ORDER BY total_sales DESC LIMIT 10 ), -- 定义一个子查询,获取销售额排名前10的客户 top_customers AS ( SELECT customer_id, SUM(sales) AS total_sales FROM orders WHERE order_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY customer_id ORDER BY total_sales DESC LIMIT 10 ), -- 定义一个窗口函数,计算每个客户的销售额排名 customer_sales_rank AS ( SELECT customer_id, SUM(sales) AS total_sales, ROW_NUMBER() OVER (ORDER BY SUM(sales) DESC) AS sales_rank FROM orders WHERE order_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY customer_id ) -- 最终查询,获取纽约市销售额排名前10的客户,以及他们购买的销售额排名前10的产品 SELECT customers.id AS customer_id, customers.name AS customer_name, products.id AS product_id, products.name AS product_name, SUM(orders.sales) AS total_sales FROM orders -- 连接顾客信息 INNER JOIN customers ON orders.customer_id = customers.id -- 连接产品信息 INNER JOIN products ON orders.product_id = products.id -- 仅查询纽约市的客户 WHERE customers.city = 'New York' -- 仅查询销售额排名前10的客户 AND customers.id IN (SELECT customer_id FROM top_customers) -- 仅查询销售额排名前10的产品 AND products.id IN (SELECT product_id FROM top_products) -- 仅查询客户销售额排名前10的订单 AND customers.id IN (SELECT customer_id FROM customer_sales_rank WHERE sales_rank <= 10) GROUP BY customers.id, customers.name, products.id, products.name ORDER BY customers.id, total_sales DESC, products.id;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值