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. S02_CH15_ AXI_OLED 实验

    S02_CH15_ AXI_OLED 实验 在上一个例子中,主要是以软件功能为主,采用了软件模拟SPI时序进行控制OLED.这样做的好处是灵活,但是牺牲了效率.本章采用的方式是让SPI驱动由Veril ...

  2. hdu 2680 Dijstra

    Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. scala的泛型浅析

    1. scala泛型浅析 package com.dtspark.scala.basics /** * 1,scala的类和方法.函数都可以是泛型. * * 2,关于对类型边界的限定分为上边界和下边界 ...

  4. NPOI 实现在已存在的Excel中任意位置开始插入任意数量行,并填充数据

    1 npoi版本2.1.3.1 2 需要添加的引用: using NPOI.SS.UserModel;using NPOI.XSSF.UserModel;using System.IO;using N ...

  5. CAFFE(四):Ubuntu 下安装jupyter notebook

    第一步.安装 pycaffe notebook 接口环境 在上一步成功安装 caffe 之后,就可以通过 caffe 去做训练数据集或者预测各种相关的事了,只不过需要在命令行下通过 caffe 命令进 ...

  6. namespace" 或The content of element type "mapper" must match "EMPTY"

    必须为元素类型 "mapper" 声明属性 "namespace" 或The content of element type "mapper" ...

  7. 关于JPype报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误的解决

    部署到线上的项目正常运行一年,今天早上突然报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误. JPyp ...

  8. 深入理解Java虚拟机——读书笔记

    首先 强烈推荐周志明老师的这本书,真的可以说是(起码中文出版界)新手了解Java虚拟机必须人手一本的教科书!!!   第二部分自动内存管理机制 由于Java虚拟机的多线程是通过线程轮流切换并分配处理器 ...

  9. Python求均值,方差,标准差

    import numpy as nparr = [1,2,3,4,5,6]#求均值arr_mean = np.mean(arr)#求方差arr_var = np.var(arr)#求标准差arr_st ...

  10. tsung报告中Transactions Statistics缺失问题

    长时间没有做性能测试,最近在使用tsung进行性能测试时,修改tsung自带的范例脚本后,运行查看结果时,发现测试报告中transactions  statistics缺失,刚开始一直以为是监控中的配 ...