times New Roman">程序我觉得没啥问题,就是不出结果。小弟想做的事12864显示汉字。
CLK 2MHZ
LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY bishe1 IS PORT ( clk : IN std_logic; --全局时钟 reset : IN std_logic; --异步复位 -- LCD12864的接口 lcd_data : OUT std_logic_vector(7 DOWNTO 0); --数据总线 lcd_en : OUT std_logic; lcd_rs : OUT std_logic; --数据/指令 lcd_rw : OUT std_logic); --读/写END bishe1; architecture one of bishe1 is type statetype is(s1,s2,s3,s4,s5,s6,s7,s8,s9,s10); --定义一个有10个状态的状态机 signal state:statetype; signal count:integer range 0 to 7; --数据计数器 type datatype1 is array (0 to 11) of std_logic_vector(7 downto 0); type datatype2 is array (0 to 7) of std_logic_vector(7 downto 0); type datatype3 is array (0 to 13) of std_logic_vector(7 downto 0); type datatype4 is array (0 to 15) of std_logic_vector(7 downto 0); --自定义四个数据类型 constant hanzi1:datatype1:=("10110110","10111000","11000111","11101100","11010011","11001010","10110101","11100111", "10110100","10110011","11010001","10100111");-- constant hanzi2:datatype2:=("11001101","10101000","11010000","11000101","10110100","11110011","11010100","10111010"); --存储通信学院 constant hanzi3:datatype3:=("10100011","10110000","10100011","10111001","10110101","11100111","11010000","11000101", "11010110","11101100","10111111","10100001","10111110","11111100");-- constant hanzi4:datatype4:=("11010110","10111000","10110101","10111100","11000000","11001100","11001010","10100110", "10100001","10100011","11001100","10110111","10100111","10110101","10111010","11101010");-- signal rs:std_logic:='0'; signal rw:std_logic:='0'; signal data:std_logic_vector(7 downto 0); begin lcd_rw<=rw; lcd_rs<=rs; lcd_data<=data; lcd_en<=clk;process(clk,reset)begin if reset='1' then --未按下清屏按键 if clk'event and clk='1' then --在时钟的上升沿判断,进行状态选择与跳转 case state is when s1=>if count=0 then data<="00110100";count<=count+1;--功能设定 elsif count=1 then data<="00000110";count<=count+1;--点设定 elsif count=2 then data<="00001100";count<=count+1;--显示控制 else state<=s2;count<=0; end if; when s2=>data<="10000001";state<=s3;--设置第一行显示DDRAM地址 when s3=>rs<='1';--访问数据寄存器,显示第一行汉字 if count=11 then state<=s4;data<=hanzi1(count); else state<=s3;data<=hanzi1(count);count<=count+1; end if; when s4=>rs<='0';data<="10010010";count<=0;state<=s5; when s5=>rs<='1'; if count=7 then state<=s6;data<=hanzi2(count); else state<=s5;data<=hanzi2(count);count<=count+1; end if; when s6=>rs<='0';data<="10100000";count<=0;state<=s6; when s7=>rs<='1'; if count=13 then state<=s7;data<=hanzi3(count); else state<=s6;data<=hanzi3(count);count<=count+1; end if; when s8=>rs<='0';data<="10110000";count<=0;state<=s5; when s9=>rs<='1'; if count=15 then state<=s8;data<=hanzi2(count); else state<=s7;data<=hanzi4(count);count<=count+1; end if; when s10=>rs<='0';data<="00000010";count<=0;--光标归位 when others=>count<=0;state<=s1; end case; end if; else data<="00000001";state<=s1;--按下清屏键,清屏 end if; end process; end;
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY lcd12864 IS
PORT(
CLK: IN STD_LOGIC;
ROM_DATA: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
RS,RW,CS1,CS2,E: OUT STD_LOGIC;
ADDRESS: OUT STD_LOGIC_VECTOR(4 DOWNTO 0);
Q: OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END;
ARCHITECTURE BEHAV OF lcd12864 IS
TYPE STATES IS(ST0,ST1,ST2,ST3,ST4,ST5,ST6,ST7,
ST8,ST9,ST10,ST11,ST12,ST13,ST14,ST15); --状态定意
SIGNAL PRE_STATE,NEXT_STATE:STATES;
SIGNAL DATALOCK,EN,RST1:STD_LOGIC;
SIGNAL ADDR:INTEGER RANGE 0 TO 65:=0;
SIGNAL XPAGE:STD_LOGIC_VECTOR(7 DOWNTO 0):="10111000";
SIGNAL YADDR:STD_LOGIC_VECTOR(7 DOWNTO 0):="01000000";
BEGIN
CLOCK:PROCESS(CLK) --将时钟进行分频
VARIABLE CONT:INTEGER RANGE 0 TO 20;
BEGIN
IF CLK'EVENT AND CLK='1' THEN
CONT:=CONT+1;
IF CONT = 12 THEN DATALOCK<='0';CONT:=0;
ELSIF CONT = 9 THEN
DATALOCK<='1';
END IF;
END IF;
END PROCESS CLOCK;
EN<= NOT DATALOCK;
E<=EN;
DATAK:PROCESS(EN,PRE_STATE)
BEGIN
IF EN'EVENT AND EN='1' THEN
CASE PRE_STATE IS
WHEN ST0=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="00111110";PRE_STATE<=ST1; --显示开关设置
WHEN ST1=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="00111110";PRE_STATE<=ST2;
WHEN ST2=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="11000000";PRE_STATE<=ST3; --起始行设置
--左半清屏
WHEN ST3=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<=XPAGE;PRE_STATE<=ST4; --页地址设置
WHEN ST4=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<=YADDR;PRE_STATE<=ST5; --列地址设置
WHEN ST5=>RS<='1';RW<='0';CS1<='0';CS2<='1';
IF XPAGE>"10111111" THEN
XPAGE<="10111000";
YADDR<="01000000";
PRE_STATE<=ST6; --左半清屏完毕,进入下一状态
ELSIF YADDR>"01111111" THEN
YADDR<="01000000";
XPAGE<=XPAGE+1; --清完一页,开始下一页
PRE_STATE<=ST3; --返回重新设置页地址
ELSE
Q<="00000000";YADDR<=YADDR+1;PRE_STATE<=ST5; --清完一列,开始下一列
END IF;
--右半清屏
WHEN ST6=>RS<='0';RW<='0';CS1<='1';CS2<='0';Q<=XPAGE;PRE_STATE<=ST7; --页地址设置
WHEN ST7=>RS<='0';RW<='0';CS1<='1';CS2<='0';Q<=YADDR;PRE_STATE<=ST8; --列地址设置
WHEN ST8=>RS<='1';RW<='0';CS1<='1';CS2<='0';
IF XPAGE>"10111111" THEN
XPAGE<="10111000";
YADDR<="01000000";
PRE_STATE<=ST9; ----右半清屏完毕,进入下一状态
ELSIF YADDR>"01111111" THEN
YADDR<="01000000";
XPAGE<=XPAGE+1; --清完一页,开始下一页
PRE_STATE<=ST6; --返回重新设置页地址
ELSE
Q<="00000000";YADDR<=YADDR+1;PRE_STATE<=ST8; --清完一列,开始下一列
END IF;
--清屏完毕,开始显示数据
--显示上半边
WHEN ST9=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="00111111";PRE_STATE<=ST10; --显示开关设置
WHEN ST10=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="10111011";PRE_STATE<=ST11; --页地址设置 第三页
WHEN ST11=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="01000001";PRE_STATE<=ST12; --列地址设置 第1列
WHEN ST12=>RS<='1';RW<='0';CS1<='0';CS2<='1';
IF ADDR>15 THEN
YADDR<="01000000";
PRE_STATE<=ST13; --显示完上半边后显示下半边
ELSE
Q<=ROM_DATA;
ADDR<=ADDR+1;
YADDR<=YADDR+1;
PRE_STATE<=ST12;
END IF;
--显示下半边
WHEN ST13=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="10111100";PRE_STATE<=ST14; --页地址设置 第四页
WHEN ST14=>RS<='0';RW<='0';CS1<='0';CS2<='1';Q<="01000001";PRE_STATE<=ST15; --列地址设置 第1列
WHEN ST15=>RS<='1';RW<='0';CS1<='0';CS2<='1';
IF ADDR>31 THEN
ADDR<=0;
YADDR<="01000000";
PRE_STATE<=ST10; --显示完毕后又重新显示
ELSE
Q<=ROM_DATA;
ADDR<=ADDR+1;
YADDR<=YADDR+1;
PRE_STATE<=ST15;
END IF;
WHEN OTHERS=>PRE_STATE<=ST0;
END CASE;
END IF;
ADDRESS<=CONV_STD_LOGIC_VECTOR(ADDR,5);
END PROCESS DATAK;
END BEHAV;
看下这个程序,
一周热门 更多>