基于FPGA的UART接口模塊設(shè)計(jì)
發(fā)送模塊由發(fā)送控制進(jìn)程、寫(xiě)數(shù)據(jù)進(jìn)程、并/串轉(zhuǎn)換進(jìn)程、狀態(tài)操作進(jìn)程等進(jìn)程構(gòu)成。其中,最主要的是發(fā)送控制進(jìn)程,在發(fā)送控制進(jìn)程中聲明了一個(gè)6比特的變量scit_v,由它的取值(狀態(tài)機(jī))狀態(tài)來(lái)控制整個(gè)發(fā)送過(guò)程。scit_v被分為高四位的sh_t和低兩位的sl_,tscit_v在系統(tǒng)復(fù)位后被賦初值28(011100B),每來(lái)一個(gè)時(shí)鐘scit_v增量,每來(lái)四個(gè)時(shí)鐘sh_t增量,當(dāng)sh_t為0111B時(shí)發(fā)送起始位,sh_t為1000~1111B時(shí)發(fā)送8比特的數(shù)據(jù)。下面給出的是發(fā)送控制進(jìn)程和發(fā)送接收數(shù)據(jù)進(jìn)程的原代碼:
-----數(shù)據(jù)發(fā)送控制進(jìn)程-----
PROCESS(clk,reset)
variablescit_v:integerrange0to63;
variablescit_s:std_logic_vector(tdownto0);
BEGIN
IF(reset=0')'THEN
scit_v:=0;--000000
ELSIF(clkE'VENTANDclk=1')'THEN
IF(scit_v=27)THEN
IF(tdEMPTY_s=0''ANDwr=1')'THEN
scit_v:=28;--sci_v=011100
ELSE
scit_v:=0;
ENDIF;
ELSE
scit_v:=scit_v+1;
ENDIF;
ENDIF;
scit_s:=conv_std_logic_vector(scit_v,6);
scit=TO_STDULOGICVECTOR(scit_s);
ENDPROCESS;
------數(shù)據(jù)的串行發(fā)送-----
PROCESS(sh_t)
BEGIN
CASEsh_tIS
WHEN0111=>txd=0';'
WHEN1000=>txd=din_latch(0);
WHEN1001=>txd=din_latch(1);
WHEN1010=>txd=din_latch(2);
WHEN1011=>txd=din_latch(3);
WHEN1100=>txd=din_latch(4);
WHEN1101=>txd=din_latch(5);
WHEN1110=>txd=din_latch(6);
WHEN1111=>txd=din_latch(7);
WHENOTHERS=>txd=1';'
ENDCASE;
ENDPROCESS;
圖3給出的是發(fā)送數(shù)據(jù)的仿真圖。當(dāng)CS和WR有效時(shí)寫(xiě)入數(shù)據(jù)55H,同時(shí)EMPTY被置成無(wú)效狀態(tài),開(kāi)始數(shù)據(jù)的發(fā)送,從圖中可以看到TXD上電平的變化過(guò)程,當(dāng)發(fā)送結(jié)束后EMPTY變?yōu)橛行А?/p>
圖3 發(fā)送數(shù)據(jù)的仿真波形
評(píng)論