4x8c液晶加不同键盘按键控制不同输出显示


--不同键盘控制不同输出显示
--自动扫描重新显示

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity inandout2 is
 port(clk,reset:in std_logic;
       led:in std_logic_vector(3 downto 0);
       RW,RS:out std_logic;
           E:buffer std_logic;
         PSB:out std_logic;
     LcdData:out std_logic_vector(7 downto 0));
end inandout2;

architecture behavior of inandout2 is
                               
signal cout:std_logic;

type States is(s0,s1,s2);
signal CurrentState:States:=s0;

type InstructArray is array(0 to 2)of std_logic_vector(7 downto 0);
constant Instruct:InstructArray:=(x"30",x"0c",x"01");

type DataArray is array(0 to 63)of std_logic_vector(7 downto 0);
       --定义了所有的控制字
constant DataBuffer0:DataArray:=(X"a3",X"b0",X"a3",X"b0",X"c4",X"ea",X"bc",X"b6",--00年级电气三班
                                 X"b5",X"e7",X"c6",X"f8",X"c8",X"fd",X"b0",X"e0",
                                 X"b7",X"ae",X"c8",X"ea",X"c9",X"ad",X"d7",X"f7",--樊汝森作液晶显示
                                 X"d2",X"ba",X"be",X"a7",X"cf",X"d4",X"ca",X"be",
                                 X"d4",X"f8",X"be",X"ad",X"b2",X"d7",X"ba",x"a3",--曾经沧海难为水
                                 X"c4",X"d1",X"ce",X"aa",X"cb",X"ae",X"a3",x"ac",
                                 X"b3",X"fd",X"c8",X"b4",X"ce",X"d7",X"c9",X"bd",--除却巫山不是云
                                 X"b2",X"bb",X"ca",X"c7",X"d4",X"c6",X"a1",X"a3");
constant DataBuffer1:DataArray:=(X"a3",X"b0",X"a3",X"b1",X"c4",X"ea",X"bc",X"b6",--01年级电气三班
                                 X"b5",X"e7",X"c6",X"f8",X"c8",X"fd",X"b0",X"e0",
                                 X"b7",X"ae",X"c8",X"ea",X"c9",X"ad",X"d7",X"f7",--樊汝森作液晶显示
                                 X"d2",X"ba",X"be",X"a7",X"cf",X"d4",X"ca",X"be",
                                 X"d4",X"f8",X"be",X"ad",X"b2",X"d7",X"ba",x"a3",--曾经沧海难为水
                                 X"c4",X"d1",X"ce",X"aa",X"cb",X"ae",X"a3",x"ac",
                                 X"b3",X"fd",X"c8",X"b4",X"ce",X"d7",X"c9",X"bd",--除却巫山不是云
                                 X"b2",X"bb",X"ca",X"c7",X"d4",X"c6",X"a1",X"a3");
constant DataBuffer2:DataArray:=(X"a3",X"b0",X"a3",X"b2",X"c4",X"ea",X"bc",X"b6",--02年级电气三班
                                 X"b5",X"e7",X"c6",X"f8",X"c8",X"fd",X"b0",X"e0",
                                 X"b7",X"ae",X"c8",X"ea",X"c9",X"ad",X"d7",X"f7",--樊汝森作液晶显示
                                 X"d2",X"ba",X"be",X"a7",X"cf",X"d4",X"ca",X"be",
                                 X"d4",X"f8",X"be",X"ad",X"b2",X"d7",X"ba",x"a3",--曾经沧海难为水
                                 X"c4",X"d1",X"ce",X"aa",X"cb",X"ae",X"a3",x"ac",
                                 X"b3",X"fd",X"c8",X"b4",X"ce",X"d7",X"c9",X"bd",--除却巫山不是云
                                 X"b2",X"bb",X"ca",X"c7",X"d4",X"c6",X"a1",X"a3");
