




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
URAT VHDL程序-仿真。1. 顶层程序与仿真(1)顶层程序-文件名:top.vhd。-功能:顶层映射。-最后修改日期:2004.3.24。library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity top is Port (clk32mhz,reset,rxd,xmit_cmd_p_in:in std_logic; -总的输入输出信号的定义 rec_ready,txd_out,txd_done_out:out std_logic; txdbuf_in:in std_logic_vector(7 downto 0); -待发送数据输入 rec_buf:out std_logic_vector(7 downto 0); -接收数据缓冲end top;architecture Behavioral of top iscomponent reciever Port (bclkr,resetr,rxdr:in std_logic; r_ready:out std_logic; rbuf:out std_logic_vector(7 downto 0);end component;component transfer Port (bclkt,resett,xmit_cmd_p:in std_logic; txdbuf:in std_logic_vector(7 downto 0); txd:out std_logic; txd_done:out std_logic);end component;component baud Port (clk,resetb:in std_logic; bclk:out std_logic);end component;signal b:std_logic;beginu1:baud port map(clk=clk32mhz,resetb=reset,bclk=b); -顶层映射u2:reciever port map(bclkr=b,resetr=reset,rxdr=rxd,r_ready=rec_ready, rbuf=rec_buf);u3:transfer port map(bclkt=b,resett=reset,xmit_cmd_p=xmit_cmd_p_in, txdbuf=txdbuf_in,txd=txd_out,txd_done=txd_done_out);end Behavioral;(2)程序仿真仿真波形图如图8.8.5所示。图8.8.5 仿真波形2. 波特率发生器程序与仿真(1)波特率发生器VHDL程序-文件名:baud.vhd.-功能:将外部输入的32MHz的信号分成频率为153600Hz的信号。-最后修改日期:2004.3.24。library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity baud is Port (clk,resetb:in std_logic; bclk:out std_logic);end baud;architecture Behavioral of baud isbeginprocess(clk,resetb)variable cnt:integer;begin if resetb=1 then cnt:=0; bclk=208 then cnt:=0; bclk=1; -设置分频系数 else cnt:=cnt+1; bclk=0; end if; end if;end process;end Behavioral;(2)程序仿真仿真波形如图8.8.6所示。图8.8.6 波特率发生器的仿真波形3. UART发送器程序与仿真(1)UART发送器VHDL程序-文件名:transfer.vhd。-功能:UART发送器。-说明:系统由五个状态(x_idle,x_start,x_wait,x_shift,x_stop)和一个进程构成。-最后修改日期:2004.3.24。library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity transfer is generic(framlent:integer:=8); Port (bclkt,resett,xmit_cmd_p:in std_logic; -定义输入输出信号 txdbuf:in std_logic_vector(7 downto 0):=11001010; txd:out std_logic; txd_done:out std_logic);end transfer;architecture Behavioral of transfer istype states is (x_idle,x_start,x_wait,x_shift,x_stop); -定义个子状态signal state:states:=x_idle;signal tcnt:integer:=0;beginprocess(bclkt,resett,xmit_cmd_p,txdbuf) -主控时序、组合进程variable xcnt16:std_logic_vector(4 downto 0):=00000; -定义中间变量variable xbitcnt:integer:=0;variable txds:std_logic;begin if resett=1 then state=x_idle; txd_done -状态1,等待数据帧发送命令if xmit_cmd_p=1 then state=x_start;txd_done=0;else state -状态2,发送信号至起始位if xcnt16=01111 then state=x_wait; xcnt16:=00000;else xcnt16:=xcnt16+1; txds:=0; state -状态3,等待状态if xcnt16=01110 then if xbitcnt=framlent then state=x_stop; xbitcnt:=0; else state=x_shift; end if; xcnt16:=00000; else xcnt16:=xcnt16+1; statetxds:=txdbuf(xbitcnt); xbitcnt:=xbitcnt+1; state -状态5,停止位发送状态if xcnt16=01111 then if xmit_cmd_p=0 then state=x_idle; xcnt16:=00000; else xcnt16:=xcnt16; state=x_stop; end if; txd_done=1;else xcnt16:=xcnt16+1; txds:=1; statestate=x_idle; end case; end if; txd=txds;end process;end Behavioral;UART发送器的仿真波形如图8.8.7所示。图8.8.7 UART发送器的仿真波形4. UART接收器程序与仿真(1)UART接收器VHDL程序-文件名:reciever.vhd。-功能:UART接受器。-说明:系统由五个状态(r_start,r_center,r_wait,r_sample,r_stop)和两个进程构成-最后修改日期:2004.3.24。library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity reciever isgeneric(framlenr:integer:=8); Port (bclkr,resetr,rxdr:in std_logic; -定义输入输出信号 r_ready:out std_logic; rbuf:out std_logic_vector(7 downto 0);end reciever;architecture Behavioral of reciever istype states is (r_start,r_center,r_wait,r_sample,r_stop); -定义各子状态signal state:states:=r_start;signal rxd_sync:std_logic;beginpro1:process(rxdr)begin if rxdr=0 then rxd_sync=0; else rxd_sync=1; end if;end process;pro2:process(bclkr,resetr,rxd_sync) -主控时序、组合进程variable count:std_logic_vector(3 downto 0); -定义中间变量variable rcnt:integer:=0;variable rbufs:std_logic_vector(7 downto 0);begin if resetr=1 then state -状态1,等待起始位if rxd_sync=0 then state=r_center; r_ready=0; rcnt:=0;else state=r_start; r_ready -状态2,求出每位的中点if rxd_sync=0 then if count=0100 then state=r_wait; count:=0000;else count:=count+1; state=r_center;end if;else state -状态3,等待状态if count=1110 thenif rcnt=framlenr then state=r_stop; else state=r_samp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025化工原料采购销售合同范本参考
- 2025年自建房设计与施工一体化合同协议书
- 患者的心理护理
- 2025年吉林省长春市宽城区中考二模英语试卷
- 招投标实务操作
- 医学检验技术分析模板
- NC6应付管理培训
- 途牛:2022国庆旅游消费趋势报告
- 八年级语文上册《大自然的语言》教学设计
- 三下乡社会实践个人工作总结模版
- MOOC 企业文化与商业伦理-东北大学 中国大学慕课答案
- 保洁突发事件应急培训
- 中医学理论体系的形成和发展
- 中医养生五脏
- 篮球研究报告
- 第12课+自觉抵制犯罪(课时2)【中职专用】中职思想政治《职业道德与法治》高效课堂(高教版2023·基础模块)
- 泪道置管的护理课件
- 造影剂脑病护理查房课件
- 体育场馆充值协议
- 电力铁塔制造培训资料
- Unit+2+Lesson+3+Getting+To+The+Top-高中英语北师大版选择性必修第一册+
评论
0/150
提交评论