					when selftest_cycle1 =>
						addr <= std_logic_vector(count(1)&count(0));
						n_we <= '1'; n_oe <= '1';
						io_z <= '0';
						io_data <= (0 to 3 => count(2), 4 => count(3));
						state <= selftest_cycle2;
					when selftest_cycle2 =>
						addr <= std_logic_vector(count(1)&count(0));
						n_we <= '0'; n_oe <= '1';
						io_z <= '0';
						io_data <= (0 to 3 => count(2), 4 => count(3));
						state <= selftest_cycle3;
					when selftest_cycle3 =>
						addr <= std_logic_vector(count(1)&count(0));
						n_we <= '1'; n_oe <= '1';
						io_z <= '0';
						io_data <= (0 to 3 => count(2), 4 => count(3));
						state <= selftest_cycle4;
					when selftest_cycle4 =>
						addr <= std_logic_vector(count(1)&count(0));
						n_we <= '1'; n_oe <= '0';
						io_z <= '1'; io_data <= (others=>'0');
						state <= selftest_cycle5;
					when selftest_cycle5 =>
						addr <= std_logic_vector(count(1)&count(0));
						n_we <= '1'; n_oe <= '0';
						io_z <= '1'; io_data <= (others=>'0');
						if io(0) = count(2) and io(1) = count(2)
							and io(2) = count(2) and io(3) = count(2)
							and io(4) = count(3) then
							state <= selftest_cycle6;
						else
							state <= selftest_error;
						end if;
					when selftest_cycle6 =>
						addr <= std_logic_vector(count(1)&count(0));
						n_we <= '1'; n_oe <= '1';
						io_z <= '0'; io_data <= (others=>'0');
						if count(4) = '1' then
							state <= selftest_cycle1;
						else
							state <= selftest_wait;
						end if;
					when selftest_error =>
						product <= "1111";
						case button is
							when lreset_button =>
								state <= startup;
							when greset_button =>
								count <= (others=>'0');
								state <= greset1;
							when others =>
								state <= selftest_error;
						end case;
