51单片机与fpga进行串行通信

51单片机与fpga进行串行通信

ID:35718873

大小:18.51 KB

页数:11页

时间:2019-04-14

51单片机与fpga进行串行通信_第1页
51单片机与fpga进行串行通信_第2页
51单片机与fpga进行串行通信_第3页
51单片机与fpga进行串行通信_第4页
51单片机与fpga进行串行通信_第5页
资源描述:

《51单片机与fpga进行串行通信》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、51单片机与fpga进行串行通信,并显示到LCD上。下面给出串口通信USart部分程序:1.FPGA程序:Module1(协议部分):Libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;--Uncommentthefollowinglibrarydeclarationifusing--arithmeticfunctionswithSignedorUnsignedvalues--useIEEE.NUMERIC

2、_STD.ALL;--Uncommentthefollowinglibrarydeclarationifinstantiating--anyXilinxprimitivesinthiscode.--libraryUNISIM;--useUNISIM.VComponents.all;entitytxisport(din:instd_logic_vector(7downto0);sout:outstd_logic;clk:instd_logic;len_r:outstd_Logic_vector(3downto0);txclk:instd_logic)

3、;endtx;architectureBehavioraloftxistypesis(start,shift,stop,delay1,delay2);--typesis(start1,shift1,stop1,delay1,start2,shift2,stop2,delay2,start3,shift3,stop3,delay3,start4,shift4,stop4,delay4);signalstate:s:=start;signaltxcnt_r,len:std_logic_vector(3downto0);signalsout1:std_l

4、ogic;signalthr:std_logic_vector(7downto0);signalclk1:std_logic;beginprocess(txclk)beginiftxclk='1'andtxclk'eventthenthr<=din;endif;endprocess;process(txclk)variabletsr:std_logic_vector(7downto0);variablecount:integerrange0to480:=0;variablecount1:integerrange0to4800:=0;beginift

5、xclk='1'andtxclk'eventthencasestateiswhenstart=>tsr:=thr;sout1<='0';--传输起始位txcnt_r<=(others=>'0');--传输数据位数计数清0state<=shift;whenshift=>sout1<=tsr(0);--数据位传输第1位数据tsr(6downto0):=tsr(7downto1);--填充数据tsr(7):='0';txcnt_r<=txcnt_r+1;if(txcnt_r=7)thenstate<=stop;endif;whenstop=>sout1<

6、='1';state<=delay1;whendelay1=>ifcount<120thencount:=count+1;elsecount:=0;iflen<7thenstate<=start;len<=len+1;elsestate<=delay2;endif;endif;whendelay2=>ifcount1<2400thencount1:=count1+1;elsecount1:=0;len<="0000";state<=start;endif;endcase;sout<=sout1;len_r<=len;endif;endprocess

7、;process(clk)variablenc:integerrange0to100000000:=0;beginifclk='1'andclk'eventthenif(nc>50000000ornc<0)thennc:=0;endif;nc:=nc+1;if(nc>25000000)thenclk1<='0';elseclk1<='1';endif;endif;endprocess;--process(clk1)--begin--ifclk1='1'andclk1'eventthen--len<="000";--endif;--endproces

8、s;endBehavioral;Module2(数据发送部分):Libraryieee;useieee.std_logic

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。