constant DataBuffer3:DataArray:=(X"a3",X"b0",X"a3",X"b3",X"c4",X"ea",X"bc",X"b6",--03年级电气三班
                                 X"b5",X"e7",X"c6",X"f8",X"c8",X"fd",X"b0",X"e0",
                                 X"b7",X"ae",X"c8",X"ea",X"c9",X"ad",X"d7",X"f7",--樊汝森作液晶显示
                                 X"d2",X"ba",X"be",X"a7",X"cf",X"d4",X"ca",X"be",
                                 X"d4",X"f8",X"be",X"ad",X"b2",X"d7",X"ba",x"a3",--曾经沧海难为水
                                 X"c4",X"d1",X"ce",X"aa",X"cb",X"ae",X"a3",x"ac",
                                 X"b3",X"fd",X"c8",X"b4",X"ce",X"d7",X"c9",X"bd",--除却巫山不是云
                                 X"b2",X"bb",X"ca",X"c7",X"d4",X"c6",X"a1",X"a3");
                                
                                
begin
PSB<='1';

PROCESS(clk)  --fen  pin;  f= 5k;
variable  i : integer range 0 to 10000;  
BEGIN
if i=10000 then
i:=0;
cout<='1';
elsif clk'event and clk='1' then
i:=i+1;
if i=5000 then
cout<='0';
end if;
end if;
END PROCESS;
 

U1: process(cout,reset)
 variable cnt1:integer:=0;
 variable cnt2:integer range 0 to 200;
 
