{"id":1027,"date":"2018-09-20T03:50:55","date_gmt":"2018-09-20T03:50:55","guid":{"rendered":""},"modified":"2018-09-20T11:51:24","modified_gmt":"2018-09-20T03:51:24","slug":"fpga%e5%ad%a6%e4%b9%a0%e7%b3%bb%e5%88%97%ef%bc%9a32.+%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e4%ba%8c%e8%bf%9b%e5%88%b6%e8%bd%ac%e5%8d%81%e8%bf%9b%e5%88%b6%e7%9a%84%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"http:\/\/www.szryc.com\/?p=1027","title":{"rendered":"FPGA\u5b66\u4e60\u7cfb\u5217\uff1a32. \u5982\u4f55\u5b9e\u73b0\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236\u7684\u8bbe\u8ba1"},"content":{"rendered":"

\n\t\u8bbe\u8ba1\u80cc\u666f\uff1a<\/strong><\/p>\n

\n\t\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236\u5728\u8bbe\u8ba1\u5e94\u7528\u4e2d\u5341\u5206\u7684\u5e7f\u6cdb\u3002\u5c24\u5176\u5728AD\u8f6c\u5316\u4e2d\u662f\u5fc5\u987b\u6240\u7528\u5230\u7684\u4e00\u4e2a\u5c0f\u77e5\u8bc6\u70b9\uff0c\u5b66\u4e60\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236\u7684\u65b9\u6cd5\u663e\u7684\u975e\u5e38\u7684\u91cd\u8981\u3002\u4eca\u5929\u5c31\u548c\u7b14\u8005\u6765\u5b66\u4e60\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236\u7684\u65b9\u6cd5\uff0c\u901a\u8fc7\u7b80\u5355\u7684\u5b66\u4e60\u6765\u638c\u63e1\u8fd9\u4e48\u4e00\u95e8\u77e5\u8bc6\u3002<\/span><\/p>\n

\n\t <\/div>\n

\n\t\u8bbe\u8ba1\u539f\u7406:<\/strong><\/p>\n

\n\t\u672c\u6b21\u7684\u8bbe\u8ba1\u4e3b\u8981\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4e8c\u9009\u4e00\u6570\u636e\u9009\u62e9\u5668\uff0c\u6211\u4eec\u7684\u8bbe\u8ba1\u4e3b<\/span><\/p>\n

\n\t\u4e8c\u8fdb\u5236\u4e2d\u53ea\u6709 0 \u548c 1 \u4e24\u4e2a\u72b6\u6001\uff0c\u53ef\u4ee5\u8868\u793a 0\u30011 \u4e24\u79cd\u72b6\u6001\u7684\u7535 \u5b50\u5668\u4ef6\u5f88\u591a\uff0c\u5982\u5f00\u5173\u7684\u63a5\u901a\u548c\u65ad\u5f00\uff0c\u6676\u4f53\u7ba1<\/u>\u7684\u5bfc\u901a\u548c\u622a\u6b62\u3001\u78c1\u5143 \u4ef6\u7684\u6b63\u8d1f\u5269\u78c1\u3001\u7535\u4f4d\u7535\u5e73\u7684\u4f4e\u4e0e\u9ad8\u7b49\u90fd\u53ef\u8868\u793a 0\u30011 \u4e24\u4e2a\u6570\u7801\u3002\u4f7f \u7528\u4e8c\u8fdb\u5236\uff0c\u7535\u5b50\u5668\u4ef6\u5177\u6709\u5b9e\u73b0\u7684\u53ef\u884c\u6027\u3002<\/span><\/p>\n

\n\t\u4e8c\u8fdb\u5236\u6570\u7684\u8fd0\u7b97\u6cd5\u5219\u5c11\uff0c\u8fd0\u7b97\u7b80<\/span>\u5355\uff0c\u4f7f\u8ba1\u7b97\u673a\u8fd0\u7b97\u5668\u7684\u786c\u4ef6\u7ed3 \u6784\u5927\u5927\u7b80\u5316\u3002\u7531\u4e8e\u4e8c\u8fdb\u5236 0 \u548c 1 \u6b63\u597d\u548c\u903b\u8f91\u4ee3\u6570\u7684\u5047\uff08false\uff09\u548c \u771f\uff08true\uff09\u76f8\u5bf9\u5e94\uff0c\u6709\u903b\u8f91\u4ee3\u6570\u7684\u7406\u8bba\u57fa\u7840\uff0c\u7528\u4e8c\u8fdb\u5236\u8868\u793a\u4e8c\u503c \u903b\u8f91\u5f88\u81ea\u7136\u3002\u7535\u5b50\u5668\u4ef6\u4e2d\uff0c\u6240\u6709\u7684\u6570\u636e\u90fd\u662f\u7528\u4e8c\u8fdb\u5236\u6765\u8868\u793a\u7684\u3002<\/span><\/span><\/p>\n

\n\t2.<\/span> BCD<\/span> \u7801<\/span><\/span><\/p>\n

\n\tBCD \u7801\uff08Binary-Coded Decimal\uff09\u4ea6\u79f0\u4e8c\u8fdb\u7801\u5341\u8fdb\u6570\u6216\u4e8c-\u5341\u8fdb\u5236\u4ee3\u7801\u3002\u7528<\/span> 4<\/span> \u4f4d\u4e8c\u8fdb\u5236\u6570\u6765\u8868\u793a<\/span> 1<\/span> \u4f4d\u5341\u8fdb\u5236\u6570\u4e2d\u7684<\/span> 0~9<\/span> \u8fd9<\/span> 10<\/span> \u4e2a \u6570\u7801\u3002BCD <\/span>\u7801\u662f\u4e00\u79cd\u4e8c\u8fdb\u5236\u7684\u6570\u5b57\u7f16\u7801\u5f62\u5f0f\uff0c\u7528\u4e8c\u8fdb\u5236\u7f16\u7801\u7684\u5341 <\/span>\u8fdb\u5236\u4ee3\u7801\u3002BCD <\/span>\u7801\u8fd9\u79cd\u7f16\u7801\u5f62\u5f0f\u5229\u7528\u4e86\u56db\u4e2a\u4f4d\u5143\u6765\u50a8\u5b58\u4e00\u4e2a\u5341\u8fdb <\/span>\u5236\u7684\u6570\u7801\uff0c\u4f7f\u4e8c\u8fdb\u5236\u548c\u5341\u8fdb\u5236\u4e4b\u95f4\u7684\u8f6c\u6362\u5f97\u4ee5\u5feb\u6377\u7684\u8fdb\u884c\u3002<\/span><\/span><\/p>\n

\n\t        3.<\/span> \u5b9e\u73b0\u65b9\u6cd5<\/span><\/span><\/p>\n

\n\t           1)<\/span> \u5bf9<\/span> 10<\/span> \u6c42\u4f59\u6cd5<\/span><\/span><\/p>\n

