参考设计之一:初始程序(包括LED,BTN,LCD;VHDL源码部分)
上一篇 / 下一篇 2008-06-10 22:56:10 / 个人分类:参考设计
-- 黑色矩阵 FPGA+USB 开发板 参考设计之一:初始程序
V1URM+O2s-[^6SzP0-- 用于测试开发板的基本功能模块,包括:LED,BTN, LCDEDA中国门户网站
OUC!R1B;`8su
--
2Da,i2~H0--
kBK4Q IWH0-- Reference design - Initial design for Black Matrix FPGA+USB Starter Kit when delivered.
:}4k(V,\P0--
#~9U%yS;M ]S;M0-- Email: spartan3@163.com
7N%s,O'nE^0--EDA中国门户网站C}k)n4j G
-- All rights reserved.EDA中国门户网站yy9Q;u @DZebcR
--EDA中国门户网站6K#_b|3~^ dO
-- Introduction:EDA中国门户网站&u+AW:OGq
--EDA中国门户网站jf"h9uJ4BSd
-- This design use LED, BTN and LCD to show the board is working OK!EDA中国门户网站,n5yj:F?
`
--EDA中国门户网站$Z"O4hH0Us
-- PicoBlaze is included.EDA中国门户网站\.hG|i,c.hx
--EDA中国门户网站IxJ4tQ5] Hq
--
E.KG2M|!MrV!i0-- Library declarationsEDA中国门户网站y?VrN9T8W!f/ha
--
CD"dX8}*Y(t*D']"Uw0-- Standard IEEE libraries
P&wl{:p.S0--
2rS1b2d1GE:C0library IEEE;
9X\*u V:Ye(I2E0use IEEE.STD_LOGIC_1164.ALL;
c$g
N1trw+V0use IEEE.STD_LOGIC_ARITH.ALL;
!I1GZ.X5w0use IEEE.STD_LOGIC_UNSIGNED.ALL;
C(q|*q&R0?F#EZ0--EDA中国门户网站A2L)R
F/k&K8e
------------------------------------------------------------------------------------
7Cd7AM)OJ0--
,BH/`uc0--EDA中国门户网站tR2n${-HT1d$K)^0X(c
entity blackmatrix_startup isEDA中国门户网站3Z0ykQ4s
Port ( led : out std_logic_vector(3 downto 0);EDA中国门户网站F
oW#['rvd"p
led_sys : out std_logic;EDA中国门户网站&da\7vjEz+pZ
btn_rst : in std_logic;
%mh&zq7[+pV0 btn_left : in std_logic;EDA中国门户网站&F4T
stn
[;A\!k
btn_right : in std_logic;
Y%M&M[2Bwd0 lcd_d : inout std_logic_vector(7 downto 4);EDA中国门户网站6[5yX8l/a
lcd_rs : out std_logic;
0B3jZ*aH/Z0 lcd_rw : out std_logic;EDA中国门户网站i(G_%@'WA%_4C
lcd_e : out std_logic;EDA中国门户网站QG1cMX
clk : in std_logic);EDA中国门户网站9v+IB;w+G-zft t
end blackmatrix_startup;
$}9`AdB+}0--
^Z
h'UVw&X;tx0------------------------------------------------------------------------------------EDA中国门户网站NTL:^%l!d|$D
--
]'N)`
^I#D,I*o0-- Start of test architectureEDA中国门户网站3r*B@}l$o[|
\
--EDA中国门户网站uW!m kk M!n
architecture Behavioral of blackmatrix_startup is
i)U&b1ipMe?5w0--
:CHkKob1F0q0------------------------------------------------------------------------------------
ct~kb9x}P q0--
T!M*x9wQ;J0-- declaration of KCPSM3
q \^{({:B0--
j0R?A8e0 component kcpsm3 EDA中国门户网站+C
mX7u5ATJ?f@
Port ( address : out std_logic_vector(9 downto 0);EDA中国门户网站8s^J _t?*AJ
instruction : in std_logic_vector(17 downto 0);EDA中国门户网站M
K3Jq&f2[ |
port_id : out std_logic_vector(7 downto 0);EDA中国门户网站#I0x}ZqCQ
write_strobe : out std_logic;
r1N"EXN0 out_port : out std_logic_vector(7 downto 0);EDA中国门户网站(H:L,Yt.ug
read_strobe : out std_logic;EDA中国门户网站\ Q6m+`6]?
in_port : in std_logic_vector(7 downto 0);EDA中国门户网站4t,Zq$[0QT'\
interrupt : in std_logic;
,cj[X
P0 interrupt_ack : out std_logic;
'o7o7NX0J6i"_A0_V0 reset : in std_logic;
3v
a7k^kZ*d:z0 clk : in std_logic);
R;rg6}k|Jg0 end component;EDA中国门户网站!X6pY+y)|;l
--
B0^Y-d0RQC0Z0-- declaration of program ROM
];Q(s
yl;_y0--
:s
A9n)k5E&jH0 component control
{(I[']W5g(Jc&\0 Port ( address : in std_logic_vector(9 downto 0);EDA中国门户网站X-zS:IXSId)f%V
D
instruction : out std_logic_vector(17 downto 0);EDA中国门户网站7Z6Ufq!EVV2CYV'e
proc_reset : out std_logic; --JTAG Loader versionEDA中国门户网站7R8z'`*{1Gm"H
clk : in std_logic);EDA中国门户网站
McP DgojN3c0W|C
end component;
(N+Sy }/?u0--EDA中国门户网站?},@#}n#F
{{a-A\9a
------------------------------------------------------------------------------------EDA中国门户网站o*[2a6AT a0w"Dq
G@%Q
--EDA中国门户网站7Ym;r]5xh U?\
-- Signals used to connect KCPSM3 to program ROM and I/O logicEDA中国门户网站D z&SLz:s
d?D-q
--
U
bAwRT0signal address : std_logic_vector(9 downto 0);
FD}(l
oo$G,t0signal instruction : std_logic_vector(17 downto 0);EDA中国门户网站.uD-`R/b.tbj
signal port_id : std_logic_vector(7 downto 0);
(f
]A&i;i0signal out_port : std_logic_vector(7 downto 0);EDA中国门户网站 ``Fq8JE4t:H}
signal in_port : std_logic_vector(7 downto 0);
/_C(iKk#x'x*Y
v8I?m0signal write_strobe : std_logic;EDA中国门户网站C)[%}eD"@}5N1|$\s&nP
signal read_strobe : std_logic;
\P'f1Qrs'C*Nh1H0signal interrupt : std_logic :='0';EDA中国门户网站8brhfap
signal interrupt_ack : std_logic;EDA中国门户网站$J;tC-H;j
signal interrupt_event : std_logic;EDA中国门户网站
j7wrn&g)A^2Z$H
--EDA中国门户网站IQ8? Gztt~
--EDA中国门户网站:P%xo/wb|
-- Signals for LCD operation
7d#^2Bmrz5aH0--EDA中国门户网站Y(M-P!d!|
-- Tri-state output requires internal signalsEDA中国门户网站8mW3a
b
n@o
-- 'lcd_drive' is used to differentiate between LCD and StrataFLASH communications EDA中国门户网站&W"smpY:M/Q
-- which share the same data bits.EDA中国门户网站forhgoF
Q
--EDA中国门户网站z@%t~o8y
signal lcd_rw_control : std_logic;
!F_ G
`/JJv
v0signal lcd_output_data : std_logic_vector(7 downto 4);EDA中国门户网站Jgt*DP3]
signal lcd_drive : std_logic;
f"~ Z;h5p,q(p7a0--EDA中国门户网站ps c(@$@-wc#JM*M%s
--EDA中国门户网站@5ZR*hzl!QD
--EDA中国门户网站K*aHMq+nr
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#{4LW8Va7fE3K0--EDA中国门户网站Zt3h9i tW2WM
-- Start of circuit descriptionEDA中国门户网站,v"Se:B`C
--EDA中国门户网站O6H-vd7y7e[A
begin
----------------------------------------------------------------------------------------------------------------------------------EDA中国门户网站x+m|L
V |g/S
-- KCPSM3 and the program memory EDA中国门户网站}Hj Tp)~7|
----------------------------------------------------------------------------------------------------------------------------------
J Z;Z cCJ0x0o+S:q a0 --EDA中国门户网站(}Hm)Y|ZD
|gi6Z-gE"u0 processor: kcpsm3
0Uzb&?#|JP)I$\0 port map( address => address,EDA中国门户网站:Yy)s8SR+_J
instruction => instruction,EDA中国门户网站Mq;t6g8wZ%yL
port_id => port_id,
CitH0^/A0 write_strobe => write_strobe,EDA中国门户网站*h j7qK8] O1O
out_port => out_port,
d/CHgAj)t5UDp0 read_strobe => read_strobe,
5oeA@\N,aW0 in_port => in_port,EDA中国门户网站v/Q%Tp
LrBt
interrupt => interrupt,EDA中国门户网站;@7S)@3MB0v
interrupt_ack => interrupt_ack,EDA中国门户网站5J"ok@:h![&RK
reset => btn_rst,
;l`1ZYx,I)x0 clk => clk);
-{0V!uRtC0
{+w0H]j.v0 program_rom: control
`FB[s
s@8l0 port map( address => address,EDA中国门户网站a1z$Z(o
FX
instruction => instruction,EDA中国门户网站*Pav*p x6]D'Mp+h
proc_reset => btn_rst,
MO
^)cc"TGt-V;y0 clk => clk);
f!EkbQ.fzJ4}/A0 --EDA中国门户网站9C0j3y2F"C`,o2J
----------------------------------------------------------------------------------------------------------------------------------
sj0ss2Y:k3L/?0 -- Interrupt
tA8|Q`5|p aK`0 ----------------------------------------------------------------------------------------------------------------------------------EDA中国门户网站.Wt`z9B
--
?#v;MT)O0 --
7v8t*R[3hA0 -- Interrupt is used to detect rotation of the rotary encoder.
Jt[
R8N0 -- It is anticipated that the processor will respond to interrupts at a far higher EDA中国门户网站$Z{B7A;X~c
-- rate that the rotary control can be operated and hence events will not be missed.
V'uUc5y}7~o`0 --
?1a%\bor0 interrupt_control: process(clk)
y\'l jo/K0 begin
tF4PF7m:_0 if clk'event and clk='1' thenEDA中国门户网站
[g;j(K5z
cGf/NG Q0 -- processor interrupt waits for an acknowledgementEDA中国门户网站;xl5M$L*N.^8K)rr
if interrupt_ack='1' then
\]4lzXy0 interrupt <= '0';EDA中国门户网站Y!?NLj$B'V
elsif interrupt_event='1' then
9M%V
B{7hZk-l0 interrupt <= '1';
,} Wj['@da5a
S0 else
1^*B{^k@&[0 interrupt <= interrupt;
r-DN+f&zz7[(P0 end if;
end if; EDA中国门户网站}-]
Y$|T.?l h B
end process interrupt_control;
mJ{^E5F0 --EDA中国门户网站Z8cN7^ lir
----------------------------------------------------------------------------------------------------------------------------------EDA中国门户网站b9j!L8]nWf;a ` B
-- KCPSM3 input ports
?x
T$hQV0 ----------------------------------------------------------------------------------------------------------------------------------EDA中国门户网站I.fe_lf
--EDA中国门户网站 WtRQP,l
--EDA中国门户网站Y Nsh$NG
-- The inputs connect via a pipelined multiplexer
)h)\{6Z7SQ5d}G[0 --
input_ports: process(clk)EDA中国门户网站
_&II@P5G}:R
beginEDA中国门户网站/EU)l#Rg'SY;NX
if clk'event and clk='1' then
case port_id(1 downto 0) is
rB%^ k Zz0 EDA中国门户网站 e|V'ApWK.s"Qxp_ -- read simple buttons at address 00 hex
6qLz$l U|9y
Sl0 when "00" => in_port <= "000000" & btn_right & btn_left;
(CA$z/Q(A+oz$q]0 -- read rs232 datain at address 01 hexEDA中国门户网站U2H6f/ReX'J
-- will include laterEDA中国门户网站}&J{9zF7B%c(e
-- when "01" => in_port <= uart_dout;
;zHx^0A3`0
T:ZDb%?3H[7y$g0 when thers => in_port <= "XXXXXXXX"; EDA中国门户网站COXo&|3~
end case;
4S:Cr x0T y03pXB:` {n6o8K2| zj0 end if;EDA中国门户网站AA y Z H
*Hg3LZ0BF e0 end process input_ports;EDA中国门户网站+`S/zQ(]g.q
EDA中国门户网站]C*z&^e{D\E2_Q
8ra];NZ'W@i ]LK0 --EDA中国门户网站s(H5p~tL
----------------------------------------------------------------------------------------------------------------------------------EDA中国门户网站%zur{wT2hSz[
-- KCPSM3 output ports
NJ4PRhr.Y0 ----------------------------------------------------------------------------------------------------------------------------------EDA中国门户网站*R1x0Al~;^$gEtJ
--
L!c.FhP)w8j g0 -- adding the output registers to the processorEDA中国门户网站 oUX_)Ac
EDA中国门户网站sEGpU7h
x$bS
output_ports: process(clk)
i9~2^TZ0 beginEDA中国门户网站B;K_ A#}{#F7J.n9Xh,Pn
if clk'event and clk='1' thenEDA中国门户网站 yG^/z-z${o
if write_strobe='1' thenEDA中国门户网站,Q&D#B)d2l^
-- Write to LEDs at address 80 hex.EDA中国门户网站4Ni{,h ^w8sk%N
#z&]DO!qemX0 if port_id(7)='1' thenEDA中国门户网站 m T;\4fN%[`
led <= out_port(3 downto 0);EDA中国门户网站{2j*NZ%^2L
led_sys <= out_port(4);EDA中国门户网站Zme2l*O
end if;
cU[nO4PG.Z0 -- LCD data output and controls at address 40 hex.EDA中国门户网站]_D8SsC| \@
EDA中国门户网站8|fs N N(m3w if port_id(6)='1' thenEDA中国门户网站*{ w,[K3f/I*G9W
lcd_output_data <= out_port(7 downto 4);EDA中国门户网站9xl-ySGsjW%l
lcd_drive <= out_port(3);
~4f`_u#l}d#G5[1_0 lcd_rs <= out_port(2);
(PZ;re2Br"b,S0 lcd_rw_control <= out_port(1);EDA中国门户网站u2v/h3l(F&Ez&F/O
lcd_e <= out_port(0);
$|1HENuO"K0 end if;
end if;
e'`b Z'QrF0 EDA中国门户网站J$XLn4vR+TA7^3d0}end if;
h(Pi"p,[$R\h06QFZ)iH;uy0 end process output_ports;EDA中国门户网站-df8[k K&y+x
EDA中国门户网站;j*@uX~0I$Z --EDA中国门户网站gh'uR&g
----------------------------------------------------------------------------------------------------------------------------------
k;X7l9]-H }0 -- LCD interface EDA中国门户网站/H&}FZ `
----------------------------------------------------------------------------------------------------------------------------------
1p+H1fo/]A+j"~Ls4A0 --EDA中国门户网站7z1ehP5p
zh*O
-- The 4-bit data port is bidirectional.EDA中国门户网站vp&k
|F*YO)d
-- lcd_rw is '1' for read and '0' for write EDA中国门户网站[["go5{{
-- lcd_drive is like a master enable signal which prevents either the
!\2N4~5Xb0 -- FPGA outputs or the LCD display driving the data lines.EDA中国门户网站&g.pVs$kG@;q
--