|
ceooo
- 正班长
- 8
- 80
- 2006-05-08
|
54#
t
T
发表于 2006-05-09 00:54
|只看该用户
Re:资料共享处:请大家把有用的资料都传上来吧!
谢谢大家,我是个初学者,这些对我比较有用,谢谢你们, 我有个AHDL的程序,要改成VHDL 的,我的知识还没有到能修改的水平,大家能不能帮我看看啊. 利用ahdl (或者vhdl)语言进行全双工异步通信口设计,收发通信协议参见实验九内容(没有收录到本文档),具体内容如下: (1) cpld利用接收接口电路接收计算机发来的地址(或数据),进行译码并显示, (2) cpld将接收到的地址与本机地址相比较如果相符,则将输入端口的8位数据通过发送端口送给计算机。 (3) cpld全双工通信参考程序设计如下: (AHDL 程序已经写好了,是一本实验教材上提供的,和下面的VB程序配套,要求是用 VHDL 语言设计)。 -------------------------------------------AHDL语言描述--------------------------------------------------- subdesign data_sr&t (inclk,a[7..0],ina:input; outt,smga[6..0],smgb[6..0]  utput; ) --------------------------inclk 为系统时钟(22.1148MHZ);ina 为接收数据输入口;a[7..0]为待发的八位数据,可以是开关量,也可以--------------------------是A/D转换的输出;outt发送数据出口;smga[6..0],smgb[6..0]为接收数据译码显示接口。 variable ma[7..0],count[20..0]  ff; mb[7..0],mc[7..0],md[7..0]  ff; outt  ff; st[3..0]  ff; str[3..0]  ff; fp:dff; sint:dff; begin ma[].clk=inclk;fp.clk=inclk;sint.clk=inclk; ---------------------------发送时钟分频,fp为115200HZ,即发送的波特率为115200。 if ma[]==95 then ma[]=0;fp=!fp; else ma[]=ma[]+1;fp=fp; end if; ---------------------------发送状态机,辨别sint标志位,如果为高电平发送数据,否则发送停止位 outt.clk=fp; st[].clk=fp; if sint==gnd then outt=vcc;st[]=0; else case st[] is when 0 => if sint then st[]=1; else st[]=0; end if; outt=vcc; when 1=> outt=gnd; st[]=2; when 2=> outt=a0;st[]=3; when 3 => outt=a1;st[]=4; when 4 => outt=a2;st[]=5; when 5 => outt=a3;st[]=6; when 6 => outt=a4;st[]=7; when 7 => outt=a5;st[]=8; when 8 => outt=a6;st[]=9; when 9 => outt=a7;st[]=10; when 10 => outt=vcc; st[]=11; when 11 => outt=vcc; st[]=12; when 12 => outt=vcc; st[]=13; when 13 => outt=vcc;st[]=0; when 14 => outt=vcc;st[]=0; when others => outt=vcc;st[]=0; end case; end if; ---------------------------接收状态机 str[].clk=inclk; (mb[],mc[],md[]).clk=inclk; if sint then str[]=12; else if sint==gnd then str[]=0; end if; case str[] is when 0=> if ina then str[]=0; else if mc[]==11 then str[]=11;mc[]=0; else str[]=0;mc[]=mc[]+1; end if; end if; when 1 => if mc[]==192 then str[]=2;mc[]=0;mb0=mb0; else str[]=1; if mc[]==95 then mb0=ina;mc[]=mc[]+1; else mc[]=mc[]+1; mb0=mb0; end if; end if; when 2=> if mc[]>=192 then str[]=3;mc[]=0;mb[1..0]=mb[1..0]; else str[]=2; if mc[]==95 then mb1=ina;mc[]=mc[]+1;mb0=mb0; else mc[]=mc[]+1; mb[1..0]=mb[1..0]; end if; end if; when 3=> if mc[]==192 then str[]=4;mc[]=0;mb[2..0]=mb[2..0]; else str[]=3; if mc[]==95 then mb2=ina;mc[]=mc[]+1;mb[1..0]=mb[1..0]; else mc[]=mc[]+1; mb[2..0]=mb[2..0]; end if; end if; when 4=> if mc[]==192 then str[]=5;mc[]=0;mb[3..0]=mb[3..0]; else str[]=4; if mc[]==95 then mb3=ina;mc[]=mc[]+1; mb[2..0]=mb[2..0]; else mc[]=mc[]+1; mb[3..0]=mb[3..0]; end if; end if; when 5=> if mc[]==192 then str[]=6;mc[]=0;mb[4..0]=mb[4..0]; else str[]=5; if mc[]==95 then mb4=ina;mc[]=mc[]+1;mb[3..0]=mb[3..0]; else mc[]=mc[]+1; mb[4..0]=mb[4..0]; end if; end if; when 6=> if mc[]==192 then str[]=7;mc[]=0;mb[5..0]=mb[5..0]; else str[]=6; if mc[]==95 then mb5=ina;mc[]=mc[]+1;mb[4..0]=mb[4..0]; else mc[]=mc[]+1; mb[5..0]=mb[5..0]; end if; end if; when 7=> if mc[]==192 then str[]=8;mc[]=0;mb[6..0]=mb[6..0]; else str[]=7; if mc[]==95 then mb6=ina;mc[]=mc[]+1;mb[5..0]=mb[5..0]; else mc[]=mc[]+1; mb[6..0]=mb[6..0]; end if; end if; when 8=> if mc[]==192 then str[]=9;mc[]=0;mb[7..0]=mb[7..0]; else str[]=8; if mc[]==95 then mb7=ina;mc[]=mc[]+1;mb[6..0]=mb[6..0]; else mc[]=mc[]+1; mb[7..0]=mb[7..0]; end if; end if; when 9=> mb[]=mb[]; if mc[]==191 then str[]=10;mc[]=0; else str[]=9;mc[]=mc+1; end if; when 10=> if mc[]==192 then str[]=0;mc[]=0; else str[]=10;mc[]=mc[]+1; end if; when 11=> if mc[]>=180 then str[]=1;mc[]=0; else mc[]=mc[]+1; str[]=11; end if; mb[]=mb[]; when 12=> if sint then str[]=12; else if mc[]==100 then str[]=0;mc[]=0; else str[]=12;mc[]=mc[]+1; end if; end if; when others=> str[]=0; end case; -------------------------------地址码辨别,本机的地址码为十进制51(33H),如果相符则将sint置位,否则清零。 count[].clk=fp; if str[]==9 then if mb[]==51 then sint=vcc; else sint=gnd; end if; md[]=mb[]; else md[]=md[]; if st[]==12 then if count[]>=95500 then count[]=0;sint=gnd; else count[]=count[]+1; sint=sint; end if; else sint=sint; count[]=count[]; end if; end if; -----------------------------接收数据译码显示 TABLE md[3..0] => smga0,smga1,smga2,smga3,smga4,smga5,smga6; H"0" => 1,1,1,1,1,1,0; H"1" => 0,1,1,0,0,0,0; H"2" => 1,1,0,1,1,0,1; H"3" => 1,1,1,1,0,0,1; H"4" => 0,1,1,0,0,1,1; H"5" => 1,0,1,1,0,1,1; H"6" => 1,0,1,1,1,1,1; H"7" => 1,1,1,0,0,0,0; H"8" => 1,1,1,1,1,1,1; H"9" => 1,1,1,1,0,1,1; H"A" => 1,1,1,0,1,1,1; H"B" => 0,0,1,1,1,1,1; H"C" => 1,0,0,1,1,1,0; H"D" => 0,1,1,1,1,0,1; H"E" => 1,0,0,1,1,1,1; H"F" => 1,0,0,0,1,1,1; END TABLE; TABLE md[7..4] => smgb0,smgb1,smgb2,smgb3,smgb4,smgb5,smgb6; H"0" => 1,1,1,1,1,1,0; H"1" => 0,1,1,0,0,0,0; H"2" => 1,1,0,1,1,0,1; H"3" => 1,1,1,1,0,0,1; H"4" => 0,1,1,0,0,1,1; H"5" => 1,0,1,1,0,1,1; H"6" => 1,0,1,1,1,1,1; H"7" => 1,1,1,0,0,0,0; H"8" => 1,1,1,1,1,1,1; H"9" => 1,1,1,1,0,1,1; H"A" => 1,1,1,0,1,1,1; H"B" => 0,0,1,1,1,1,1; H"C" => 1,0,0,1,1,1,0; H"D" => 0,1,1,1,1,0,1; H"E" => 1,0,0,1,1,1,1; H"F" => 1,0,0,0,1,1,1; END TABLE; end; -------------------------------------------AHDL语言描述---------------------------------------------------
|