新聞中心

Verilog串口UART程序

作者: 時間:2012-03-25 來源:網(wǎng)絡(luò) 收藏

if (!rx_busy !rx_d2) begin
rx_busy = 1;
rx_sample_cnt = 1;
rx_cnt = 0;
end
// Start of frame detected, Proceed with rest of data
if (rx_busy) begin
rx_sample_cnt = rx_sample_cnt + 1;
// Logic to sample at middle of data
if (rx_sample_cnt == 7) begin
if ((rx_d2 == 1) (rx_cnt == 0)) begin
rx_busy = 0;
end else begin
rx_cnt = rx_cnt + 1;
// Start storing the rx data
if (rx_cnt > 0 rx_cnt 9) begin
rx_reg[rx_cnt - 1] = rx_d2;
end
if (rx_cnt == 9) begin
rx_busy = 0;
// Check if End of frame received correctly
if (rx_d2 == 0) begin
rx_frame_err = 1;
end else begin
rx_empty = 0;
rx_frame_err = 0;
// Check if last rx data was not unloaded,
rx_over_run = (rx_empty) ? 0 : 1;
end
end
end
end
end
end
if (!rx_enable) begin
rx_busy = 0;
end
end

// TX Logic
always @ (posedge txclk or posedge reset)
if (reset) begin
tx_reg = 0;
tx_empty = 1;
tx_over_run = 0;
tx_out = 1;
tx_cnt = 0;
end else begin
if (ld_tx_data) begin
if (!tx_empty) begin
tx_over_run = 0;
end else begin
tx_reg = tx_data;
tx_empty = 0;
end
end
if (tx_enable !tx_empty) begin
tx_cnt = tx_cnt + 1;
if (tx_cnt == 0) begin
tx_out = 0;
end
if (tx_cnt > 0 tx_cnt 9) begin
tx_out = tx_reg[tx_cnt -1];
end
if (tx_cnt == 9) begin
tx_out = 1;
tx_cnt = 0;
tx_empty = 1;
end
end
if (!tx_enable) begin
tx_cnt = 0;
end
end

endmodule

本文引用地址:http://2s4d.com/article/149350.htm
上一頁 1 2 下一頁

關(guān)鍵詞: 程序 UART 串口 Verilog

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