有限状态机时序电路设计之检测连续四个0或1的个数
来源:互联网 发布:淘宝产品推广方案 编辑:程序博客网 时间:2024/06/06 07:33
有限状态机时序电路之连续检测四个0或1的个数
设计一个4连续0或者4个连续1的序列检测FSM,定义一个长序列,在七段管上分别显示检测的4个连续0和4个连续1的个数。显示连续0和连续1的个数在七段管上的显示,分别用函数和任务实现。
比如:100000110011111000011111.。。。。
检测连0个数: 000011111111111111222222。。。。
1个数: 000000000000011111111122.。。
module show(clk,clr,x,hex1,hex2);input clk,clr,x; output reg[6:0] hex1,hex2; reg[3:0] state;reg[3:0] count1=0,count2=0;parameter S0=4'b0000,S1=4'b0001,S2=4'b0010,S3=4'b0011,S4=4'b0100,S5=4'b0101,S6=4'b0110,S7=4'b0111,S8=4'b1000;//定义八个好状态always @(posedge clk or posedge clr)begin if(clr) state=S0; //异步复位,s0为起始状态 else case(state)//状态转移过程 S0:begin if(x) begin state<=S5; taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state<=S1; taskMatch(count1,hex1);hex2<=funMatch(count2); end end S1:begin if(x) begin state <=S5;taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state <=S2; taskMatch(count1,hex1);hex2<=funMatch(count2); end end S2:begin if(x) begin state <=S5; taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state <=S3; taskMatch(count1,hex1);hex2<=funMatch(count2); end end S3:begin if(x) begin state <=S5; taskMatch(count1,hex1);hex2 <=funMatch(count2); end else begin state<=S4; count1 <= count1+1;taskMatch(count1,hex1);hex2<=funMatch(count2); end end S4:begin if(x) begin state <=S5; taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state<=S1; ; taskMatch(count1,hex1);hex2<=funMatch(count2); end end S5:begin if(x) begin state <=S6; taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state<=S1; taskMatch(count1,hex1);hex2<=funMatch(count2); end end S6:begin if(x) begin state <=S7; taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state<=S1; taskMatch(count1,hex1);hex2<=funMatch(count2); end end S7:begin if(x) begin state <=S8; count2 <= count2+1;taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state<=S1; taskMatch(count1,hex1);hex2<=funMatch(count2); end end S8:begin if(x) begin state <=S5;taskMatch(count1,hex1);hex2<=funMatch(count2); end else begin state<=S1; taskMatch(count1,hex1);hex2<=funMatch(count2); end end default:begin state<=S0;taskMatch(count1,hex1);hex2<=funMatch(count2); end endcase endtask taskMatch;//七段管显示数字的任务input [3:0] a;output [6:0] b;case(a) 4'H0:b<=7'b1000000; 4'H1:b<=7'b1111001; 4'H2:b<=7'b0100100; 4'H3:b<=7'b0110000; 4'H4:b<=7'b0011001; 4'H5:b<=7'b0010010; 4'H6:b<=7'b0000010; 4'H7:b<=7'b1111000; 4'H8:b<=7'b0000000; 4'H9:b<=7'b0011000; 4'HA:b<=7'b0001000; 4'Hb:b<=7'b0000011; 4'Hc:b<=7'b1000110; 4'Hd:b<=7'b0100001; 4'He:b<=7'b0000110; 4'Hf:b<=7'b0001110; default:b<=7'b1111111;endcaseendtaskfunction [6:0] funMatch;//七段管显示数字的函数input [3:0] a;case(a) 4'H0:funMatch=7'b1000000; 4'H1:funMatch=7'b1111001; 4'H2:funMatch=7'b0100100; 4'H3:funMatch=7'b0110000; 4'H4:funMatch=7'b0011001; 4'H5:funMatch=7'b0010010; 4'H6:funMatch=7'b0000010; 4'H7:funMatch=7'b1111000; 4'H8:funMatch=7'b0000000; 4'H9:funMatch=7'b0011000; 4'HA:funMatch=7'b0001000; 4'Hb:funMatch=7'b0000011; 4'Hc:funMatch=7'b1000110; 4'Hd:funMatch=7'b0100001; 4'He:funMatch=7'b0000110; 4'Hf:funMatch=7'b0001110; default:funMatch=7'b1111111;endcaseendfunctionendmodule
1 0
- 有限状态机时序电路设计之检测连续四个0或1的个数
- 连续0的个数
- 统计字符串中连续1和连续0的个数
- 四个连续的自然数
- 图像处理 之 统计数组中连续0/1的个数
- 时序(四)----有限状态机FSM
- 一种简单的短路检测电路设计
- N!的尾部连续0的个数
- N!的尾部连续0的个数
- n!最后连续0的个数
- LeetCode 485 最大连续1的个数
- C/C++面试之算法系列--N!的尾部连续0的个数
- leetcode解题之485. Max Consecutive Ones Java版 (二进制连续最长1的个数)
- UML建模之时序图(重点讲矩形长条的连续与间断)
- UML建模之时序图(重点讲矩形长条的连续与间断)
- python 判断连续是0 或1 的最大次数
- 统计连续字段的个数
- 求二进制数中0或1的个数
- 实验四-dpcm编码
- hihoCoder 1066 : 无间道之并查集
- SELECT语句语法格式
- 09 WebGL通过uniform变量修改点的颜色
- 指针与数组
- 有限状态机时序电路设计之检测连续四个0或1的个数
- maven创建java项目
- GitHub上fork别人的项目,并保存同步方法
- Docker学习笔记(一)
- 16. 导入开源库 java.lang.NoClassDefFoundError: rx.plugins.RxJavaPlugins
- Struts2 Action中获得Request,Response,Session对象的几种常用方法
- LeetCode118 Pascal's Triangle
- C# WinForm开发系列之DataRepeater控件的使用(显示数据的基础使用和自定义使用)
- JavaScript 4.3 函数高级-闭包