3178|5

230

帖子

2

TA的资源

纯净的硅(初级)

楼主
 

小梅哥和你一起深入学习FPGA之word文档中加入代码的方法 [复制链接]

相信有很多同学都和小梅哥一样,喜欢把自己的学习经历和技术经验通过文档的方式记录下来,其一可以发布到各大论坛,以和其它同样热爱技术的筒子们交流,其二,也能为自己如后复习滚固留下宝贵的资料。作为码农,我们在写文档时,遇到的最大问题莫过于在文档中添加代码了。直接从各种代码编辑器里面复制出来的代码,加入到word文档中,会丢失原本的排版,关键字的颜色也会丢失,为了使自己文档中的代码在阅读时有原汁原味的编辑器中显示的风格,小梅哥通过网络学习,找到了比较好的方法,这里将方法整理出来,分享给各位。

        这里,为了实现我们的目标,我们只需要一个额外工具,它就是大名鼎鼎的文本编辑软件“NotePad ++”,相信很多人都用过这款软件了,安装包不大,才几M,但是却能够完美打开并编辑各种语言的代码,如C语言、Verilog语言、VHDL 语言等等。需要下载的,可以直接在百度上搜索Notepad ++,即可下载最新版。

        这里,小梅哥已经安装好了软件,因此软件的安装过程就不再详述了,接下来小梅哥就以一个实际的例子来演示如何将代码插入到文档中。

    第一步,找到你需要插入到文档中的代码,这里小梅哥就用我编写的PS2键盘解码的Verilog代码来做演示,找到“PS2_Key_Board_Driver.v”文件,选中它,单击鼠标右键,选择edit with notepad ++,如下图所示:


    打开文档后,软件会默认识别到代码属于哪种编程语言,并进行对应到格式和关键字渲染,效果如下所示:


    熟悉Verilog编程环境的一眼就能看出来,此软件将各种渲染都做的很好,甚至比Quartus II 11.0自带的编辑器渲染效果还要好,完全达到了Quartus II13.0的境界,可见,这个软件对于代码的识别和渲染还是相当到位的。

    如果你的代码因为某种原因,没有被编辑器识别出来,代码则会以全黑显示,出现这种情况也不要紧,我们可以手动设定代码的格式,点击notepad ++ 菜单栏上的“语言”,选择V,在后面的三个选项中选中Verilog即可。如下图所示:



    如此一来,我们就将我们的代码按照我们希望的格式显示了。如果我们希望我们贴进文档的代码前面都有一个行号,方便我们在文档中解说时进行定位,我们还需要进行一个小小的设置,如果没有这个要求,就可以直接跳过这一步。这里,小梅哥还是按照加入行号的方式来进行讲述。

    首先,我们通过按下鼠标左键并拖拽的方式选中我们需要加入行号的这部分代码,如这里,我们代码中,前17行为注释内容,不需要加入到文档中。因此,我将从第18行代码开始,给后续的代码加上行号。将光标定位到第18行代码的开头,点击菜单栏的“编辑”按钮,选择列块编辑选项,如下图所示:



    选中以后,会弹出下图所示的界面,请按照图中的设置参数填写,然后点击确定即可:



    如下图,软件就自动给我们的代码加上了行号了:



    如果你的代码是从顶格开始写的,那么可能会出现行号和代码融合到一起到情况,为了清晰,我们可以先全选代码,然后按键盘上的“Tab”键,将整体代码后移一个制表符的位置,这样再加行号就不会有影响了。行号添加完毕,接下来我们就可以将代码粘贴到文档中来了,我们选中需要粘贴的代码部分,如我这里将行号为01~40的代码粘贴到文档中来,先用鼠标选中这部分代码,然后点击菜单栏中的 “插件”选项,选择“NppExport”,然后选择“copy html toclipboard”即可,如下图所示:



    回到文档中来,直接Ctrl + V就能够粘贴代码了,如下即为粘贴到文档中的代码了:



    怎么样,感觉很方便吧,和在编辑器中看起来没什么差别呢。

    最后,小梅哥再附上本文中用到的完整代码:

PS2_Key_Board_Driver.v

3.59 KB, 下载次数: 16

小梅哥和你一起深入学习FPGA之word文档中加入代码.pdf

568.81 KB, 下载次数: 18

