正如上所述,我们小脚丫FPGA板上有8颗LED和2颗3色LED,总计8+6=14颗,我们通过逻辑让某些灯亮,某些灯灭,看看代码如何写,实际的效果如何? 比如:
再上一个案例的基础上,进一步体会Verilog代码的语法结构 - 向量及注释。
在这个示例中用到了8个分立的LED,在Verilog中以向量(类似C中的数组)的方式来表示,另外两个RGB三色LED分开描述,以进行对比。
代码如下:
module one_led_on(led, led_r1, led_g1, led_b1, led_r2, led_g2, led_b2); output [8:1] led; // define 8 led signals to be output output led_r1, led_g1, led_b1; output led_r2, led_g2, led_b2; assign led_r1=1'b1; // set signal of this pin = 1 to turn off the led connected to this pin assign led_g1=1'b0; // make the green led on assign led_b1=1'b1; assign led_r2=1'b1; assign led_g2=1'b1; assign led_b2=1'b0; // make the blue led on assign led = 8'b01001100; // set bit 8, 6, 5, 2, 1 = 0 to make led 8, 6, 5, 2, 1 on endmodule
Verilog语法说明: