找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2218|回复: 0
打印 上一主题 下一主题
收起左侧

Tablet counting system verilog code

[复制链接]
跳转到指定楼层
楼主
Hex keypad or tablet counting system


源程序如下:
  1. //##################################################################
  2. /*
  3. Project/Module        : Assignment
  4. File name        : HexKeyCodeGenerator.v
  5. Version                : 1-0
  6. Date created        : 25 Aug 2017
  7. Author                : Vimalraj Kasivisvanathan
  8. Code type        : Verilog
  9. Description        : Verilog code for HexKeypad
  10. */
  11. //##################################################################

  12. //`default_nettype none

  13. module HEXKEY
  14. #(parameter [3:0]
  15. PRESSKEY = 4'b0001,
  16. KEYCOL0 = 4'b0010,
  17. KEYCOL1 = 4'b0011,
  18. KEYCOL2 = 4'b0100,
  19. KEYCOL3 = 4'b0101,
  20. //DELAY1 = 4'b0110,
  21. //DELAY2 = 4'b0111,
  22. KEYVALID = 4'b1000,
  23. KEYRELEASE = 4'b1001,
  24. KEYERROR = 4'b1010)
  25. (input        b_ip_hex_sys_clock,
  26. input        b_ip_hex_sys_reset,
  27. input        b_ip_hex_clear,
  28. input [3:0] b_ip_hex_keypad_row
  29. output reg [3:0] b_op_hex_keycode,
  30. output reg              b_op_hex_valid_code,
  31. output reg [3:0]  b_op_hex_keypad_column,
  32. );

  33. reg [3:0] current,next,row;

  34. //***********************************************************

  35. ///////////////FIRST//////////////////////////////////////
  36. always @(posedge b_ip_hex_sys_clock) begin: BGN
  37. if (b_ip_hex_sys_reset || b_ip_hex_clear) current <= PRESSKEY;
  38. else                                         current <= next;
  39. end
  40. //////////////////////////////////////////////////////////


  41. ///////////////////////CURRENTSTATE/////////////////////////
  42. always @(b_ip_hex_keypad_row || current)begin: NSL
  43.         case(current)
  44.        
  45.                 PRESSKEY:
  46.                         if ((|b_ip_hex_keypad_row))  next <= KEYCOL0;
  47.                         else                            next <= PRESSKEY;
  48.                
  49.                 KEYCOL0:
  50.                         if ((|b_ip_hex_keypad_row))  next = KEYVALID;
  51.                         else if ((!(|b_ip_hex_keypad_row)) && b_op_hex_keypad_column == 4'b0001) next = KEYCOL1;  
  52.        
  53.        
  54.                 KEYCOL1:
  55.                         if ((|b_ip_hex_keypad_row))  next = KEYVALID;
  56.                         else if ((!(|b_ip_hex_keypad_row)) && b_op_hex_keypad_column == 4'b0010) next = KEYCOL2;


  57.                 KEYCOL2:
  58.                         if ((|b_ip_hex_keypad_row))  next = KEYVALID;
  59.                         else if ((!(|b_ip_hex_keypad_row)) && b_op_hex_keypad_column == 4'b0100) next = KEYCOL3;


  60.                 KEYCOL3:
  61.                         if ((|b_ip_hex_keypad_row))          next = KEYVALID;
  62.                         else if (!(b_ip_hex_keypad_row)) next = KEYERROR;
  63.                         else                                 next = 4'bx;



  64.                 KEYVALID:
  65.                         next = KEYRELEASE;


  66.                 KEYRELEASE:
  67.                         if (!(|b_ip_hex_keypad_row)) next = PRESSKEY;
  68.                         else                            next = KEYRELEASE;


  69.                 KEYERROR:
  70.                         next = PRESSKEY;
  71.                

  72.                 default:
  73.                         next = 4'bx;
  74.         endcase
  75. end


  76. /////////////////////NEXTSTATE LOGIC///////////////////////////////////////////////

  77. always @(posedge b_ip_hex_sys_clock)begin: ROL
  78.     if (b_ip_hex_sys_reset || b_ip_hex_clear)begin
  79.         b_op_hex_keypad_column <= 4'b1111;
  80.         b_op_hex_valid_code    <= 1'b0;
  81.         b_op_hex_keycode       <= 4'b0000;
  82.         row                       <= 4'b0000;
  83. end
  84. else begin

  85.         case(next)

  86.                 PRESSKEY:begin
  87.                         b_op_hex_keypad_column <= 4'b1111;
  88.                         b_op_hex_valid_code    <= 1'b0;
  89.                         b_op_hex_keycode       <= 4'b0000;
  90.                         row                       <= 4'b0000;
  91.                         end
  92.                
  93.                 KEYCOL0:begin
  94.                         b_op_hex_keypad_column <= 4'b0001;
  95.                         b_op_hex_valid_code    <= 1'b0;
  96.                         row                       <= b_ip_hex_keypad_row;
  97.                                 if (row == 4'b0001) b_op_hex_keycode <= 4'b0000;
  98.                                 else if (row == 4'b0010) b_op_hex_keycode <= 4'b0100;
  99.                                 else if (row == 4'b0100) b_op_hex_keycode <= 4'b1000;
  100.                                 else if(row == 4'b1000) b_op_hex_keycode <= 4'b1100;
  101.                         end

  102.                 KEYCOL1:begin
  103.                         b_op_hex_keypad_column <= 4'b0010;
  104.                         b_op_hex_valid_code    <= 1'b0;
  105.                         row                       <= row;
  106.                                 if (row == 4'b0001) b_op_hex_keycode <= 4'b0001;
  107.                                 else if (row == 4'b0010) b_op_hex_keycode <= 4'b0101;
  108.                                 else if (row == 4'b0100) b_op_hex_keycode <= 4'b1001;
  109.                                 else if(row == 4'b1000) b_op_hex_keycode <= 4'b1101;
  110.                         end

  111.                 KEYCOL2:begin
  112.                         b_op_hex_keypad_column <= 4'b0100;
  113.                         b_op_hex_valid_code    <= 1'b0;
  114.                         row                       <= row;
  115.                                 if (row == 4'b0001) b_op_hex_keycode <= 4'b0010;
  116.                                 else if (row == 4'b0010) b_op_hex_keycode <= 4'b0110;
  117.                                 else if (row == 4'b0100) b_op_hex_keycode <= 4'b1010;
  118.                                 else if(row == 4'b1000) b_op_hex_keycode <= 4'b1110;
  119.                         end

  120.                 KEYCOL3:begin
  121.                         b_op_hex_keypad_column <= 4'b1000;
  122.                         b_op_hex_valid_code    <= 1'b0;
  123.                         row                       <= row;
  124.                                 if (row == 4'b0001) b_op_hex_keycode <= 4'b0011;
  125.                                 else if (row == 4'b0010) b_op_hex_keycode <= 4'b0111;
  126.                                 else if (row == 4'b0100) b_op_hex_keycode <= 4'b1011;
  127.                                 else if(row == 4'b1000) b_op_hex_keycode <= 4'b1111;
  128.                         end

  129.                 KEYRELEASE:begin
  130.                         b_op_hex_keypad_column <= 4'b1111;
  131.                         b_op_hex_valid_code    <= 1'b0;
  132.                         b_op_hex_keycode       <= b_op_hex_keycode;
  133.                         end

  134. ……………………

  135. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
HexKeypad.rar (72.42 KB, 下载次数: 6)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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