此帖出自FPGA/CPLD论坛

最新回复

工作中实际遇到的问题分享,很赞!  详情 回复 发表于 2016-3-28 09:47
点赞 关注
 

回复
举报

6423

帖子

17

TA的资源

版主

沙发
 
小梅哥有心啦,赞一个
此帖出自FPGA/CPLD论坛
个人签名training
 
 

回复

2721

帖子

0

TA的资源

纯净的硅(中级)

板凳
 
谢谢分享学习一下
此帖出自FPGA/CPLD论坛
 
 
 

回复

5979

帖子

8

TA的资源

版主

4
 
前来点赞
此帖出自FPGA/CPLD论坛
个人签名生活就是油盐酱醋再加一点糖,快活就是一天到晚乐呵呵的忙
===================================
做一个简单的人,踏实而务实,不沉溺幻想,不庸人自扰
 
 
 

回复

6423

帖子

17

TA的资源

版主

5
 
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=GBK">
  5. <title>F:\FPGA\CODE\FPGA纯硬件程序\实战训练20 FPGA片上硬件乘法器的使用\rtl\IIR.v.html</title>
  6. <meta name="Generator" content="Vim/7.4">
  7. <meta name="plugin-version" content="vim7.4_v1">
  8. <meta name="syntax" content="verilog">
  9. <meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy=">
  10. <meta name="colorscheme" content="desert">
  11. <style type="text/css">
  12. <!--
  13. pre { font-family: monospace; color: #ffffff; background-color: #333333; }
  14. body { font-family: monospace; color: #ffffff; background-color: #333333; }
  15. * { font-size: 1em; }
  16. .Statement { color: #f0e68c; font-weight: bold; }
  17. .LineNr { color: #ffff00; }
  18. .Comment { color: #87ceeb; }
  19. .Constant { color: #ffa0a0; }
  20. .Special { color: #ffdead; }
  21. -->
  22. </style>
  23. <script type='text/javascript'>
  24. <!--
  25. /* function to open any folds containing a jumped-to line before jumping to it */
  26. function JumpToLine()
  27. {
  28. var lineNum;
  29. lineNum = window.location.hash;
  30. lineNum = lineNum.substr(1); /* strip off '#' */
  31. if (lineNum.indexOf('L') == -1) {
  32. lineNum = 'L'+lineNum;
  33. }
  34. lineElem = document.getElementById(lineNum);
  35. /* Always jump to new location even if the line was hidden inside a fold, or
  36. * we corrected the raw number to a line ID.
  37. */
  38. if (lineElem) {
  39. lineElem.scrollIntoView(true);
  40. }
  41. return true;
  42. }
  43. if ('onhashchange' in window) {
  44. window.onhashchange = JumpToLine;
  45. }
  46. -->
  47. </script>
  48. </head>
  49. <body onload='JumpToLine();'>
  50. <pre id='vimCodeElement'>
  51. <span id="L1" class="LineNr"> 1 </span><span class="Statement">module</span> <span class="Constant">IIR</span><span class="Special">(</span>clk<span class="Special">,</span>rst_n<span class="Special">,</span>din<span class="Special">,</span>dout<span class="Special">);</span>
  52. <span id="L2" class="LineNr"> 2 </span>
  53. <span id="L3" class="LineNr"> 3 </span> <span class="Statement">input</span> clk<span class="Special">,</span>rst_n <span class="Special">;</span>
  54. <span id="L4" class="LineNr"> 4 </span> <span class="Statement">input</span> <span class="Special">[</span><span class="Constant">12</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> din <span class="Special">;</span>
  55. <span id="L5" class="LineNr"> 5 </span>
  56. <span id="L6" class="LineNr"> 6 </span> <span class="Statement">output</span> <span class="Special">[</span><span class="Constant">12</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> dout <span class="Special">;</span>
  57. <span id="L7" class="LineNr"> 7 </span>
  58. <span id="L8" class="LineNr"> 8 </span> <span class="Statement">reg</span> <span class="Special">[</span><span class="Constant">12</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> x1<span class="Special">,</span>x2<span class="Special">,</span>x3 <span class="Special">;</span>
  59. <span id="L9" class="LineNr"> 9 </span> <span class="Statement">reg</span> <span class="Special">[</span><span class="Constant">12</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> y1<span class="Special">,</span>y2<span class="Special">,</span>y3 <span class="Special">;</span>
  60. <span id="L10" class="LineNr">10 </span> <span class="Statement">reg</span> <span class="Special">[</span><span class="Constant">12</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> q1<span class="Special">,</span>q2<span class="Special">,</span>q3 <span class="Special">;</span>
  61. <span id="L11" class="LineNr">11 </span> <span class="Statement">reg</span> <span class="Special">[</span><span class="Constant">12</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> dout <span class="Special">;</span>
  62. <span id="L12" class="LineNr">12 </span>
  63. <span id="L13" class="LineNr">13 </span> <span class="Statement">wire</span> <span class="Special">[</span><span class="Constant">25</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> sum1_abuf<span class="Special">,</span>sum2_abuf <span class="Special">;</span>
  64. <span id="L14" class="LineNr">14 </span> <span class="Statement">wire</span> <span class="Special">[</span><span class="Constant">12</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> sum1_buf<span class="Special">,</span>sum2_buf <span class="Special">;</span>
  65. <span id="L15" class="LineNr">15 </span> <span class="Statement">wire</span> <span class="Special">[</span><span class="Constant">25</span><span class="Special">:</span><span class="Constant">0</span> <span class="Special">]</span> mul <span class="Special">[</span><span class="Constant">10</span><span class="Special">:</span><span class="Constant">1</span> <span class="Special">]</span> <span class="Special">;</span>
  66. <span id="L16" class="LineNr">16 </span>
  67. <span id="L17" class="LineNr">17 </span><span class="Statement">always</span> <span class="Special">@</span> <span class="Special">(</span> <span class="Statement">posedge</span> clk <span class="Statement">or</span> <span class="Statement">negedge</span> rst_n <span class="Special">)</span>
  68. <span id="L18" class="LineNr">18 </span> <span class="Statement">if</span><span class="Special">(</span> <span class="Special">!</span>rst_n <span class="Special">)</span>
  69. <span id="L19" class="LineNr">19 </span> <span class="Statement">begin</span>
  70. <span id="L20" class="LineNr">20 </span> x1 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span> y1 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span> q1 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span>
  71. <span id="L21" class="LineNr">21 </span> x2 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span> y2 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span> q2 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span>
  72. <span id="L22" class="LineNr">22 </span> x3 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span> y3 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span> q3 <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span>
  73. <span id="L23" class="LineNr">23 </span> <span class="Statement">end</span>
  74. <span id="L24" class="LineNr">24 </span> <span class="Statement">else</span>
  75. <span id="L25" class="LineNr">25 </span> <span class="Statement">begin</span>
  76. <span id="L26" class="LineNr">26 </span> x3 <span class="Special"><=</span> x2 <span class="Special">;</span> x2 <span class="Special"><=</span> x1 <span class="Special">;</span> x1 <span class="Special"><=</span> din <span class="Special">;</span>
  77. <span id="L27" class="LineNr">27 </span> y3 <span class="Special"><=</span> y2 <span class="Special">;</span> y2 <span class="Special"><=</span> y1 <span class="Special">;</span> y1 <span class="Special"><=</span> sum1_buf <span class="Special">;</span>
  78. <span id="L28" class="LineNr">28 </span> q3 <span class="Special"><=</span> q2 <span class="Special">;</span> q2 <span class="Special"><=</span> q1 <span class="Special">;</span> q1 <span class="Special"><=</span> sum2_buf <span class="Special">;</span>
  79. <span id="L29" class="LineNr">29 </span> <span class="Statement">end</span>
  80. <span id="L30" class="LineNr">30 </span>
  81. <span id="L31" class="LineNr">31 </span><span class="Statement">always</span> <span class="Special">@</span> <span class="Special">(</span> <span class="Statement">posedge</span> clk <span class="Statement">or</span> <span class="Statement">negedge</span> rst_n <span class="Special">)</span>
  82. <span id="L32" class="LineNr">32 </span> <span class="Statement">if</span><span class="Special">(</span> <span class="Special">!</span>rst_n <span class="Special">)</span>
  83. <span id="L33" class="LineNr">33 </span> dout <span class="Special"><=</span> <span class="Constant">13'b0</span> <span class="Special">;</span>
  84. <span id="L34" class="LineNr">34 </span> <span class="Statement">else</span>
  85. <span id="L35" class="LineNr">35 </span> dout <span class="Special"><=</span> q1 <span class="Special">;</span>
  86. <span id="L36" class="LineNr">36 </span>
  87. <span id="L37" class="LineNr">37 </span><span class="Comment">//assign sum1_abuf = mul[1] + mul[2] + mul[3] + mul[4] + mul[5] ;</span>
  88. <span id="L38" class="LineNr">38 </span><span class="Comment">//assign sum2_abuf = mul[6] + mul[7] + mul[8] + mul[9] + mul[10] ;</span>
  89. <span id="L39" class="LineNr">39 </span>
  90. <span id="L40" class="LineNr">40 </span><span class="Statement">assign</span> sum1_abuf <span class="Special">=</span> mul<span class="Special">[</span><span class="Constant">1</span><span class="Special">]</span> <span class="Special">+</span> mul<span class="Special">[</span><span class="Constant">5</span><span class="Special">]</span> <span class="Special">;</span>
  91. <span id="L41" class="LineNr">41 </span><span class="Statement">assign</span> sum2_abuf <span class="Special">=</span> mul<span class="Special">[</span><span class="Constant">6</span><span class="Special">]</span> <span class="Special">+</span> mul<span class="Special">[</span><span class="Constant">10</span><span class="Special">]</span> <span class="Special">;</span>
  92. <span id="L42" class="LineNr">42 </span>
  93. <span id="L43" class="LineNr">43 </span>
  94. <span id="L44" class="LineNr">44 </span><span class="Statement">assign</span> sum1_buf <span class="Special">=</span> sum1_abuf<span class="Special">[</span><span class="Constant">25</span><span class="Special">:</span><span class="Constant">13</span><span class="Special">]</span> <span class="Special">;</span>
  95. <span id="L45" class="LineNr">45 </span><span class="Statement">assign</span> sum2_buf <span class="Special">=</span> sum2_abuf<span class="Special">[</span><span class="Constant">25</span><span class="Special">:</span><span class="Constant">13</span><span class="Special">]</span> <span class="Special">;</span>
  96. <span id="L46" class="LineNr">46 </span>
  97. <span id="L47" class="LineNr">47 </span>multiply m0 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>x1<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">1</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  98. <span id="L48" class="LineNr">48 </span>multiply m1 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>x2<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">2</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  99. <span id="L49" class="LineNr">49 </span>multiply m2 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>x3<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">3</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  100. <span id="L50" class="LineNr">50 </span>multiply m3 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>y1<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">4</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  101. <span id="L51" class="LineNr">51 </span>multiply m4 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>y2<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">5</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  102. <span id="L52" class="LineNr">52 </span>multiply m5 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>y1<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">6</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  103. <span id="L53" class="LineNr">53 </span>multiply m6 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>y2<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">7</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  104. <span id="L54" class="LineNr">54 </span>multiply m7 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>y3<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">8</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  105. <span id="L55" class="LineNr">55 </span>multiply m8 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>q1<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">9</span><span class="Special">]</span> <span class="Special">)</span> <span class="Special">);</span>
  106. <span id="L56" class="LineNr">56 </span>multiply m9 <span class="Special">(</span> <span class="Special">.</span>clk<span class="Special">(</span>clk<span class="Special">),.</span>a<span class="Special">(</span>q2<span class="Special">),.</span>o<span class="Special">(</span>mul<span class="Special">[</span><span class="Constant">10</span><span class="Special">])</span> <span class="Special">);</span>
  107. <span id="L57" class="LineNr">57 </span>
  108. <span id="L58" class="LineNr">58 </span><span class="Statement">endmodule</span>
  109. </pre>
  110. </body>
  111. </html>
  112. <!-- vim: set foldmethod=manual : -->
复制代码
此帖出自FPGA/CPLD论坛
个人签名training
 
 
 

回复

2万

帖子

74

TA的资源

管理员

6
 
工作中实际遇到的问题分享,很赞!
此帖出自FPGA/CPLD论坛
加EE小助手好友,
入技术交流群
EE服务号
精彩活动e手掌握
EE订阅号
热门资讯e网打尽
聚焦汽车电子软硬件开发
认真关注技术本身
个人签名

加油!在电子行业默默贡献自己的力量!:)

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表