FPGA入门实验之串口发送
生活随笔
收集整理的這篇文章主要介紹了
FPGA入门实验之串口发送
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
要求
串口助手功能實現,5個按鍵,按一次輸出1種波特率的信號及他的一半波特率的信號,再按一次輸出另一種信號,依次對應。
代碼設計
## 分頻模塊 module frequency( input clk_50m,input rst, output BPS_CLK1,//輸出為不同波特率的信號output BPS_CLK2,output BPS_CLK3,output BPS_CLK4,output BPS_CLK5,output BPS_CLK6,output BPS_CLK7,output BPS_CLK8,output BPS_CLK9,output BPS_CLK10);reg [12:0]cnt_bps1=0;reg [12:0]cnt_bps2=0;reg [12:0]cnt_bps3=0;reg [12:0]cnt_bps4=0;reg [12:0]cnt_bps5=0;reg [12:0]cnt_bps6=0;reg [12:0]cnt_bps7=0;always@(posedge clk_50m or posedge rst)if(rst) //復位信號cnt_bps1<=0;else if(cnt_bps1==13'd5207) // 50_000_000/9600cnt_bps1<=0;elsecnt_bps1<=cnt_bps1+1;always@(posedge clk_50m or posedge rst)if(rst)cnt_bps2<=0;elseif(cnt_bps2==13'd2603) //19200cnt_bps2<=0;elsecnt_bps2<=cnt_bps2+1;always@(posedge clk_50m or posedge rst)if(rst)cnt_bps3<=0;elseif(cnt_bps3==13'd1301) //38400cnt_bps3<=0;elsecnt_bps3<=cnt_bps3+1;always@(posedge clk_50m or posedge rst)if(rst)cnt_bps4<=0;elseif(cnt_bps4==13'd867) //57600cnt_bps4<=0;elsecnt_bps4<=cnt_bps4+1;always@(posedge clk_50m or posedge rst)if(rst)cnt_bps5<=0;elseif(cnt_bps5==13'd433)cnt_bps5<=0;elsecnt_bps5<=cnt_bps5+1;always@(posedge clk_50m or posedge rst)if(rst)cnt_bps6<=0;elseif(cnt_bps6==13'd1301) //115200cnt_bps6<=0;elsecnt_bps6<=cnt_bps6+1; always@(posedge clk_50m or posedge rst)if(rst)cnt_bps7<=0;elseif(cnt_bps7==13'd215)cnt_bps7<=0;elsecnt_bps7<=cnt_bps7+1; assign BPS_CLK1=(cnt_bps1==13'd2604)?1:0;assign BPS_CLK2=(cnt_bps2==13'd1302)?1:0;assign BPS_CLK3=(cnt_bps3==13'd868)?1:0;assign BPS_CLK4=(cnt_bps4==13'd434)?1:0;assign BPS_CLK5=(cnt_bps5==13'd217)?1:0;assign BPS_CLK6=(cnt_bps2==13'd1302)?1:0;assign BPS_CLK7=(cnt_bps6==13'd651)?1:0;assign BPS_CLK8=(cnt_bps4==13'd434)?1:0;assign BPS_CLK9=(cnt_bps5==13'd217)?1:0;assign BPS_CLK10=(cnt_bps7==13'd018)?1:0; endmodule七個always語句里面分別產生對應波特率信號的計數。比如要產生9600的就應該是計數(系統時鐘50m除以9600)下。
## 按鍵模塊
按鍵計數,把按鍵當作使能信號,當按鍵按下,按鍵計數器計數,之后case語句判斷按鍵次數,然后賦值輸出對應波特率及他的一半;輸出為sen_clk與rec_clk。也就是按一次鍵會產生兩種波特率信號。
## 頂層文件
仿真波形
總結
以上是生活随笔為你收集整理的FPGA入门实验之串口发送的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FlexRay笔记
- 下一篇: VMware VMotion迁移与原理