我想用VHDL驱动4x16 LCD显示器。第一行应该说“FREQ:000 RPM”,其中零表示输入的8位频率数据。对于具有不同数据的下一行也是如此,也是8位。我的VHDL代码如下:
-- 16 Characters
subtype string16_type is string(1 to 16);
-- 4 string of 16 characters
type message4x16_type is array(1 to 4) of string16_type;
-- Define messages displayed
constant message_home: message4x16_type := ( --1234567890123456
1 => "FREE MODE ",
2 => "PARCOURS ",
3 => "- - - - - - - - ",
4 => " - - - - - - - -");
constant message_info: message4x16_type := ( --1234567890123456
1 => "FREQ: 000 RPM ",
2 => "SPEED: 000 KM/H ",
3 => "DIST: 000 KM ",
4 => "MORE INFO ");
-- Character amount in line
signal character_counter: integer range 1 to 16;
-- Line amount on LCD
signal line_counter : integer range 1 to 4;
然后跟随状态机,状态write_char看起来部分如下:
if msg_select = '0' then
aline := message_home(line_counter);
elsif msg_select = '1' then
aline := message_info(line_counter);
end if;
data <= std_logic_vector(to_unsigned(character'pos(aline(character_counter)),8));
这一切都顺利地运行,但我想不出一种方法将频率数据实现到消息中,就像在C中使用%i一样。我知道'记录'语句但不知道如何使用它这个情况。我们非常欢迎任何其他实现数据的方法。
感谢正手。
答案 0 :(得分:3)
像以前一样声明类型,常量和信号:
-- 16 characters
type lcd_line_type is array(0 to 15) of character;
-- 4 lines of 16 characters
type message4x16_type is array(0 to 3) of lcd_line_type;
-- Define messages displayed
constant message_home : message4x16_type := (
--1234567890123456
"FREE MODE ",
"PARCOURS ",
"- - - - - - - - ",
" - - - - - - - -"
);
constant message_info : message4x16_type := (
--1234567890123456
"FREQ: 000 RPM ",
"SPEED: 000 KM/H ",
"DIST: 000 KM ",
"MORE INFO "
);
-- Character amount in line
signal character_counter : integer range 0 to 15;
-- Line amount on LCD
signal line_counter : integer range 0 to 3;
subtype rawchar is std_logic_vector(7 downto 0);
type rawstring is array(natural range <>) of rawchar;
signal rpm : rawstring(2 downto 0);
signal kmh : rawstring(2 downto 0);
function to_rawchar(char : character) return rawchar is
begin
return std_logic_vector(to_unsigned(character'pos(char), 8));
end function;
用法示例:
if msg_select = '0' then
data <= to_rawchar(message_home(line_counter)(character_counter));
elsif msg_select = '1' then
case line_counter is
when 0 =>
-- replace 000 by rpm(2:0)
case character_counter is
when 6 => data <= rpm(2);
when 7 => data <= rpm(1);
when 8 => data <= rpm(0);
when others => data <= to_rawchar(message_info(0)(character_counter));
end case;
when 1 =>
-- replace 000 by kmh(2:0)
case character_counter is
when 7 => data <= kmh(2);
when 8 => data <= kmh(1);
when 9 => data <= kmh(0);
when others => data <= to_rawchar(message_info(1)(character_counter));
end case;
-- ...
end case;
end if;
第一个案例测试所请求的行。第二种情况会覆盖特定位置的常数值。
我还将char转换为slv转换为函数。