module digital_watch(clk, reset,push1,push2,push3,digit,seg,seg_2,led); input clk; input reset; input push1; input push2; input push3; output reg [5:0]digit; output reg [6:0]seg,seg_2; output reg [3:0]led; wire tmp_reset; reg tmp_second_reset; wire tmp_push1; wire tmp_push2; wire tmp_push3; wire tmp_clk_1khz; wire tmp_1sec_mux_in; wire tmp_1min_mux_in; wire tmp_1hour_mux_in; reg tmp_1sec_mux_out; reg tmp_1min_mux_out; reg tmp_1hour_mux_out; wire [2:0] sel; wire [6:0] seg1, seg2, seg3; wire


[3:0]tmp_digit; reg [3:0]tmp_led; wire enable; wire enable_2; reg tmp_enable; reg tmp_enable_2; reg [2:0]tmp_seg_2; decoder_2to4 decoder1(.in(tmp_digit), .out(sel)); mux_2to1 mux1(.sel(sel[0]), .in1(seg1), .in2(seg2), .out(seg)); mux_2to1 mux2(.sel(sel[1]), .in1(seg2), .in2(seg3), .out(seg)); always @(posedge clk) begin if (tmp_reset == 1) begin tmp_second_reset <= 0; tmp_push1 <= 0; tmp_push2 <= 0; tmp_push3 <= 0; end else begin tmp_second_reset <= reset; tmp_push1 <= push1; tmp_push2 <= push2; tmp_push3 <= push3; end end always @(posedge clk) begin if (tmp_reset == 1) begin digit <= 0; end else begin if (tmp_push1 == 1) begin digit <= digit + 1; if (digit > 9) begin digit <= 0; end end end end always @(posedge clk_1khz) begin if (tmp_reset == 1) begin tmp_1sec_mux_out <= 4'b0000; tmp_1min_mux_out <= 4'b0000; tmp_1hour_mux_out <= 4'b0000; end else begin if (tmp_second_reset == 1) begin tmp_1sec_mux_out <= 4'b0000; end else begin tmp_1sec_mux_out <= tmp_1sec_mux_in; end if (tmp_push1 == 1) begin tmp_1min_mux_out <= 4'b0000; end else begin tmp_1min_mux_out <= tmp_1min_mux_in; end if (tmp_push2 == 1) begin tmp_1hour_mux_out <= 4'b0000; end else begin tmp_1hour_mux_out <= tmp_1hour_mux_in; end end end always @(posedge clk) begin if (tmp_reset == 1) begin tmp_1sec_mux_in <= 4'b0000; tmp_1min_mux_in <= 4'b0000; tmp_1hour_mux_in <= 4'b0000; end else begin if (tmp_push1 == 1) begin tmp_1sec_mux_in <= tmp_1sec_mux_in + 1; if (tmp_1sec_mux_in > 9) begin tmp_1sec_mux_in <= 0; end end if (tmp_push2 == 1) begin tmp_1min_mux_in <= tmp_1min_mux_in + 1; if (tmp_1min_mux_in > 9) begin tmp_1min_mux_in <= 0; end end if (tmp_push3 == 1) begin tmp_1hour_mux_in <= tmp_1hour_mux_in + 1; if (tmp_1hour_mux_in > 9) begin tmp_1hour_mux_in <= 0; end end end end always @(posedge clk) begin if (tmp_reset == 1) begin tmp_seg_2 <= 3'b000; tmp_enable <= 1'b0; tmp_led <= 4'b0000; end else begin if (tmp_push1 == 1) begin tmp_seg_2 <= tmp_seg_2 + 1; if (tmp_seg_2 > 4) begin tmp_seg_2 <= 0; end end if (tmp_push2 == 1) begin tmp_enable <= ~tmp_enable; end if (tmp_push3 == 1) begin tmp_led <= tmp_led + 1; if (tmp_led > 9) begin tmp_led <= 0; end end end end assign enable = tmp_enable; binary_counter_1hz counter1(.clk(clk), .reset(tmp_reset), .count(tmp_clk_1khz)); counter_24h counter2(.clk(tmp_clk_1khz), .reset(tmp_second_reset), .count(tmp_1sec_mux_out)); counter_60 counter3(.clk(tmp_clk_1khz), .reset(tmp_second_reset), .count(tmp_1min_mux_out)); counter_12 counter4(.clk(tmp_clk_1khz), .reset(tmp_second_reset), .count(tmp_1hour_mux_out)); always @(posedge clk) begin if (tmp_reset == 1) begin enable_2 <= 0; end else begin if (push2 == 1) begin enable_2 <= ~enable_2; end end end assign tmp_1sec_mux_in = enable_2 ? tmp_second_reset : tmp_1sec_mux_out; always @(posedge clk) begin if (reset == 1) begin seg1 <= 7'b1111111; // displays a "-" seg2 <= 7'b1111111; // displays a "-" seg3 <= 7'b1111111; // displays a "-" end else begin case(tmp_seg_2) 3'b000: begin seg1 <= tmp_1sec_mux_in; seg2 <= tmp_1min_mux_in; seg3 <= tmp_1hour_mux_in; end 3'b001: begin seg1 <= tmp_1min_mux_in; seg2 <= tmp_1hour_mux_in; seg3 <= tmp_1sec_mux_in; end 3'b010: begin seg1 <= tmp_1hour_mux_in; seg2 <= tmp_1sec_mux_in; seg3 <= tmp_1min_mux_in; end default: begin seg1 <= tmp_1sec_mux_in; seg2 <= tmp_1min_mux_in; seg3 <= tmp_1hour_mux_in; end endcase end end assign led = tmp_led; assign seg_2 = tmp_seg_2; assign enable_2 = tmp_enable_2; endmodule [2024-11-15 10:14:41 | AI写代码神器 | 3130点数解答]
- module digital_watch(clk, reset,push1,push2,push3,digit,seg,seg_2,led); input clk; input reset; input push1; input push2; input push3; output reg [5:0]digit; output reg [6:0]seg,seg_2; output reg [3:0]led; wire tmp_reset; reg tmp_second_reset; wire tmp_push1; wire tmp_push2; wire tmp_push3; wire tmp_clk_1khz; wire tmp_1sec_mux_in; wire tmp_1min_mux_in; wire tmp_1hour_mux_in; reg tmp_1sec_mux_out; reg tmp_1min_mux_out; reg tmp_1hour_mux_out; wire [2:0] sel; wire [6:0] seg1, seg2, seg3; wire(36点数解答 | 2024-11-15 10:12:43)173
- module digital_watch(clk, reset,push1,push2,push3,digit,seg,seg_2,led); input clk; input reset; input push1; input push2; input push3; output reg [5:0]digit; output reg [6:0]seg,seg_2; output reg [3:0]led; wire tmp_reset; reg tmp_second_reset; wire tmp_push1; wire tmp_push2; wire tmp_push3; wire tmp_clk_1khz; wire tmp_1sec_mux_in; wire tmp_1min_mux_in; wire tmp_1hour_mux_in; reg tmp_1sec_mux_out; reg tmp_1min_mux_out; reg tmp_1hour_mux_out; wire [2:0] sel; wire [6:0] seg1, seg2, seg3; wire(3130点数解答 | 2024-11-15 10:14:41)155
- module y( clk, rst_n, en_in, in_data, en_out, ou ); input clk; input rst_n; input en_in; input [15:0] in_data; output[7:0] ou; output en_out; /* 根据输入,提取rgb565各分量*/ /* 按公式计算亮度y */ //// y=0.299r+0.587g+0.114b-128(rgb888) //// y=2.460r+2.376g+0.938b-128(rgb565) /*第一步 处理浮点系数,并分别计算2.460r,2.376g,0.938b */ /* 第二步分别计算2.460r+2.376g——0.938b,并生成输出使能 */ /* 第三步 用第二步求和结果-128,得出最终输出数据 */ endmodule(857点数解答 | 2024-06-27 16:53:10)319
- module y( clk, rst_n, en_in, in_data, en_out, out_y ); input clk; input rst_n; input en_in; input [15:0] in_data; output[7:0] out_y; output en_out; /* 根据输入,提取rgb565各分量*/ /* 按公式计算亮度y */ //// y=0.299r+0.587g+0.114b-128(rgb888) //// y=2.460r+2.376g+0.938b-128(rgb565) /*第一步 处理浮点系数,并分别计算2.460r,2.376g,0.938b */ /* 第二步分别计算2.460r+2.376g——0.938b,并生成输出使能 */ /* 第三步 用第二步求和结果-128,得出最终输出数据 */ endmodule(830点数解答 | 2024-06-27 16:54:11)235
- module y( clk, rst_n, en_in, in_data, en_out, ou ); input clk; input rst_n; input en_in; input [15:0] in_data; output[7:0] ou; output en_out; /* 根据输入,提取rgb565各分量*/ /* 按公式计算亮度y */ //// y=0.299r+0.587g+0.114b-128(rgb888) //// y=2.460r+2.376g+0.938b-128(rgb565) /*第一步 处理浮点系数,并分别计算2.460r,2.376g,0.938b */ /* 第二步分别计算2.460r+2.376g——0.938b,并生成输出使能 */ /* 第三步 用第二步求和结果-128,得出最终输出数据 */ endmodule(529点数解答 | 2024-06-27 16:55:38)238
- #include <reg51.h> 3 sbit button=p1^0; 4 sbit led=pl^1; 5 6 bit led_state=0; 7 8日void delay(unsigned int ms){ 9 unsigned int i,j: 10 for(i=ms;i>0;i--) 11 for(j=110;j>0;j--); 12 } 13 14日void main(){ 15 while(1){ 16 白 if (button==0){ 17 delay(20); 18 if (button-=0){ 19 while (button==ah; 20 led state=~led state; 21 led=led state; 22 } 写详细注释(697点数解答 | 2024-10-29 14:54:31)221
- 外部中断 0 由边沿触发,控制 P2 口的 8 个发光二极管依次点亮。C51 程序如下: #include <reg51.h> void ex0_isr() interrupt 0 { static unsigned char led = 0x01; P2 = led; led = (led << 1) | (led >> 7); } void main() { IT0 = 1; EX0 = 1; EA = 1; P2 = 0x01; while(1); } (228点数解答 | 2025-06-22 23:18:42)75
- #include <reg51.h> void ex0_isr() interrupt 0 { static unsigned char led = 0x01; P2 = led; led = (led << 1) | (led >> 7); } void main() { IT0 = 1; EX0 = 1; EA = 1; P2 = 0x01; while(1); }(214点数解答 | 2025-06-22 23:19:09)95
- 循环点亮 led 灯: (1) 使用定时器to 的方式 1,实现 8个 led 由上至下间隔 1s 流动,其中每个 led 亮 0.5s,灭0.5s,一直重复。。 (2) 使用定时器 to 的方式 1,实现 8个 led 逐个点亮,间隔 1s,一直重复。。(1193点数解答 | 2024-12-27 15:10:29)198
- #include<Servo.h> Servo servo_3; void setup(){ servo_3.attach(3); //连接端口; pinMode(A0,INPUT);//dianweiqi pinMode(A1,INPUT);//anjian pinMode(10,OUTPUT); pinMode(6,OUTPUT); pinMode(8,OUTPUT); digitalWrite(10,LOW); servo_3.write(0); analogWrite(5,0); } void loop(){ while(digitalRead(A1)==0){} while(digitalRead(A1)==1){ servo_3.write(30); delay(1000); servo_3.write(150); delay(1000); //digitalWrite(8,HIGH); analogWrite(6,map(A0,0,1023,0,255))(204点数解答 | 2025-03-14 16:42:24)113
- #include <reg51.h> sbit LED = P1^0; sbit KEY = P1^1; void delay(unsigned int ms) { unsigned int i; for(; ms>0; ms--) for(i=0; i<120; i++); } void main() { while(1) { if(KEY == 0) { delay(20); if(KEY == 0) { LED = ~LED; while(KEY == 0); } } } } (326点数解答 | 2025-06-22 23:19:40)99
- 6-4 使用函数统计指定数字的个数 分数 10 作者 zju-mbq 单位 浙江大学 本题要求实现一个统计整数中指定数字的个数的简单函数。 countd(number,digit ) 其中number是整数,digit为[0, 9]区间内的一数字。函数countd应返回number中digit出现的次数。 函数接口定义: countd(number,digit ),返回number中digit出现的次数 裁判测试程序样例: 输入样例: 在一行中输入 10001 0 输出样例: 在另一行输出 3(247点数解答 | 2024-11-14 15:19:47)237