標(biāo)題:
Tablet counting system verilog code
[打印本頁]
作者:
Vimalraj
時間:
2017-12-3 16:09
標(biāo)題:
Tablet counting system verilog code
Hex keypad or tablet counting system
0.png
(11.26 KB, 下載次數(shù): 73)
下載附件
2017-12-3 22:21 上傳
源程序如下:
//##################################################################
/*
Project/Module : Assignment
File name : HexKeyCodeGenerator.v
Version : 1-0
Date created : 25 Aug 2017
Author : Vimalraj Kasivisvanathan
Code type : Verilog
Description : Verilog code for HexKeypad
*/
//##################################################################
//`default_nettype none
module HEXKEY
#(parameter [3:0]
PRESSKEY = 4'b0001,
KEYCOL0 = 4'b0010,
KEYCOL1 = 4'b0011,
KEYCOL2 = 4'b0100,
KEYCOL3 = 4'b0101,
//DELAY1 = 4'b0110,
//DELAY2 = 4'b0111,
KEYVALID = 4'b1000,
KEYRELEASE = 4'b1001,
KEYERROR = 4'b1010)
(input b_ip_hex_sys_clock,
input b_ip_hex_sys_reset,
input b_ip_hex_clear,
input [3:0] b_ip_hex_keypad_row
output reg [3:0] b_op_hex_keycode,
output reg b_op_hex_valid_code,
output reg [3:0] b_op_hex_keypad_column,
);
reg [3:0] current,next,row;
//***********************************************************
///////////////FIRST//////////////////////////////////////
always @(posedge b_ip_hex_sys_clock) begin: BGN
if (b_ip_hex_sys_reset || b_ip_hex_clear) current <= PRESSKEY;
else current <= next;
end
//////////////////////////////////////////////////////////
///////////////////////CURRENTSTATE/////////////////////////
always @(b_ip_hex_keypad_row || current)begin: NSL
case(current)
PRESSKEY:
if ((|b_ip_hex_keypad_row)) next <= KEYCOL0;
else next <= PRESSKEY;
KEYCOL0:
if ((|b_ip_hex_keypad_row)) next = KEYVALID;
else if ((!(|b_ip_hex_keypad_row)) && b_op_hex_keypad_column == 4'b0001) next = KEYCOL1;
KEYCOL1:
if ((|b_ip_hex_keypad_row)) next = KEYVALID;
else if ((!(|b_ip_hex_keypad_row)) && b_op_hex_keypad_column == 4'b0010) next = KEYCOL2;
KEYCOL2:
if ((|b_ip_hex_keypad_row)) next = KEYVALID;
else if ((!(|b_ip_hex_keypad_row)) && b_op_hex_keypad_column == 4'b0100) next = KEYCOL3;
KEYCOL3:
if ((|b_ip_hex_keypad_row)) next = KEYVALID;
else if (!(b_ip_hex_keypad_row)) next = KEYERROR;
else next = 4'bx;
KEYVALID:
next = KEYRELEASE;
KEYRELEASE:
if (!(|b_ip_hex_keypad_row)) next = PRESSKEY;
else next = KEYRELEASE;
KEYERROR:
next = PRESSKEY;
default:
next = 4'bx;
endcase
end
/////////////////////NEXTSTATE LOGIC///////////////////////////////////////////////
always @(posedge b_ip_hex_sys_clock)begin: ROL
if (b_ip_hex_sys_reset || b_ip_hex_clear)begin
b_op_hex_keypad_column <= 4'b1111;
b_op_hex_valid_code <= 1'b0;
b_op_hex_keycode <= 4'b0000;
row <= 4'b0000;
end
else begin
case(next)
PRESSKEY:begin
b_op_hex_keypad_column <= 4'b1111;
b_op_hex_valid_code <= 1'b0;
b_op_hex_keycode <= 4'b0000;
row <= 4'b0000;
end
KEYCOL0:begin
b_op_hex_keypad_column <= 4'b0001;
b_op_hex_valid_code <= 1'b0;
row <= b_ip_hex_keypad_row;
if (row == 4'b0001) b_op_hex_keycode <= 4'b0000;
else if (row == 4'b0010) b_op_hex_keycode <= 4'b0100;
else if (row == 4'b0100) b_op_hex_keycode <= 4'b1000;
else if(row == 4'b1000) b_op_hex_keycode <= 4'b1100;
end
KEYCOL1:begin
b_op_hex_keypad_column <= 4'b0010;
b_op_hex_valid_code <= 1'b0;
row <= row;
if (row == 4'b0001) b_op_hex_keycode <= 4'b0001;
else if (row == 4'b0010) b_op_hex_keycode <= 4'b0101;
else if (row == 4'b0100) b_op_hex_keycode <= 4'b1001;
else if(row == 4'b1000) b_op_hex_keycode <= 4'b1101;
end
KEYCOL2:begin
b_op_hex_keypad_column <= 4'b0100;
b_op_hex_valid_code <= 1'b0;
row <= row;
if (row == 4'b0001) b_op_hex_keycode <= 4'b0010;
else if (row == 4'b0010) b_op_hex_keycode <= 4'b0110;
else if (row == 4'b0100) b_op_hex_keycode <= 4'b1010;
else if(row == 4'b1000) b_op_hex_keycode <= 4'b1110;
end
KEYCOL3:begin
b_op_hex_keypad_column <= 4'b1000;
b_op_hex_valid_code <= 1'b0;
row <= row;
if (row == 4'b0001) b_op_hex_keycode <= 4'b0011;
else if (row == 4'b0010) b_op_hex_keycode <= 4'b0111;
else if (row == 4'b0100) b_op_hex_keycode <= 4'b1011;
else if(row == 4'b1000) b_op_hex_keycode <= 4'b1111;
end
KEYRELEASE:begin
b_op_hex_keypad_column <= 4'b1111;
b_op_hex_valid_code <= 1'b0;
b_op_hex_keycode <= b_op_hex_keycode;
end
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
HexKeypad.rar
(72.42 KB, 下載次數(shù): 6)
2017-12-3 16:08 上傳
點擊文件名下載附件
hex key
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1