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. java学习要想精炼掌握应运的必备知识(博文来源于网络)

    一: 编程基础 不管是C还是C++,不管是Java还是PHP,想成为一名合格的程序员,基本的数据结构和算法基础还是要有的.下面几篇文章从思想到实现,为你梳理出常用的数据结构和经典算法. 1-1 常用数 ...

  2. C# 7.0 语法

    C# 7.0的语法主要是优化了之前的写法,使得更加简洁方便.try catch when  这个使用场景很少,正常的开发无业务处理的时候不建议使用 . #region 2.字符串嵌入值 Console ...

  3. sqlserver错误状态码解释

    Code Error Message 0 操作成功完成. 1 功能错误. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒绝访问. 6 句柄无效. 7 存储控制块 ...

  4. PS笔记

    PS 笔记 PS调色人像步骤-by李涛: 色阶- 追饱和度- 色彩平衡-  中间调不动,阴影偏青,偏绿,偏蓝  , 高光偏红,偏一点蓝 锐化 1. 冷暖对比-by狼族摄影:   高光和阴影设置为偏青色 ...

  5. css3之媒体查询

    <html> <head> <meta charset="utf-8"> <style> body{ background-colo ...

  6. JAVA对ArrayList排序

    ava如何对ArrayList中对象按照该对象某属性排序 增加排序功能,打印时:输出学生对象的时候,需要先按照年龄排序,如果年龄相同,则按照姓名排序,如果姓名也相同,则按照学号排序. Code hig ...

  7. LaTeX中Python代码的语法高亮

    LaTeX中Python代码的语法高亮 本文中,"{}"中的字母为LaTeX或Python的包名,只有"Pygments"是Python的包,其他都是LaTeX ...

  8. SSISDB7:当前正在运行的Package及其Executable

    PM问:“Vic,现在ETL Job跑到哪一个Package了,正在执行哪个Task?”,第一次遇到这个问题时,一下就懵逼了,只能硬着头皮说:“我看看”. 在做项目开发时,这个问题很常见,但是,被很多 ...

  9. liunx加载JX2410标准配置文件

  10. 一图一知-NPM&YARN常用命令