设为首页收藏本站淘宝杂货铺

从F到0 - From F to 0

 找回密码
 注册已关闭
搜索
查看: 192|回复: 0
收起左侧

Quartus Verilog HDL/FPGA 函数实现 取颜色值(),取红色值(),取绿色值(),取蓝色值()

[复制链接]
发表于 2023-3-20 19:41:50 | 显示全部楼层 |阅读模式
main.png
  1. module main(
  2.         input clk,                        //时钟输入
  3.         output reg led                //低电平(计算正确)点亮
  4. );
  5. function [23:0] rgb;                //取颜色值 返回24位宽颜色值
  6.         input [7:0] red;                //8位宽红色值:0~255
  7.         input [7:0] green;        //8位宽绿色值:0~255
  8.         input [7:0] blue;                //8位宽蓝色值:0~255
  9.         begin
  10.                 rgb = {blue,green,red};
  11.         end
  12. endfunction

  13. function [7:0] red;                                //取红色值 返回8位宽
  14.         input [23:0] rgb;                //24位宽颜色值
  15.         begin
  16.                 red = rgb[7:0];
  17.         end
  18. endfunction

  19. function [7:0] green;                        //取绿色值 返回8位宽
  20.         input [23:0] rgb;                //24位宽颜色值
  21.         begin
  22.                 green = rgb[15:8];
  23.         end
  24. endfunction

  25. function [7:0] blue;                        //取蓝色值 返回8位宽
  26.         input [23:0] rgb;                //24位宽颜色值
  27.         begin
  28.                 blue = rgb[23:16];
  29.         end
  30. endfunction
  31. wire [23:0] color = 24'd12345678;

  32. always @(posedge clk) begin
  33.         if(rgb(8'd123,8'd234,8'd101) == 24'd6679163 && red(color) == 8'd78 && green(color) == 8'd97 && blue(color) == 8'd188) begin
  34.                 led <= 1'd0;
  35.         end else begin
  36.                 led <= 1'd1;
  37.         end
  38. end
  39. endmodule
复制代码

相关帖子

您需要登录后才可以回帖 登录 | 注册已关闭

本版积分规则

QQ|手机版|Archiver|从F到0 ( 蒙ICP备17002595号-1 )
蒙公网安备15010402000325号

腾讯云安全认证

GMT+8, 2024-4-20 04:50 , Processed in 0.552031 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表