\n\t         \u5c06\u9700\u8981<\/span>\u8f6c<\/span>\u6362\u7684<\/span>\u6570<\/span>\u5b57\u9664<\/span>\u4ee5<\/span>“<\/span>\u6743<\/span>”<\/span>\uff0c<\/span>\u7136\u540e\u5bf9<\/span> 1<\/span>0<\/span> \u6c42\u4f59<\/span>\uff0c<\/span>\u5f97\u51fa\u6570<\/span>\u5b57<\/span>\u5404\u4e2a \u4f4d\u4e0a\u7684<\/span>\u6570<\/span>\u5b57\u3002<\/span>\u4f8b<\/span>\u5982<\/span>\uff1a<\/span>8<\/span>&rs<\/u>quo;<\/span>b1000<\/span>_<\/span>0000<\/span>\uff081<\/span>0<\/span> \u8fdb<\/span>\u5236<\/span>\u4e2d\u7684<\/span> 1<\/span>28<\/span>\uff09<\/span>\uff0c<\/span>\u5c06\u6b64\u6570 \u5b57\u5bf9<\/span> 10<\/span> \u6c42<\/span>\u4f59\uff0c<\/span>\u5f97<\/span>\u51fa<\/span>\u4e2a<\/span>\u4f4d<\/span>“8<\/span>”<\/span>\uff0c<\/span>\u7136<\/span>\u540e<\/span>\u5c06<\/span>“8”\u8d4b<\/span>\u7ed9<\/span>\u6700\u4f4e\u7684<\/span> 4<\/span> \u4f4d<\/span>\u3002<\/span>\u5c06 \u6b64\u6570\u5b57\uff08<\/span>1<\/span>28\uff09<\/span>\u9664<\/span>\u4ee5<\/span> 10<\/span>\uff0c<\/span>\u5f97\u51fa<\/span> 1<\/span>2<\/span>\uff08\u5728<\/span> F<\/span>P<\/span>GA<\/span> \u8ba1\u7b97<\/span>\u4e2d<\/span>\uff0c\u81ea<\/span>\u52a8<\/span>\u53d6\u6574<\/span>\uff09<\/span>\uff0c \u5bf9<\/span> 10<\/span> \u6c42<\/span>\u4f59<\/span>\uff0c\u7136<\/span>\u540e<\/span>\u5f97\u51fa<\/span>\u5341<\/span>\u4f4d“2<\/span>”<\/span>\uff0c<\/span>\u628a“<\/span>2<\/span>”\u8d4b\u7ed9<\/span>\u6b21<\/span>\u4f4e\u7684<\/span> 4<\/span> \u4f4d<\/span>\u3002\u5c06\u6b64 \u6570\u5b57\uff0812<\/span>8<\/span>\uff09\u9664\u4ee5<\/span> 10<\/span>0<\/span>\uff0c\u5f97\u51fa<\/span> 1<\/span>\uff0c\u5bf9<\/span> 10<\/span> \u6c42<\/span>\u4f59\uff0c\u7136<\/span>\u540e<\/span>\u5f97\u51fa<\/span>\u767e<\/span>\u4f4d“1<\/span>”<\/span>\uff0c <\/span>\u628a“1”\u8d4b\u7ed9\u53e6\u5916\u7684<\/span> 4<\/span> \u4f4d\u3002\u8fd9\u6837\u5c31\u8f6c\u6362\u51fa\u4e86<\/span> BCD<\/span> \u7801\u3002<\/span><\/span><\/p>\n

\n\t        \u8fd9\u7c7b\u65b9\u6cd5\u4e2d\uff0c\u5229\u7528\u4e86\u5927\u91cf\u7684\u9664\u6cd5\u548c\u6c42\u4f59\uff0c\u5360\u7528\u4e86\u5927\u91cf\u7684\u903b\u8f91\u8d44 \u6e90\u3002\u4f46\u662f\uff0c\u5b9e\u73b0\u6bd4\u8f83\u7b80\u5355\uff0c\u5982\u679c\u82af\u7247\u7684\u903b\u8f91\u8d44\u6e90\u8db3\u591f\u7684\u8bdd\uff0c\u53ef\u4ee5 <\/span>\u91c7\u53d6\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u3002<\/span><\/span><\/p>\n

\n\t        2)<\/span> \u5927\u56db\u52a0\u4e09\u6cd5<\/span><\/span><\/p>\n

\n\t<\/span><\/p>\n

\n\t\u8fdb\u884c\u79fb\u4f4d\uff0c\u7136\u540e\u8fdb\u884c\u5224\u65ad\u3002\u5982\u679c\u5927\u4e8e\u56db\uff0c\u5219\u52a0\u4e09\u3002\u6700\u540e\u5f97\u51fa\u6211<\/span>\u4eec\u60f3\u8981\u7684<\/span> BCD<\/span> \u7801<\/span>\uff08\u4e0b<\/span>\u8ff0<\/span>\u662f\u6309<\/span>\u7167<\/span>\u8f6c\u6362<\/span> 7<\/span> \u4f4d<\/span>\u8bb2\u89e3\u7684<\/span>\u539f<\/span>\u7406<\/span>\uff09<\/span>\u3002<\/span><\/span><\/span><\/span><\/p>\n

\n\t<\/p>\n

\n\t<\/p>\n

\n\t                <\/strong><\/p>\n

\n\t\u67b6\u6784\u56fe\u5982\u4e0b<\/strong><\/p>\n

\n\t<\/p>\n

\n\tbin_data[7:0]:\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u3002<\/p>\n

\n\tbin_data[11:0]:\u8f93\u51fa\u7684BCD\u7801\uff08\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u4e3a8\u4f4d\uff0c\u6700\u5927 \u4e3a8’b1111_1111(255),\u6bcf\u56db\u4f4d\u4e8c\u8fdb\u5236\u8868\u793a\u4e00\u4e2aBCD\u7801\uff0c\u6545\u800c12\u4f4d\uff09\u3002<\/p>\n

\n\t\u8bbe\u8ba1\u4ee3\u7801:<\/strong><\/p>\n

\n\t\u8bbe\u8ba1\u6a21\u5757<\/span><\/p>\n

\n\tmodule bin_to_bcd(bin, bcd);<\/span><\/p>\n

\n\tinput [7:0] bin;<\/span><\/p>\n

\n\toutput [11:0] bcd;<\/span><\/p>\n

\n\twire [19:0] shift_reg [5:0];<\/span><\/p>\n

\n\tassign shift_reg[5] = {9'b0,bin,3'b0};<\/span><\/p>\n

\n\tbcd_modify u1(.bcd_in(shift_reg[5]), .bcd_out(shift_reg[4]));<\/span><\/p>\n

\n\tbcd_modify u2(.bcd_in(shift_reg[4]), .bcd_out(shift_reg[3]));<\/span><\/p>\n

\n\tbcd_modify u3(.bcd_in(shift_reg[3]), .bcd_out(shift_reg[2]));<\/span><\/p>\n

\n\tbcd_modify u4(.bcd_in(shift_reg[2]), .bcd_out(shift_reg[1]));<\/span><\/p>\n

