通过查找表对比特率选择
比特率是指每秒传送的比特(bit)数。单位为 bps(Bit Per Second),比特率越高,传送数据速度越快.但是通过串口通信使用波特率,必须保证发端和收端波特率保持一致,不至于丢失数据,导致数据错误
//关键代码
//建立查找表--比特率选择
reg [15:0]bps_max;//分频计数最大值
always @(posedge clk or negedge rst_n)
if(!rst_n)
bps_max <= 16'd5207;
else begin
case (baud_set)
0: bps_max <= 16'd5207;//9600
1: bps_max <= 16'd2603;//19200
2: bps_max <= 16'd1301;//38400
3: bps_max <= 16'd867;//57600
4: bps_max <= 16'd433;//115200
default:bps_max <= 16'd5207;
endcase
end