【正文】
0。 when others= cs=39。139。 shift=1111。 data_ledin=1111。 end case。 end if。end process。process (data_ledin) 譯碼begin case data_ledin is when0000=data_led=11000000。0 when0001=data_led=11111001。1 when0010=data_led=10100100。2 when0011=data_led=10110000。3 when0100=data_led=10011001。4 when0101=data_led=10010010。5 when0110=data_led=10000010。6 when0111=data_led=11111000。7 when1000=data_led=10000000。8 when1001=data_led=10010000。9 when1010=data_led=11000000。 when others=data_led=11111111。No signal。 end case。end process。end Behavioral。library IEEE。use 。use 。use 。 Unment the following lines to use the declarations that are provided for instantiating Xilinx primitive ponents.library UNISIM。use 。entity mcfp is Port ( pwm_clk:in std_logic。 clk:in std_logic。 reset:in std_logic。 sel:in std_logic_vector(1 downto 0)。 正反轉(zhuǎn)信號(hào) 1為正轉(zhuǎn) 0為反轉(zhuǎn) control:out std_logic_vector(3 downto 0)。 qs:out std_logic)。end mcfp。architecture Behavioral of mcfp istype states is (st0,st1,st2,st3,st4,st5,st6,st7)。signal stx :states 。 四相八拍通電方式begin process (clk,reset,sel)begin if reset=39。139。 then stx=st0。 elsif clk39。event and clk=39。139。 then case stx is when st0=if pwm_clk=39。039。 then if sel=01 then stx=st1。 elsif sel=10 then stx=st7。 else stx=st0。 end if。 end if。 when st1=if pwm_clk=39。139。 then if sel=01 then stx=st2。 elsif sel=10 then stx=st0。 else stx=st1。 end if。 end if。 when st2=if pwm_clk=39。039。 then if sel=01 then stx=st3。 elsif sel=10 then stx=st1。 else stx=st2。 end if。 end if。 when st3=if pwm_clk=39。139。 then if sel=01 then stx=st4。 elsif sel=10 then stx=st2。 else stx=st3。 end if。 end if。 when st4=if pwm_clk=39。039。 then if sel=01 then stx=st5。 elsif sel=10 then stx=st3。 else stx=st4。 end if。 end if。 when st5=if pwm_clk=39。139。 then if sel=01 then stx=st6。 elsif sel=10 then stx=st4。 else stx=st5。 end if。 end if。 when st6=if pwm_clk=39。039。 then if sel=01 then stx=st7。 elsif sel=10 then stx=st5。 else stx=st6。 end if。 end if。 when st7=if pwm_clk=39。139。 then if sel=01 then stx=st0。 elsif sel=10 then stx=st6。 else stx=st7。 end if。 end if。 when others =stx= st0 。 end case。 end if。end process。 process(stx)狀態(tài)轉(zhuǎn)換進(jìn)程 前四位控制ABCD相 后四位使其余發(fā)光2極管熄滅begin case stx is when st0 =control=0111。qs=39。039。 when st1 =control=0011。qs=39。039。 when st2 =control=1011。qs=39。039。 when st3 =control=1001。qs=39。039。 when st4 =control=1101。qs=39。039。 when st5 =control=1100。qs=39。039。 when st6 =control=1110。qs=39。039。 when st7 =control=0110。qs=39。139。 when others =control=1111。qs=39。039。 end case。end process。 end Behavioral。 28