begin
if reset='0' then
 cnt1:=0; cnt2:=0;CurrentState<=s0;
   elsif cout'event and cout='1' then
  case CurrentState is
    when s0=>cnt1:=cnt1+1;            --选择用哪个基本指令
         if cnt2<3 then
     if cnt1<20 then
      RW<='0';RS<='0';E<='0';
     elsif cnt1<40 then
      E<='1';
     elsif cnt1<60 then
      LcdData<=Instruct(cnt2); 
     elsif cnt1<80 then
      E<='0';
     elsif cnt1<100 then
      null;
     else
      cnt1:=0;cnt2:=cnt2+1;
      CurrentState<=s0;
     end if;
    else
               cnt2:=0;CurrentState<=s1;
       end if;
  
 when s1=>cnt1:=cnt1+1;     
     if led="0000"  then      --输入“0000”,第一行输出DataBuffer1曾经沧海难为水
    if cnt2<64 then
     if cnt1<2 then
      RW<='0';RS<='0';E<='0';
     elsif cnt1<4 then
      E<='1';
     elsif cnt1<6 then
      LcdData<=X"01";
     elsif cnt1<8 then
      E<='0';
     elsif cnt1<10 then
      null;
      
     elsif cnt1<12 then
      RW<='0';RS<='0';E<='0';
     elsif cnt1<14 then
      E<='1';
     elsif cnt1<16 then
      case cnt2 is
          when 0  =>LcdData<=X"80";
          when 16 =>LcdData<=X"90";
          when 32 =>LcdData<=X"88";
          when 48 =>LcdData<=X"98";
          when others =>null;
         end case;
     elsif cnt1<18 then
      E<='0';
     elsif cnt1<20 then
      null;
     
      
     elsif cnt1<22 then
      RW<='0';RS<='1';E<='0';
     elsif cnt1<24 then
      E<='1';
     elsif cnt1<26 then
      LcdData<=DataBuffer0(cnt2);  
     elsif cnt1<28 then
      E<='0';
     elsif cnt1<30 then
      null;
     else
      cnt2:=cnt2+1;
      if (cnt2=16 or cnt2=32 or cnt2=48 ) then  cnt1:=10;
                        elsif cnt2=64 then  cnt2:=0; cnt1:=0;CurrentState<=s2;
         else  cnt1:=20;
         end if;
                    end if;
    else null;
    end if;
   elsif led="0001"  then  --输入“0001”,第二行输出DataBuffer2除却巫山不是云      
    if cnt2<64 then
     if cnt1<2 then
      RW<='0';RS<='0';E<='0';
     elsif cnt1<4 then
      E<='1';
     elsif cnt1<6 then
      LcdData<=X"01";
     elsif cnt1<8 then
      E<='0';
     elsif cnt1<10 then
      null;
      
     elsif cnt1<12 then
      RW<='0';RS<='0';E<='0';
     elsif cnt1<14 then
      E<='1';
     elsif cnt1<16 then
      case cnt2 is
          when 0  =>LcdData<=X"80";
          when 16 =>LcdData<=X"90";
          when 32 =>LcdData<=X"88";
          when 48 =>LcdData<=X"98";
          when others =>null;
         end case;
     elsif cnt1<18 then
      E<='0';
     elsif cnt1<20 then
      null;
     
      
     elsif cnt1<22 then
      RW<='0';RS<='1';E<='0';
     elsif cnt1<24 then
      E<='1';
     elsif cnt1<26 then
      LcdData<=DataBuffer1(cnt2);    --xie
     elsif cnt1<28 then
      E<='0';
     elsif cnt1<30 then
      null;
     else
      cnt2:=cnt2+1;
      if (cnt2=16 or cnt2=32 or cnt2=48 ) then  cnt1:=10;
                        elsif cnt2=64 then  cnt2:=0; cnt1:=0;CurrentState<=s2;
         else  cnt1:=20;
         end if;
                    end if;
    else null;
    end if;
   elsif led="0010"  then  --输入“0010”,第三行输出DataBuffer3  青岛大学
   if cnt2<64 then
     if cnt1<2 then
      RW<='0';RS<='0';E<='0';
     elsif cnt1<4 then
      E<='1';
     elsif cnt1<6 then
      LcdData<=X"01";
     elsif cnt1<8 then
      E<='0';
     elsif cnt1<10 then
      null;
      
     elsif cnt1<12 then
      RW<='0';RS<='0';E<='0';
     elsif cnt1<14 then
      E<='1';
     elsif cnt1<16 then
      case cnt2 is
          when 0  =>LcdData<=X"80";
          when 16 =>LcdData<=X"90";
          when 32 =>LcdData<=X"88";
          when 48 =>LcdData<=X"98";
          when others =>null;
         end case;
     elsif cnt1<18 then
      E<='0';
     elsif cnt1<20 then
      null;
     
      
     elsif cnt1<22 then
      RW<='0';RS<='1';E<='0';
     elsif cnt1<24 then
      E<='1';
     elsif cnt1<26 then
      LcdData<=DataBuffer2(cnt2);    --xie
     elsif cnt1<28 then
      E<='0';
     elsif cnt1<30 then
      null;
     else
      cnt2:=cnt2+1;
      if (cnt2=16 or cnt2=32 or cnt2=48 ) then  cnt1:=10;
                        elsif cnt2=64 then  cnt2:=0; cnt1:=0;CurrentState<=s2;
         else  cnt1:=20;
         end if;
                    end if;
    else null;
    end if;     
   elsif led="0011"  then  --输入“0011”,第四行输出DataBuffer4电工电子实验中心
        if cnt2<64 then
     if cnt1<2 then          --再清零
      RW<='0';RS<='0';E<='0';
     elsif cnt1<4 then
      E<='1';
     elsif cnt1<6 then
      LcdData<=X"01";
     elsif cnt1<8 then
      E<='0';
     elsif cnt1<10 then
      null;
      
     elsif cnt1<12 then   --分配初始地址
      RW<='0';RS<='0';E<='0';
     elsif cnt1<14 then
      E<='1';
     elsif cnt1<16 then
      case cnt2 is
          when 0  =>LcdData<=X"80";
          when 16 =>LcdData<=X"90";
          when 32 =>LcdData<=X"88";
          when 48 =>LcdData<=X"98";
          when others =>null;
         end case;
     elsif cnt1<18 then
      E<='0';
     elsif cnt1<20 then
      null;
     
      
     elsif cnt1<22 then     --输出显示
        RW<='0';RS<='1';E<='0';
     elsif cnt1<24 then
      E<='1';
     elsif cnt1<26 then
      LcdData<=DataBuffer3(cnt2);    --xie
     elsif cnt1<28 then
      E<='0';
     elsif cnt1<30 then
      null;
     else
      cnt2:=cnt2+1;
      if (cnt2=16 or cnt2=32 or cnt2=48 ) then  cnt1:=10;
                        elsif cnt2=64 then  cnt2:=0; cnt1:=0;CurrentState<=s2;
         else  cnt1:=20;
         end if;
                    end if;
    else null;
    end if;
       
    else  cnt2:=0; cnt1:=0;CurrentState<=s2;
    end if; --end led
   
   
    when s2=>cnt1:=cnt1+1;     
     if cnt1<2000 then
      null;
     else
      cnt1:=0;CurrentState<=s1;
     end if;
  end case; 
end if; --end rst 
end process U1;
end behavior;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值