{"id":28220421,"url":"https://github.com/septemus/swjtu_computer_organization_exp2_matrixkeyboard","last_synced_at":"2026-02-14T21:02:25.592Z","repository":{"id":152727490,"uuid":"626963906","full_name":"Septemus/swjtu_computer_organization_exp2_matrixkeyboard","owner":"Septemus","description":"西南交通大学计组实验2-矩阵键盘显示电路的设计","archived":false,"fork":false,"pushed_at":"2024-04-09T05:49:51.000Z","size":3285,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"dev02","last_synced_at":"2025-10-09T00:43:40.742Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"VHDL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Septemus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-04-12T14:06:32.000Z","updated_at":"2024-04-25T02:25:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"a6a6a1bd-d6e6-43d8-a1d4-31709e87cd6f","html_url":"https://github.com/Septemus/swjtu_computer_organization_exp2_matrixkeyboard","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Septemus/swjtu_computer_organization_exp2_matrixkeyboard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Septemus%2Fswjtu_computer_organization_exp2_matrixkeyboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Septemus%2Fswjtu_computer_organization_exp2_matrixkeyboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Septemus%2Fswjtu_computer_organization_exp2_matrixkeyboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Septemus%2Fswjtu_computer_organization_exp2_matrixkeyboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Septemus","download_url":"https://codeload.github.com/Septemus/swjtu_computer_organization_exp2_matrixkeyboard/tar.gz/refs/heads/dev02","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Septemus%2Fswjtu_computer_organization_exp2_matrixkeyboard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29455601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-18T04:15:23.126Z","updated_at":"2026-02-14T21:02:25.575Z","avatar_url":"https://github.com/Septemus.png","language":"VHDL","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e # 0 关于\n\n欢迎到我的博客文章查看更多内容😄：\n[https://septemus.github.io/computer_organization_exp2/\n](https://septemus.github.io/computer_organization_exp2/)\n\u003e # 1 实验内容\n\n矩阵键盘值扫描读取及显示电路的设计\n\n\u003e # 2 代码/原理图\n\n\u003e ## 2.1 顶层文件\n\n```Verilog\n\n\nmodule EXP2(\n\tclk,\n\tKEY_R,\n\tKEY_C,\n\tout,\n\tins_num,\n\tcodeout,\n\tsel\n);\n\tinput clk;\n\tinput [3:0] KEY_R;\n\toutput reg[3:0] KEY_C = 4'b0111;\n\toutput reg[31:0] out= 32'h0000_0000;\n\toutput [3:0] ins_num;\n\toutput [6:0] codeout;\n\toutput wire[2:0] sel;\n\treg [31:0]timer = 32'b1;\n\treg [1:0] state_machine = 2'b0;\n\treg valid_input=1;\n//根据按钮的列扫描信号和行输入信号判断按钮是否被按下\nalways  @(posedge clk)\nbegin\n\t\tstate_machine = state_machine + 1'b1;\n\t\tcase (state_machine)\n\t\t\t2'b00:\tKEY_C \u003c= 4'b1110;\n\t\t\t2'b01:\tKEY_C \u003c= 4'b1101;\n\t\t\t2'b10:\tKEY_C \u003c= 4'b1011;\n\t\t\t2'b11:\tKEY_C \u003c= 4'b0111;         \n      endcase\n      valid_input=!(KEY_R == 4'b1111);      \n\t\tbegin\n\t\t\tif(!valid_input)\n\t\t\t\tbegin\n\t\t\t\t\tif(timer == 32'b0)\n\t\t\t\t\tbegin\n\t\t\t\t\t\ttimer = 32'd100001;\n\t\t\t\t\tend\n\t\t\t\t\ttimer = timer + 1'b1;\n\t\t\t\tend\n\t\t\telse if(timer \u003e 32'd100000)\n\t\t\t\tbegin\n\t\t\t\t\ttimer = 32'b1;\n\t\t\t\t\t//置数没有在冷却阶段\n\t\t\t\t\tout=out\u003c\u003c4;\n\t\t\t\t\tout[3:0] = ins_num[3:0];\n\t\t\t\tend\n\t\t\tend\n\t\t\nend\nkey2num k2n(clk,KEY_R,KEY_C,ins_num);\nsegment_displays sg(clk,out,codeout,sel);\nendmodule     \n```\n\u003e ## 2.2 根据键盘按键获得输入的值\n\n```Verilog\nmodule key2num(clk,KEY_R,KEY_C,ins_num);\n\tinput clk;\n\tinput [3:0] KEY_R,KEY_C;\n\toutput reg [3:0] ins_num=0;\n\talways@(*)\n\tcase ({KEY_C, KEY_R})       \n\t\t8'b1011_1110: ins_num = 4'd0;\n\t\t8'b0111_0111: ins_num = 4'd1;\n\t\t8'b1011_0111: ins_num = 4'd2;\n\t\t8'b1101_0111: ins_num = 4'd3;\n\t\t\n\t\t8'b0111_1011: ins_num = 4'd4;\n\t\t8'b1011_1011: ins_num = 4'd5;\n\t\t8'b1101_1011: ins_num = 4'd6;\n\t\t8'b0111_1101: ins_num = 4'd7;  \n\t\t\n\t\t8'b1011_1101: ins_num = 4'd8;\n\t\t8'b1101_1101: ins_num = 4'd9;\n\t\t8'b1110_0111: ins_num = 4'd10;\n\t\t8'b1110_1011: ins_num = 4'd11;  \n\t\t\n\t\t8'b1110_1101: ins_num = 4'd12;\n\t\t8'b1110_1110: ins_num = 4'd13;\n\t\t8'b0111_1110: ins_num = 4'd14;\n\t\t8'b1101_1110: ins_num = 4'd15;  \n   endcase\nendmodule\n\n```\n\n\u003e ## 2.3 7段数码管译码器\n\n```Verilog\nmodule segment_displays(clk,N,seg,sel);\n\tinput clk;\n\tinput [31:0] N;\n\toutput reg [7:0] seg;\n\toutput reg [2:0] sel;\n\treg [3:0]num;\n\talways@(posedge clk)\n\tbegin\n\t\tsel\u003c=sel+1;\n\t\tcase(sel)\n\t\t\t3'b110:num\u003c=N[3:0];\n\t\t\t3'b101:num\u003c=N[7:4];\n\t\t\t3'b100:num\u003c=N[11:8];\n\t\t\t3'b011:num\u003c=N[15:12];\n\t\t\t3'b010:num\u003c=N[19:16];\n\t\t\t3'b001:num\u003c=N[23:20];\n\t\t\t3'b000:num\u003c=N[27:24];\n\t\t\t3'b111:num\u003c=N[31:28];\n\t\tendcase\n\tend\n\talways@(num)\n\tbegin\n\t\tcase(num)\n\t\t\t4'b0000:seg\u003c=8'b00111111;\t//\"0\"\n\t\t\t4'b0001:seg\u003c=8'b00000110;\t//\"1\"\n\t\t\t4'b0010:seg\u003c=8'b01011011;\t//\"2\"\n\t\t\t4'b0011:seg\u003c=8'b01001111;\t//\"3”\n\t\t\t4'b0100:seg\u003c=8'b01100110;\t//\"4\"\n\t\t\t4'b0101:seg\u003c=8'b01101101;\t//\"5\"\n\t\t\t4'b0110:seg\u003c=8'b01111101;\t//\"6\"\n\t\t\t4'b0111:seg\u003c=8'b00000111;\t//\"8\"\n\t\t\t4'b1000:seg\u003c=8'b01111111;\t//\"8\"\n\t\t\t4'b1001:seg\u003c=8'b01101111;\t//\"9\"\n\t\t\t4'b1010:seg\u003c=8'b01110111;\t//\"A\"\n\t\t\t4'b1011:seg\u003c=8'b01111100;\t//\"b\"\n\t\t\t4'b1100:seg\u003c=8'b00111001;\t//\"c\"\n\t\t\t4'b1101:seg\u003c=8'b01011110;\t//\"d\"\n\t\t\t4'b1110:seg\u003c=8'b01111001;\t//\"E\"\n\t\t\t4'b1111:seg\u003c=8'b01110001;\t//\"F\"\n\t\t\tdefault:seg\u003c=8'b00000000;\t//\"dark\"\n\t\tendcase\n\tend\nendmodule\n\n\n```\n\n\u003e ## 2.4 仿真用testbench\n\n```Verilog\n`timescale 1ns/1ns\nmodule exp2_tb;\nreg clk;\nreg [3:0] key_r=4'b0111;\nwire [3:0] key_c,out,ins_num;\nwire [7:0] codeout;\ninitial \nbegin\n\tclk=1'b0;\nend\nalways #50 clk=~clk;\nalways@(posedge clk)\nbegin\n\tcase(key_r)\n\t\t4'b0111:key_r=4'b1011;\n\t\t4'b1011:key_r=4'b1101;\n\t\t4'b1101:key_r=4'b1110;\n\t\t4'b1110:key_r=4'b0111;\n\tendcase\nend\nEXP2 U(\n\t.clk(clk),\n\t.KEY_R(key_r),\n\t.KEY_C(key_c),\n\t.out(out),\n\t.ins_num(ins_num),\n\t.codeout(codeout)\n);\nendmodule\n\n```\n\n\u003e # 3 引脚分配\n\n\u003cimg src=\"/images/pin2.png\" width=\"80%\"\u003e\n\n\u003e # 4 仿真波形\n\n由于设计的防抖模块会造成out和codeout信号延迟输出，此处仅关注ins_num的值\n\n\u003cimg src=\"/images/wvf2.png\" width=\"80%\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseptemus%2Fswjtu_computer_organization_exp2_matrixkeyboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseptemus%2Fswjtu_computer_organization_exp2_matrixkeyboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseptemus%2Fswjtu_computer_organization_exp2_matrixkeyboard/lists"}