\n\tbcd_modify u5(.bcd_in(shift_reg[1]), .bcd_out(shift_reg[0]));<\/span><\/p>\n

\n\tassign bcd = shift_reg[0][19:8];<\/span><\/p>\n

\n\tendmodule<\/span><\/p>\n

\n\tmodule bcd_modify(bcd_in, bcd_out);<\/span><\/p>\n

\n\tinput [19:0] bcd_in;<\/span><\/p>\n

\n\toutput [19:0] bcd_out;<\/span><\/p>\n

\n\twire [19:0] bcd_reg;<\/span><\/p>\n

\n\tbcd_sigle_modify u1(.bcd_in(bcd_in[19:16]), .bcd_out(bcd_reg[19:16]));<\/span><\/p>\n

\n\tbcd_sigle_modify u2(.bcd_in(bcd_in[15:12]), .bcd_out(bcd_reg[15:12]));<\/span><\/p>\n

\n\tbcd_sigle_modify u3(.bcd_in(bcd_in[11:8]), .bcd_out(bcd_reg[11:8]));<\/span><\/p>\n

\n\tassign bcd_reg[7:0] = bcd_in[7:0];<\/span><\/p>\n

\n\tassign bcd_out = {bcd_reg[18:0],1'b0};<\/span><\/p>\n

\n\tendmodule<\/span><\/p>\n

\n\tmodule bcd_sigle_modify(bcd_in, bcd_out);<\/span><\/p>\n

\n\tinput [3:0] bcd_in;<\/span><\/p>\n

\n\toutput reg [3:0] bcd_out;<\/span><\/p>\n

\n\talways @ (*)<\/span><\/p>\n

\n\tbegin<\/span><\/p>\n

\n\tif (bcd_in > 4)<\/span><\/p>\n

\n\tbcd_out = bcd_in + 3;<\/span><\/p>\n

\n\telse<\/span><\/p>\n

\n\tbcd_out = bcd_in;<\/span><\/p>\n

\n\tend<\/span><\/p>\n

\n\tendmodule<\/span><\/p>\n

\n\t\u6d4b\u8bd5\u6a21\u5757<\/span><\/p>\n

\n\t`ti<\/u>mescale 1ns\/1ps<\/span><\/p>\n

\n\tmodule tb();<\/span><\/p>\n

\n\treg [7:0] bin;<\/span><\/p>\n

\n\twire [11:0] bcd;<\/span><\/p>\n

\n\tinitial begin<\/span><\/p>\n

\n\tbin = 255;<\/span><\/p>\n

\n\t#500 bin = 20;<\/span><\/p>\n

\n\t#500 bin = 125;<\/span><\/p>\n

\n\t#500 $stop;<\/span><\/p>\n

\n\tend<\/span><\/p>\n

\n\tbin_to_bcd bin_to_bcd_dut(<\/span><\/p>\n

\n\t.bin(bin),<\/span><\/p>\n

\n\t.bcd(bcd)<\/span><\/p>\n

\n\t);<\/span><\/p>\n

\n\tendmodule<\/span><\/p>\n

\n\t\u4eff\u771f\u56fe:<\/strong><\/p>\n

\n\t<\/p>\n

\n\t\u4ece\u4eff\u771f\u4e2d\u53ef\u4ee5\u770b\u51fa\u672c\u6b21\u8bbe\u8ba1\u7684\u6b63\u786e\u6027\uff0c\u6d4b\u8bd5\u4e2d\u6211\u4eec\u8f93\u51fa\u7684\u4e8c\u8fdb\u5236\u548c\u4e3a8\u4e2a1\u4e5f\u5c31\u662f255\uff0c\u8f6c\u5316\u4e3a10\u8fdb\u5236\u540e \u630916\u8fdb\u5236\u663e\u793a\uff0c\u4e5f\u5c31\u662f255\uff0c\u901a\u8fc7\u9a8c\u8bc1\u8bbe\u8ba1\u6b63\u786e\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

\u8bbe\u8ba1\u80cc\u666f\uff1a \u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236\u5728\u8bbe\u8ba1\u5e94\u7528\u4e2d\u5341\u5206\u7684\u5e7f\u6cdb\u3002\u5c24\u5176\u5728AD\u8f6c\u5316\u4e2d\u662f\u5fc5\u987b\u6240\u7528\u5230\u7684\u4e00\u4e2a\u5c0f\u77e5\u8bc6\u70b9\uff0c\u5b66\u4e60\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236\u7684\u65b9\u6cd5\u663e\u7684\u975e\u5e38\u7684\u91cd\u8981\u3002\u4eca\u5929\u5c31\u548c\u7b14\u8005\u6765\u5b66\u4e60\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/1027"}],"collection":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1027"}],"version-history":[{"count":0,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/1027\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1027"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}