search_word
一个小程序,用asc码输出自己的名字。要求是,a~z两路输入,输出了一个完整的拼音之后还需要输出一个空格。—— 信息硬件过滤的雏形。
module search_word (
clock ,
reset ,
d0,
d1,
word
);
//---------------------------------------------------------
input clock ,reset;
input [:] d0 ; //A=65 M= 77
input [:] d1 ; //N = 78 Z = 90
//----------------------------------------------------------
output reg [:] word ; // pengxiaoen
`define P 'd80 // D1
`define E 'd69 //D0
`define N 'd78 //D0
`define G 'd71 //D0
`define X 'd88 //D1
`define I 'd73 //D0
`define A 'd65 //D0
`define O 'd79 //D1
`define null 'd32 //en `define S0 'd0
`define S1 'd1
`define S2 'd2
`define S3 'd3
`define S4 'd4
`define S5 'd5
`define S6 'd6
`define S7 'd7
`define S8 'd8
`define S9 'd9
`define S10 'd10 reg [:] current_state ;
reg [:] next_state ;
reg data_sel ; // 路由选通信号 1: 输出是d1 0 : 输出是d0
reg enable ; // 输出使能信号 1 : 输出空格 0:输出字母
reg [:] data_reg ; //数据缓存,缓存所选数据 always @ (posedge clock or negedge reset )
if (!reset ) current_state <= 'd0 ;
else current_state <= next_state ; //always @ (*)
always @ (posedge clock or negedge reset )
begin
if(!reset)
next_state <= 'd0 ;
else
begin
case (next_state)
`S0 : begin
if (data_reg == `P)
next_state <= `S1;
else next_state <= `S0 ; // 等待P 的到来
end
`S1 : begin
if (data_reg == `E)
next_state <= next_state + 'd1;
else next_state <= `S1 ; // 等待E 的到来
end
`S2 : begin
if (data_reg == `N)
next_state <= `S3;
else next_state <= `S2 ; // 等待N 的到来
end
`S3 : begin
if (data_reg == `G)
next_state <= `S4;
else next_state <= `S3 ; // 等待G 的到来
end
`S4 : begin
if (data_reg == `X)
next_state <= `S5;
else next_state <= `S4; // 等待X 的到来
end
`S5 : begin
if (data_reg == `I)
next_state <= `S6;
else next_state <= `S5; // 等待I 的到来
end
`S6 : begin
if (data_reg == `A)
next_state <= `S7;
else next_state <= `S6 ; // 等待A 的到来
end
`S7 : begin
if (data_reg == `O)
next_state <= `S8;
else next_state <= `S7 ; // 等待O 的到来
end
`S8 : begin
if (data_reg == `E)
next_state <= `S9;
else next_state <= `S8 ; // 等待E的到来
end
`S9 : begin
if (data_reg == `N)
next_state <= `S10;
else next_state <= `S9 ; // 等待N的到来
end
`S10 : begin
next_state = `S0 ;
end
default : next_state <= `S0 ;
endcase
end
end always @ (posedge clock or negedge reset )
begin
if(!reset)
begin
data_sel <= 'd0 ;
enable <= 'd0 ;
end
else
begin
case (current_state)
`S0 : begin
enable <= 'd1; //0: 输出字母 1 : 输出空格
data_sel <= 'd1 ; // P属于通道1
end
`S1 : begin
enable <= 'd0 ;
data_sel <= 'd0; //E 属于通道 0
end
`S2 : begin
enable <= 'd0 ;
data_sel <= 'd1 ; // N 属于通道1
end
`S3 : begin
enable <= 'd0; // 输出字母
data_sel <= 'd0 ; // G 属于通道0 end
`S4 : begin
enable <= 'd1 ; //输出空格
data_sel <= 'd1 ; //X 属于通道1
end
`S5 : begin
enable <= 'd0 ;
data_sel <= 'd0 ; // I 属于通道0
end
`S6 : begin
enable <= 'd0 ;
data_sel <= 'd0 ; // A 为通道0
end
`S7 : begin
enable <= 'd0 ;
data_sel <= 'd1 ; // O 属于通道1
end
`S8 : begin
enable <= 'd1 ; //输出空格
data_sel <= 'd0 ; // E 属于通道0
end
`S9 : begin
enable <= 'd0 ; //
data_sel <= 'd1 ; // N 属于通道 1
end
`S10 : begin
enable <='d0 ; // 输出
data_sel <= 'd1; // P 属于通道1
end
endcase
end
end always @ (posedge clock or negedge reset )
// always @ (*)
begin
if (!reset ) data_reg <= 'd0 ;
else
begin
if (data_sel) data_reg <= d1 ;
else data_reg <= d0 ;
end
end always @ (posedge clock or negedge reset )
begin
if(!reset) word <= 'd0 ;
else if(!enable)
begin
case (current_state)
`S0 : word <= `null;
`S1 : word <= `P;
`S2 : word <= `E;
`S3 : word <= `N;
`S4 : word <= `G;
`S5 : word <= `X;
`S6 : word <= `I;
`S7 : word <= `A;
`S8 : word <= `O;
`S9 : word <= `E;
`S10 : word <= `N;
default : word <= 'd0 ;
endcase
end
else word <= 'b010_0000;
end endmodule
附上testbench ,亲测可用
`timescale 1ns/1ps module search_word_tb ;
reg clock ,reset ;
reg [:] d0 ,d1 ;
wire [:]word ; integer i ,j ; always # clock = ~clock ; initial
begin
clock = ; reset = ;
# reset = ; end initial
begin
d0 = 'd0 ;
# ;
repeat ()
begin
for (i = ;i <= ; i=i+)
begin
# d0 = 'd65 + i ;
end
end
end initial
begin
d1 = 'd0 ;
# ;
repeat ()
begin
for (j = ;j <= ; j=j+)
begin
# d1 = 'd78 + j;
end
end
end search_word myu0 (
.clock (clock ),
.reset (reset ),
.d0(d0),
.d1(d1),
.word (word )
); endmodule
search_word的更多相关文章
- JS实现选择不同select标签option值的验证
js实现不同select标签option值的验证 功能描述: 选择中文时,匹配中文的正则表达式,选择英文选项是匹配英文的表达式,并且有对应的提示信息. html代码片段: <select id= ...
- vi 使用
1)命令 gf ,可以从光标指定的文件位置打开对应文件 :bd回来 2)http://www.cnblogs.com/wangkangluo1/archive/2012/04/12/244495 ...
- Browser设置搜索引擎
Browser设置搜索引擎,在com.android.browser.preferences.GeneralPreferencesFragment中加载R.xml.general_preference ...
- 从URL中获取搜索关键字
public string GetSearchKeyWords(string strQuery) { string result = ""; string pattern = &q ...
- Linux Shell编程(5)——shell特殊字符(下)
{}代码块[花括号]. 这个结构也是一组命令代码块,事实上,它是匿名的函数.然而与一个函数所不同的,在代码块里的变量仍然能被脚本后面的代码访问. bash$ { local a; a=123 ...
- Trie 字典树
字典树是哈希树的变种, 它采用公用前缀的方式来提高效率, 刚开始以为公用前缀, 空间会节省, 后来想想, 空间也不是节省, 因为每一个都有26个指针(这里假设都是小写字母的话), 不过他的时间复杂度是 ...
- 大约SQL/NoSQL数据库搜索/思考查询
转载请注明出处:jiq•钦's technical Blog Hbase特征: 近期在学习Hbase.Hbase基于行健是建立了索引的,查询速度会很快,全然实时. 可是Hbase要基于行健之外的字段进 ...
- linux_shell 特殊符号的介绍
linux_shell 特殊符号的介绍 2011-12-17 17:54:07 分类: 原文地址:linux_shell 特殊符号的介绍 作者:xu_liuzhen linux_shell 特殊符号的 ...
- ajax分页实现(php)
ajax分页实现(php) 使用jquery.pagination.js插件 引入js文件.css文件 <link rel="stylesheet" href="/ ...
随机推荐
- win使用telnet到ubuntu下vim显示中文为乱码的解决方法~
1.几个路径: ubuntu: /etc/default/locale 相当于 centos:/etc/sysconfig/i18n vimrc的路径:① ~/.vimrc ② /etc/vi ...
- (Problem 41)Pandigital prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- c++builder 重载WindowProc、WndProc 截获消息(比Delphi多一个Message Map方法)
c++builder 重载WindowProc.WndProc 截获消息 方法一WindowProc void __fastcall myWindowProc(Messages::TMessage ...
- POCO C++ lib开发环境构建
Welcome Thank you for downloading the POCO C++ Libraries and welcome to the growing community of POC ...
- Kapit控件方法笔记
r.kapit.visualizer.renderers.DefaultItemRenderer //整个节点添加click处理函数对象类型 fr.kapit.visualizer.controls. ...
- 解决https无法缓存的问题
火狐弃用http,转而大力推广https的动作一石激起千层浪,非常多没有安装安全证书的站点使用新版火狐浏览器已经打不开了. 之前我们站点仅仅有涉及须要加密的部分连接为https协议.眼下看来不得不将整 ...
- IT忍者神龟之Struts2.xml配置全然正确流程能走通可是有红叉解决
一:Multiple annotations found at this line:Undefined actionName parameter Undefined actionnamespace ...
- JavaScript constructor prototyoe
想加深一下自己对construtcor prototype的印象所以写了这一篇文章 对象的constructor 就是Object 除了通过构造函数创建的对象意外 他的constructor 都是 都 ...
- if和switch的区别,循环的for 和while的区别, 字符串常用的7种方法
相同点: 都是用于多重选择 不同点: 多重IF没有switch选择结构的限制,特别适合变量处于某个连续区间的情况 switch只能处理等值条件判断的情况,而且条件必须是整型变量或者字符串变量 字符串的 ...
- C3P0连接池参数解释
<!--acquireIncrement:链接用完了自动增量3个. --> <property name="acquireIncrement">3</ ...