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串口发送数据的更多相关文章

  1. WPF内实现与串口发送数据和接收数据

    原文:WPF内实现与串口发送数据和接收数据 与串口发送数据和接收数据,在此作一个简单的Demo.此Demo可以实现按下硬件按钮,灯亮,发送灯状态数据过来.并且可以实现几个灯同时亮,发送灯的状态数据过来 ...

  2. C#串口通信—向串口发送数据,同步接收返回数据

    最近写C#串口通信程序,系统是B/S架构.SerialPort类有一个DataReceived事件,用来接收串口返回的数据,但这种方式在C/S架构下很好用,但B/S就不好处理了.所以写了一个同步模式接 ...

  3. 【Debug】串口发送数据时部分字节被拉长,出现帧错误,原因MCU进入低功耗模式导致串口时钟停了!

    串口发送数据时部分字节被拉长,出现帧错误,原因MCU进入低功耗模式导致串口时钟停了!

  4. C#把汉字转换成16进制(HEX)并向串口发送数据

    报警器实例:(有发送,无返回获取) using System; using System.Collections.Generic; using System.Linq; using System.Te ...

  5. (已解决)STM32L151使用串口发送数据第一字节为FE问题!

    最近学习到串口发送数据时遇到一个问题:第一个字节总是FE,后面才是对的数据. 最终解决的方法是: 讲GPIO复用的操作放到GPIO配置之前! 体现在代码中就是: //打开GPIO时钟 RCC_AHBP ...

  6. stm32串口发送数据复位 第一个数据丢失

    http://blog.csdn.net/kevinhg/article/details/40991655 STM32串口发送必须先检测状态,否则第一个字节无法发出,发送完毕,必须检测发送状态是否完成 ...

  7. C# 实现串口发送数据(不用串口控件版)

    参考:https://blog.csdn.net/mannix_lei/article/details/79979432 https://www.cnblogs.com/ElijahZeng/p/76 ...

  8. 语音控制单片机工作【百度语音识别,串口发送数据到单片机】【pyqt源码+软件】!!

    前些天闲着没事,就做了个语音识别结合串口发送指令的软件,用的是pyqt写的,软件打开后对着笔记本的话筒说话, 他就能识别返回文字结果,然后匹配语音中的关键词,如果有关键词就发送关键词对应的命令,比如语 ...

  9. 如何利用.NETCore向Azure EventHubs准实时批量发送数据?

    最近在做一个基于Azure云的物联网分析项目: .netcore采集程序向Azure事件中心(EventHubs)发送数据,通过Azure EventHubs Capture转储到Azure Blog ...

随机推荐

  1. 不吹不黑,赞一下应用运维管理的cassacdra

    不吹不黑的为菊厂的应用运维管理AOM点个赞.Why? 某菊厂应用运维管理工具AOM每天处理着亿级条数据,这么多数据是怎么存储的呢? 说到数据存储就会想到关系型数据库,比如mysql,oracle,sy ...

  2. MySQL SELECT语法(二)SELECT...INTO语法

    源自MySQL 5.7 官方手册 SELECT...INTO Syntax 一.SELECT...INTO介绍 SELECT...INTO用来将查询结果存储在变量或者写入文件中. SELECT ... ...

  3. 第二讲,NT头文件格式,以及文件头格式

    今天详解NT 头格式,以及文件头格式,以及作用, 关于DOS头文件格式,以及DOSStub昨天的博客已经写过了.主要是分散讲解.便于理解. 一丶最小PE的生成,以及标准PE的生成 ps: (如果直接学 ...

  4. Pattern Recognition and Machine Learning-01-Preface

    Preface Pattern recognition has its origins in engineering, whereas machine learning grew out of com ...

  5. javaIO——BufferedReader

    今天来学习一下 java.io.BufferedReader ,从命名可以看出,跟前面学习的 StringReader 和 CharArrayReader 有些不一样,这些都是按照数据源类型命名,Bu ...

  6. spark application调度机制(spreadOutApps,oneExecutorPerWorker 算法)

    1.要想明白spark application调度机制,需要回答一下几个问题: 1.谁来调度? 2.为谁调度? 3.调度什么? 3.何时调度? 4.调度算法 前四个问题可以用如下一句话里来回答:每当集 ...

  7. 如何在调用Marketing Cloud contact创建API时增加对扩展字段的支持

    需求:扩展字段"微信ID"是我创建出来的extension field,我想用Marketing Cloud提供的contact creation API,在创建contact时也 ...

  8. hadoop中hive常用的交互式操作

    hive的帮助命令: [hadoop@master tmp]$ hive -help usage: hive -d,--define <key=value> Variable substi ...

  9. idea代码爆红,clean,或者maven reimport都不起作用

    1 突然自己的idea的Maven项目代码都是爆红,但是可以运行,添加新的代码确无法运行 尝试了clean,或者reimport,甚至是大家推荐的,刷新缓存重启也没有作用 2 检查项目的jdk配置,也 ...

  10. (十四)Linux kernel mmc 框架说明,包括mmc_test使用方法

    1.Linux 总线模型         Linux下的任何驱动在内核中最终都抽象为bus, driver以及device三者间的相互作用. 总线是处理器和一个或多个设备之间的通道,在设备模型中,所有 ...