【正文】
k) begin if(send == 139。b1) begin case(t) //產(chǎn)生起始位 839。d0: begin tx = 139。b0。 idle = 139。b1。 t = t + 839。d1。 end 839。d16: begin tx = datain[0]。 //發(fā)送數(shù)據(jù) 0 位 presult = datain[0]^paritymode。 idle = 139。b1。 t = t + 839。d1。 end 839。d32: begin tx = datain[1]。 //發(fā)送數(shù)據(jù) 1 位 presult = datain[1]^presult。 idle = 139。b1。 t = t + 839。d1。 end 839。d48: begin tx = datain[2]。 //發(fā)送數(shù)據(jù) 2 位 presult = datain[2]^presult。 idle = 139。b1。 t = t + 839。d1。 end 839。d64: 12 begin tx = datain[3]。 //發(fā)送數(shù)據(jù) 3 位 presult = datain[3]^presult。 idle = 139。b1。 t = t + 839。d1。 end 839。d80: begin tx = datain[4]。 //發(fā)送數(shù)據(jù) 4 位 presult = datain[4]^presult。 idle = 139。b1。 t = t + 839。d1。 end 839。d96: begin tx = datain[5]。 //發(fā)送數(shù)據(jù) 5 位 presult = datain[5]^presult。 idle = 139。b1。 t = t + 839。d1。 end 839。d112: begin tx = datain[6]。 //發(fā)送數(shù)據(jù) 6 位 presult = datain[6]^presult。 idle = 139。b1。 t = t + 839。d1。 end 839。d128: begin tx = datain[7]。 //發(fā)送數(shù)據(jù) 7 位 presult = datain[7]^presult。 idle = 139。b1。 t = t + 839。d1。 end 839。d144: begin tx = presult。 //發(fā)送奇偶校驗(yàn)位 presult = datain[0]^paritymode。 idle = 139。b1。 t = t + 839。d1。 end 839。d160: begin tx = 139。b1。 //發(fā)送停止位 idle = 139。b1。 t = t + 839。d1。 13 end 839。d176: begin tx = 139。b1。 idle = 139。b0。 //一幀資料發(fā)送結(jié)束 t = t + 839。d1。 end default: begin t = t + 839。d1。 end endcase end else begin tx = 139。b1。 t = 839。d0。 idle = 139。b0。 end end endmodule 接收模塊程序: module uartrx(clk, rx, dataout, rdsig, dataerror, frameerror)。 input clk。 //采樣時(shí)鐘 input rx。 //UART 數(shù)據(jù)輸入 output dataout。 //接收數(shù)據(jù)輸出 output rdsig。 output dataerror。 //資料出錯(cuò)指示 output frameerror。 //幀出錯(cuò)指示 reg[7:0] dataout。 reg rdsig, dataerror。 reg frameerror。 reg [7:0] t。 reg rxbuf, rxfall, receive。 parameter paritymode = 139。b0。 reg presult, idle。 always @(posedge clk) //檢測(cè)線路的下降沿 begin rxbuf = rx。 rxfall = rxbuf amp。 (~rx)。 end always @(posedge clk) begin if (rxfall amp。amp。 (~idle)) //檢測(cè)到線路的下降沿并且原先線路為空閑,啟動(dòng)接收數(shù)據(jù)進(jìn)程 14 begin receive = 139。b1。 end else if(t == 839。d175) //接收數(shù)據(jù)完成 begin receive = 139。b0。 end end always @(posedge clk) begin if(receive == 139。b1) begin case (t) 839。d0: begin idle = 139。b1。 t = t + 839。d1。 rdsig = 139。b0。 end 839。d24: //接收第 0 位數(shù)據(jù) begin idle = 139。b1。 dataout[0] = rx。 presult = paritymode^rx。 t = t + 839。d1。 rdsig = 139。b0。 end 839。d40: //接收第 1 位數(shù)據(jù) begin idle = 139。b1。 dataout[1