2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
9 sys_clk : in std_logic;
10 sys_res_n : in std_logic;
12 new_data : in std_logic;
13 data : in std_logic_vector(7 downto 0);
16 s_take : out std_logic;
17 s_done : in std_logic;
18 s_backspace : out std_logic;
20 do_it : out std_logic;
21 finished : in std_logic
25 architecture beh of scanner is
26 type SCANNER_STATE is (SIDLE, SIGNORE_NEXT, SREAD_NEXT, STAKE, SDEL, SENTER);
27 signal state_int, state_next : SCANNER_STATE;
28 signal s_char_int, s_char_next : hbyte;
29 signal s_take_int, s_take_next : std_logic;
30 signal s_backspace_int, s_backspace_next : std_logic;
31 signal do_it_int, do_it_next : std_logic;
35 s_backspace <= s_backspace_int;
38 process(sys_clk, sys_res_n)
40 if sys_res_n = '0' then
44 s_char_int <= (others => '0');
46 s_backspace_int <= '0';
48 elsif rising_edge(sys_clk) then
50 state_int <= state_next;
52 s_char_int <= s_char_next;
53 s_take_int <= s_take_next;
54 s_backspace_int <= s_backspace_next;
55 do_it_int <= do_it_next;
60 process(state_int, new_data, data, finished, s_done)
62 state_next <= state_int;
66 if new_data = '1' then
69 state_next <= SIGNORE_NEXT;
71 state_next <= SREAD_NEXT;
76 when SC_KP_0 | SC_KP_1 | SC_KP_2 |
77 SC_KP_3 | SC_KP_4 | SC_KP_5 | SC_KP_6 |
78 SC_KP_7 | SC_KP_8 | SC_KP_9 |
79 SC_0 | SC_1 | SC_2 | SC_3 | SC_4 |
80 SC_5 | SC_6 | SC_7 | SC_8 | SC_9 |
81 SC_PLUS | SC_KP_PLUS |
82 SC_KP_MINUS | SC_KP_MUL | SC_SPACE =>
84 when others => state_next <= SIDLE;
88 if new_data = '1' then
92 if new_data = '1' then
95 state_next <= SIGNORE_NEXT;
100 when others => state_next <= SIDLE;
108 if finished = '1' then
115 process(state_int, data, s_char_int, new_data)
116 function sc2ascii (x : hbyte) return hbyte is
120 when SC_KP_0 | SC_0 => y := x"30";
121 when SC_KP_1 | SC_1 => y := x"31";
122 when SC_KP_2 | SC_2 => y := x"32";
123 when SC_KP_3 | SC_3 => y := x"33";
124 when SC_KP_4 | SC_4 => y := x"34";
125 when SC_KP_5 | SC_5 => y := x"35";
126 when SC_KP_6 | SC_6 => y := x"36";
127 when SC_KP_7 | SC_7 => y := x"37";
128 when SC_KP_8 | SC_8 => y := x"38";
129 when SC_KP_9 | SC_9 => y := x"39";
130 when SC_KP_PLUS | SC_PLUS => y := x"2b";
131 when SC_KP_MINUS => y := x"2d";
132 when SC_KP_MUL => y := x"2a";
133 when SC_KP_DIV => y := x"2f";
134 when SC_SPACE => y := x"20";
135 when others => y := x"41";
140 s_char_next <= s_char_int;
142 s_backspace_next <= '0';
147 when SIGNORE_NEXT => null;
148 when SREAD_NEXT => null;
151 s_char_next <= sc2ascii(hbyte(data));
154 s_backspace_next <= '1';
159 end architecture beh;