利用状态机(FSM)进行简单的uart串口发送数据
module uart_tx(clk,rst_n,key,txd); input clk;
input rst_n;
input key;
output reg txd; reg[:] state;
reg[:] bit_timer;
wire[:] tx_data;
assign tx_data='h5a; parameter s_idle='d0;
parameter s_start='d1;
parameter s_bit0='d2;
parameter s_bit1='d3;
parameter s_bit2='d4;
parameter s_bit3='d5;
parameter s_bit4='d6;
parameter s_bit5='d7;
parameter s_bit6='d8;
parameter s_bit7='d9;
parameter s_stop='d10; always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
state<=s_idle;
bit_timer<='d0;
txd<='b1;
end
else
begin
case(state) s_idle:
begin
txd<='b1;
if(!key)
state<=s_start;
else
state<=state;
end s_start:
begin
txd<='b0;
if(bit_timer=='d5208)
begin
state<=s_bit0;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit0:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_bit1;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit1:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_bit2;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit2:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_bit3;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit3:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_bit4;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit4:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_bit5;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit5:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_bit6;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit6:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_bit7;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_bit7:
begin
txd<=tx_data[];
if(bit_timer=='d5208)
begin
state<=s_stop;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end s_stop:
begin
txd<='b1;
if(bit_timer=='d5208)
begin
state<=s_idle;
bit_timer<='d0;
end
else
begin
state<=state;
bit_timer=bit_timer+'d1;
end
end default:
begin
state<=s_idle;
end endcase
end end endmodule
利用状态机(FSM)进行简单的uart串口发送数据的更多相关文章
- WPF内实现与串口发送数据和接收数据
原文:WPF内实现与串口发送数据和接收数据 与串口发送数据和接收数据,在此作一个简单的Demo.此Demo可以实现按下硬件按钮,灯亮,发送灯状态数据过来.并且可以实现几个灯同时亮,发送灯的状态数据过来 ...
- C#串口通信—向串口发送数据,同步接收返回数据
最近写C#串口通信程序,系统是B/S架构.SerialPort类有一个DataReceived事件,用来接收串口返回的数据,但这种方式在C/S架构下很好用,但B/S就不好处理了.所以写了一个同步模式接 ...
- 【Debug】串口发送数据时部分字节被拉长,出现帧错误,原因MCU进入低功耗模式导致串口时钟停了!
串口发送数据时部分字节被拉长,出现帧错误,原因MCU进入低功耗模式导致串口时钟停了!
- C#把汉字转换成16进制(HEX)并向串口发送数据
报警器实例:(有发送,无返回获取) using System; using System.Collections.Generic; using System.Linq; using System.Te ...
- (已解决)STM32L151使用串口发送数据第一字节为FE问题!
最近学习到串口发送数据时遇到一个问题:第一个字节总是FE,后面才是对的数据. 最终解决的方法是: 讲GPIO复用的操作放到GPIO配置之前! 体现在代码中就是: //打开GPIO时钟 RCC_AHBP ...
- stm32串口发送数据复位 第一个数据丢失
http://blog.csdn.net/kevinhg/article/details/40991655 STM32串口发送必须先检测状态,否则第一个字节无法发出,发送完毕,必须检测发送状态是否完成 ...
- C# 实现串口发送数据(不用串口控件版)
参考:https://blog.csdn.net/mannix_lei/article/details/79979432 https://www.cnblogs.com/ElijahZeng/p/76 ...
- 语音控制单片机工作【百度语音识别,串口发送数据到单片机】【pyqt源码+软件】!!
前些天闲着没事,就做了个语音识别结合串口发送指令的软件,用的是pyqt写的,软件打开后对着笔记本的话筒说话, 他就能识别返回文字结果,然后匹配语音中的关键词,如果有关键词就发送关键词对应的命令,比如语 ...
- 如何利用.NETCore向Azure EventHubs准实时批量发送数据?
最近在做一个基于Azure云的物联网分析项目: .netcore采集程序向Azure事件中心(EventHubs)发送数据,通过Azure EventHubs Capture转储到Azure Blog ...
随机推荐
- varnish 子程序流程
VCL中主要动作: pass:当一个请求被pass后,这个请求将通过varnish转发到后端服务器,该请求不会被缓存,后续的请求仍然通过Varnish处理.pass可以放在vcl_recv 和vcl_ ...
- WebStorm使用码云插件问题
由于项目需求,需要在WebStorm中使用码云插件,在下载安装的过程中出现一系列的问题,现总结出现的问题和解决方法. 先说一下码云是什么?码云有什么作用? 码云的主要功能: 码云除了提供最基础的 Gi ...
- springboot+mybatis调用oracle存储过程
1 存储过程参数为VARCHAR 代码逻辑:controller层定义实体类对象entity,并entity.set给存储过程的输入参数赋值,把赋值后的实体类通过service层传到dao层,然后通过 ...
- c#泛型约束(转载)
博客地址:https://www.cnblogs.com/zhengwk/p/5541921.html 六种类型的约束: T:结构 类型参数必须是值类型.可以指定除 Nullable 以外的任何值类型 ...
- Linux更新程序脚本
DATE=$(date +%Y%m%d_%H%M%S) cd /opt/anystreaming/transcoder/ mv dll/libmonitor_service.so "dll/ ...
- JS 编程艺术
JS艺术片段剪贴 getFullDate: function (date) { //返回 YYYY年MM月DD日 var year = month = day = ' '; if (isNaN(dat ...
- jQuery 手写菜单(ing)
菜单支持多级 直接上代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- React中,input外边如果包一个div,可以把input的onChange事件绑定到div上面,并且也生效
最近第一次开始学习封装组件,遇到几个比较神奇的问题. 首先就是如果input外边包一个div,如果把input的onChange事件绑定到div上,也会生效 <div onChange={(e) ...
- JPA中的主键生成策略
通过annotation(注解)来映射hibernate实体的,基于annotation的hibernate主键标识为@Id, 其生成规则由@GeneratedValue设定的.这里的@id和@Gen ...
- CAFFE(FAQ.1):Ubuntu 配置caffe 框架之数据库读取错误:ImportError: No module named lmdb解决办法
Z: 在安装了caffe框架后需要读取大量的数据进行学习训练.比如在MNIST识别训练中,一般直接读图片会比较耗时,我们一般将图片转存为数据库中.目前主流的数据库有以下两种选择: LevelDB Lm ...