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. 第十章 MIZ702 ZYNQ制作UBOOT固化程序

    10.0难度系数★☆☆☆☆☆☆ 10.1是什么是固化 我们前几章将的程序都是通过JTAG先下载bit流文件,再下载elf文件,之后点击Run As来运行的程序.JTAG的方法是通过TCL脚本来初始化P ...

  2. Codeforces 1189F. Array Beauty

    传送门 首先可以注意到序列里面元素的顺序对答案是没有影响的,所以二话不说先排序再看看怎么搞 考虑枚举每种子序列可能产生的贡献并算一下产生这个贡献的子序列有多少 考虑设 $F(x)$ 表示选择的元素差值 ...

  3. 空间变换网络(STN)原理+2D图像空间变换+齐次坐标系讲解

    空间变换网络(STN)原理+2D图像空间变换+齐次坐标系讲解 2018年11月14日 17:05:41 Rosemary_tu 阅读数 1295更多 分类专栏: 计算机视觉   版权声明:本文为博主原 ...

  4. LeetCode:627.交换工资

    题目链接:https://leetcode-cn.com/problems/swap-salary/ 题目 给定一个 salary 表,如下所示,有 m = 男性 和 f = 女性 的值.交换所有的 ...

  5. vue覆盖UI组件样式不生效

    检查检查是不是加了scoped 在vue中,我们需要引用子组件,包括ui组件(element.iview). 但是在父组件中添加scoped之后,在父组件中书写子组件的样式是无效果的. 去掉scope ...

  6. 9.SpringMVC注解式开发-处理器的请求映射规则的定义

    1.对请求URI的命名空间的定义 @RequestMapping的value属性用于定义所匹配请求的URI.但对于注解在方法上和注解在类上, 其value 属性 所指定的URI,意义是不同的 一个@C ...

  7. ST3 C程序自动补全

    参考: http://www.cnblogs.com/heleifz/p/3404600.html http://www.cnblogs.com/By-ruoyu/p/4687196.html htt ...

  8. TouchGFX版本

    TouchGFX 4.12.3版本 本文概述了TouchGFX 4.12.3版本,其总体功能以及如何与CubeMX和CubeIDE集成. 总览 有关4.12.3新增功能的一般概述,请查看发行版中的ch ...

  9. socket 多线程安全、粘包问题

    脚本如下: # -*- coding:utf-8 -*- ''' @Author: Stefan @File: server_listener.py @Date: 2016-11-09 If you ...

  10. sql 语句用法

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname 3.说明:备份sql server--- 创建 ...