图1 系统框图
模块名称 | 功能简述 |
Key_Board | 矩阵按键输入控制 |
Mima_detect | 密码检测 |
HEX8 | 数码管驱动显示 |
HC595_Driver | 74HC595串行移位寄存器驱动模块 |
contrl | 逻辑控制 |
信号名称 | I/O | 功能描述 |
Clk | I | 模块时钟,50MHz |
Rst_n | I | 模块复位,低电平有效 |
Key_Board_row_i | I | 矩阵按键行输入信号 |
Key_Flag | O | 按键按下标志信号 |
Key_Value | O | 按键值 |
Key_Board_col_o | O | 矩阵按键输出列信号 |
信号名称 | I/O | 功能描述 |
Clk | I | 模块时钟,50MHz |
Rst_n | I | 模块复位,低电平有效 |
Key_falg | I | 按键按下标志信号 |
Key_value | I | 按键值 |
start_bj | I | 开始比较 |
error | O | 密码错误 |
Mima_r | O | 实际输入的密码 |
Right | O | 密码正确 |
parameter PASSWORD = 16'b0001_0010_0011_0100; |
always@(posedge Clk or negedge Rst_n) begin if(!Rst_n) key_cnt <= 2'b0; else if(key_flag) begin if(key_cnt == 2'd3) key_cnt <= 2'b0; else key_cnt <= key_cnt + 1'b1; end else key_cnt <= key_cnt; end always@(posedge Clk or negedge Rst_n) begin if(!Rst_n) mima_r <= 16'b0; else if(key_flag) case(key_cnt) 2'd0: mima_r[15:12] <= key_value[3:0]; 2'd1: mima_r[11:8] <= key_value[3:0]; 2'd2: mima_r[7:4] <= key_value[3:0]; 2'd3: mima_r[3:0] <= key_value[3:0]; default: mima_r <= 0; endcase else mima_r <= mima_r; end |
wire key_startbj_flag;wire key_startbj_state; key_filter key_filter_start( .Clk(Clk), .Rst_n(Rst_n), .key_in(start_bj), .key_flag(key_startbj_flag), .key_state(key_startbj_state) ); |
always@(posedge Clk or negedge Rst_n)begin if(!Rst_n) begin error <= 1'b0; right <= 1'b0; end else if(key_startbj_flag && !key_startbj_state)begin if(mima_r == PASSWORD) begin right <= 1'b1; error <= 1'b0; end else begin right <= 1'b0; error <= 1'b1; end end else begin error <= 1'b0; right <= 1'b0; end end |
信号名称 | I/O | 功能描述 |
Clk | I | 模块时钟,50MHz |
Rst_n | I | 模块复位,低电平有效 |
Error | I | 密码错误输入信号 |
Right | I | 密码正确输入信号 |
Door_open | O | 开门信号 |
Led_right | O | 密码正确灯光信号 |
Beep_alarm | O | 密码错误报警信号 |
Led_alarm | O | 密码错误灯光信号 |
parameter IDLE = 3'b001, PASS = 3'b010, ALARM = 3'b100; |
always@(posedge Clk or negedge Rst_n) begin if(!Rst_n) current_state <= IDLE; else current_state <= next_state; end |
always@(current_state or error or right or cnt_2s) begin case(current_state) IDLE: begin if(right) next_state = PASS; else if(error) next_state = ALARM; else next_state = IDLE; end PASS: begin if(cnt_2s) //door_close next_state = IDLE; else next_state = PASS; end ALARM: begin if(cnt_2s) next_state = IDLE; else next_state = ALARM; end default: next_state = IDLE; endcase end |
always@(posedge Clk or negedge Rst_n) begin if(!Rst_n) begin door_open_r <= 1'b0; led_alarm_r <= 1'b0; led_right_r <= 1'b0; beep_En <= 1'b0; end else begin case(next_state) IDLE: begin door_open_r <= 1'b0; led_alarm_r <= 1'b0; led_right_r <= 1'b0; beep_En <= 1'b0; end PASS: begin if(cnt_2s)begin door_open_r <= 1'b0; led_alarm_r <= 1'b0; beep_En <= 1'b0; led_right_r <= 1'b0; end else begin door_open_r = 1'b1;led_right_r = 1'b1; end end ALARM: begin if(cnt_2s) begin led_alarm_r = 1'b0; beep_En = 1'b0; end else begin led_alarm_r = 1'b1; beep_En = 1'b1; end end default: begin door_open_r <= door_open_r; led_alarm_r <= led_alarm_r; beep_En <= beep_En; led_right_r <= led_right_r; end endcase end end |
信号名称 | 功能描述 |
Clk | 50M时钟 |
Rst_n | 复位信号 |
En | 数码管使能信号1使能,0关闭 |
disp_data[31:0] | 8个数码管待显示数据,每四位组成一个BCD码 |
sel[7:0] | 数码管位选,选择当前要显示的数码管 |
seg[6:0] | 数码管段选,当前要显示的内容 |
更多回帖