tsr(6 downto 0):=tsr(7 downto 1);
tsr(7):='0';
txcnt_r<=txcnt_r+1;
if (txcnt_r=7) then
state<=odd1;cou<=cou+1;
end if;
when odd1=> --奇校驗位
if oddb='1' then
sout1<='0';state<=stop1;
else
sout1<='1';state<=stop1;
end if;
when stop1=>
sout1<='1'; --停止位
if cou<4 then
state<=start1;
else
state<=start2;
end if;
when start2=>
tsr1:=thr(15 downto 8);
oddb2:=thr(15 downto 8);
sout1<='0'; --起始位
txcnt_r<=(others=>'0');
state<=shift2;
when shift2=>
oddb<=oddb2(7) xor oddb2(6) xor oddb2(5) xor oddb2(4) xor oddb2(3) xor oddb2(2) xor oddb2(1) xor oddb2(0);
sout1<=tsr1(0);--數(shù)據(jù)位
tsr1(6 downto 0):=tsr1(7 downto 1);
tsr1(7):='0';
txcnt_r<=txcnt_r+1;
if (txcnt_r=7) then
state<=odd2;
end if;
when odd2=> --奇校驗位
if oddb='1' then
sout1<='0';state<=stop2;
else
sout1<='1';state<=stop2;
end if;
when stop2=>
sout1<='1'; --停止位
if len="0000000000000000" then
state<=stop2;
else
state<=start1;
len<=len-1;
end if;
end case;
end if;
end process;
sout<=sout1;
end behav;
其中各信號的說明已在程序中標(biāo)明了。波形仿真圖如圖1所示。
圖中Din寫入值為3355H,波特率為2400Hz,Start信號始終置邏輯1,即隨時都能發(fā)送數(shù)據(jù)。Reset信號邏輯1時復(fù)位,邏輯0時電路開始工作。THR是數(shù)據(jù)寄存器,文件頭、數(shù)據(jù)長度以及數(shù)據(jù)位都先寄存到THR中,Len是數(shù)據(jù)長度,TSR是低8位數(shù)據(jù)幀寄存器,TSR1是高8位數(shù)據(jù)幀寄存器。數(shù)據(jù)長度Len定為02H,發(fā)送時先發(fā)送低8位55H,后發(fā)送高8位33H,一共發(fā)送兩遍。發(fā)送的數(shù)據(jù)格式說明:當(dāng)發(fā)送55H時,其二進(jìn)制為01010101,則發(fā)送的數(shù)據(jù)的二進(jìn)制數(shù)為00101010111(1位開始位+8位數(shù)據(jù)位+1位奇校驗位+1位停止位)。
單片機部分先對FPGA發(fā)送過來的文件頭進(jìn)行確認(rèn),正確就接收文件,否則放棄接收的數(shù)據(jù)。根據(jù)FPGA發(fā)送模塊的協(xié)議,對串口控制寄存器SCON和波特率控制寄存器PCON的設(shè)置即可實現(xiàn)。
3 總結(jié)
目前電子產(chǎn)品的開發(fā)中經(jīng)常要綜合運用EDA技術(shù)、計算機控制技術(shù)、數(shù)字信號處理技術(shù),那么電路各部分經(jīng)常需要數(shù)據(jù)交換。本文也是基于此給出這方面應(yīng)用的實例,供開發(fā)者交流。





