原创 一些简单的Verilog代码

2007-4-26 20:25 8494 8 9 分类: FPGA/CPLD

一、


//Simple module that connect sthe SW switches to the LEDR lights
module part1(SW,LEDR);
  input [17:0] SW;//toggleswitches
output[17:0]LEDR;//redLEDs
assignLEDR=SW;
endmodule


二、


点击看大图


// Implements eight 2-to-1 multiplexers.
// inputs:  SW7-0 represent the 8-bit input X, and SW15-8 represent Y
//            SW17 selects either X or Y to drive the output LEDs
// outputs:  LEDR17-0 show the states of the switches
//               LEDG7-0 shows the outputs of the multiplexers
module part2 (SW, LEDR, LEDG);
   input [17:0] SW;         // toggle switches
   output [17:0] LEDR;   // red LEDs
   output [7:0] LEDG;    // green LEDs


   wire Sel;
   wire [7:0] X, Y, M;


   assign  LEDR = SW;
   assign  X        = SW[7:0];
   assign  Y        = SW[15:8];
   assign  Sel      = SW[17];


   assign M[0] = (~Sel & X[0]) | (Sel & Y[0]);
   assign M[1] = (~Sel & X[1]) | (Sel & Y[1]);
   assign M[2] = (~Sel & X[2]) | (Sel & Y[2]);
   assign M[3] = (~Sel & X[3]) | (Sel & Y[3]);
   assign M[4] = (~Sel & X[4]) | (Sel & Y[4]);
   assign M[5] = (~Sel & X[5]) | (Sel & Y[5]);
   assign M[6] = (~Sel & X[6]) | (Sel & Y[6]);
   assign M[7] = (~Sel & X[7]) | (Sel & Y[7]);
   assign LEDG[7:0] = M;
endmodule


三、


点击看大图点击看大图


// Implements a 3-bit wide 5-to-1 multiplexer.
// inputs: SW14-0 represent data in 5 groups, U-Y
//           SW17-15 selects one group from U to Y
// outputs: LEDR17-0 show the states of the switches
//             LEDG2-0 displays the selected group
module part3 (SW, LEDR, LEDG);
   input [17:0] SW;    // toggle switches
   output [17:0] LEDR;   // red LEDs
   output [2:0] LEDG;   // green LEDs


   wire [1:3] m_0, m_1, m_2; // m_0 is used for 3 intermediate multiplexers 
                                             // to produce the 5-to-1 multiplexer M[0], m_1 is for
                                            // M[1], and m_2 is for M[2]
   wire [2:0] S, U, V, W, X, Y, M; // M is the 3-bit 5-to-1 multiplexer


   assign S[2:0] = SW[17:15];
   assign U = SW[2:0];
   assign V = SW[5:3];
   assign W = SW[8:6];
   assign X = SW[11:9];
   assign Y = SW[14:12];


   assign LEDR = SW;


   // 5-to-1 multiplexer for bit 0
   assign m_0[1] = (~S[0] & U[0]) | (S[0] & V[0]);
   assign m_0[2] = (~S[0] & W[0]) | (S[0] & X[0]);
   assign m_0[3] = (~S[1] & m_0[1]) | (S[1] & m_0[2]);
   assign M[0] = (~S[2] & m_0[3]) | (S[2] & Y[0]); // 5-to-1 multiplexer output


   // 5-to-1 multiplexer for bit 1
   assign m_1[1] = (~S[0] & U[1]) | (S[0] & V[1]);
   assign m_1[2] = (~S[0] & W[1]) | (S[0] & X[1]);
   assign m_1[3] = (~S[1] & m_1[1]) | (S[1] & m_1[2]);
   assign M[1] = (~S[2] & m_1[3]) | (S[2] & Y[1]); // 5-to-1 multiplexer output
 
  // 5-to-1 multiplexer for bit 2
   assign m_2[1] = (~S[0] & U[2]) | (S[0] & V[2]);
   assign m_2[2] = (~S[0] & W[2]) | (S[0] & X[2]);
   assign m_2[3] = (~S[1] & m_2[1]) | (S[1] & m_2[2]);
   assign M[2] = (~S[2] & m_2[3]) | (S[2] & Y[2]); // 5-to-1 multiplexer output
 
   assign LEDG[2:0] = M;
endmodule


四、


点击看大图


// Implements a circuit that can display five characters on a 7-segment
// display.
// inputs: SW2-0 selects the letter to display. The characters are:
//  SW 2 1 0  Char
//  ----------------
//     0 0 0   'H'
//   0 0 1  'E'
//   0 1 0  'L'
//   0 1 1  'O'
//   1 0 0  ' ' Blank
//   1 0 1  ' ' Blank
//   1 1 0  ' ' Blank
//   1 1 1  ' ' Blank
//
// outputs: LEDR2-0 show the states of the switches
//    HEX0 displays the selected character
module part4 (SW, LEDR, HEX0);
   input [2:0] SW;    // toggle switches
   output [2:0] LEDR;   // red LEDs
   output [0:6] HEX0;   // 7-seg display


   wire [2:0] C;


   assign LEDR = SW;
   assign C[2:0] = SW[2:0];


 /*
  *       0 
  *      --- 
  *     |   |
  *    5|   |1
  *     | 6 |
  *      --- 
  *     |   |
  *    4|   |2
  *     |   |
  *      --- 
  *       3 
  */
 // the following equations describe HEX0[0-6] in cannonical SOP form
   assign HEX0[0] = ~((~C[2] & ~C[1] & C[0]) | (~C[2] & C[1] & C[0]));
   assign HEX0[1] = ~((~C[2] & ~C[1] & ~C[0]) | (~C[2] & C[1] & C[0]));
   assign HEX0[2] = ~((~C[2] & ~C[1] & ~C[0]) | (~C[2] & C[1] & C[0]));
   assign HEX0[3] = ~((~C[2] & ~C[1] & C[0]) | (~C[2] & C[1] & ~C[0]) |
                               (~C[2] & C[1] & C[0]));
   assign HEX0[4] = ~((~C[2] & ~C[1] & ~C[0]) | (~C[2] & ~C[1] & C[0]) |
                               (~C[2] & C[1] & ~C[0]) | (~C[2] & C[1] & C[0]));
   assign HEX0[5] = ~((~C[2] & ~C[1] & ~C[0]) | (~C[2] & ~C[1] & C[0]) |
                               (~C[2] & C[1] & ~C[0]) | (~C[2] & C[1] & C[0]));
   assign HEX0[6] = ~((~C[2] & ~C[1] & ~C[0]) | (~C[2] & ~C[1] & C[0]));
endmodule


 


 


 

文章评论1条评论)

登录后参与讨论

用户45450 2007-10-1 05:49

thanx!!!

相关推荐阅读
用户478270 2007-11-26 15:03
Visual C++中使用gotoxy() / clrscr()等函数
#include < windows.h >void clrscr(void);void clreol(void);void clreoscr(void);void gotoxy(int ...
用户478270 2007-11-15 11:38
putchar()、getch()、getche()和getchar()函数
getch()、getche()和getchar()函数     (1) getch()和getche()函数     这两个函数都是从键盘上读入一个字符。其调用格式为:      getch(); ...
用户478270 2007-11-06 21:10
VM TOOLS安装
以ROOT身份进入Redhat linux9.0以后,会发现我们并没有真正的安装上了VMWARE TOOLS软件包,这个时候需要点击“虚拟”--》“安装虚拟工具”, mount /dev/cdrom ...
用户478270 2007-11-03 16:49
用全加器实现逻辑函数
瑞芯微电子的一道笔试题f(x1,x2,x3) = E(0,2,3,5,6,7) 试用全加器实现。 在网上搜到一篇论文讲的挺全,上传共享。但还是有点没看明白,感觉技巧性太强。...
用户478270 2007-10-18 23:01
Latchup现象和预防措施
Latch up 最易产生在易受外部干扰的I/O电路处, 也偶尔发生在内部电路Latch up 是指cmos晶片中, 在电源power VDD和地线GND(VSS)之间由于寄生的PNP和NPN双极性B...
用户478270 2007-10-18 16:42
N沟道增强型MOS管的工作原理
N沟道增强型MOS管的工作原理1.vGS对iD及沟道的控制作用<?XML:NAMESPACE PREFIX = V /><?XML:NAMESPACE PREFIX = O />...
我要评论
1
8
关闭 站长推荐上一条 /2 下一条