在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1655|回复: 1

[求助] lcd1602 vhdl程序问题,求大牛指导啊!!

[复制链接]
发表于 2011-11-1 10:59:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x




  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4. entity lcd is
  5. port(clk:in std_logic;
  6.                 rst:in std_logic;
  7.                 rs:out std_logic;
  8.                 rw:out std_logic;
  9.                 ren:out std_logic;
  10.                 lcd_data:out std_logic_vector(7 downto 0));
  11. end lcd;
  12. architecture behav of lcd is
  13. type state is (set_function,set_clear,set_swtich,set_inmode,set_drram,set_writeram_1,set_writeram_2,set_idle);
  14. signal current_state:state:=set_clear;
  15. signal data_buf:std_logic_vector(7 downto 0);
  16. signal Clk_Out:std_logic;
  17. signal Lcd_clk:std_logic;
  18. signal cnt   : std_logic_vector(20 downto 0);
  19. begin
  20.         ren <= Clk_Out;
  21. div_clk:process(clk,rst)
  22.          --variable cnt:integer:=0;
  23.                         --signal clk_buf:std_logic;
  24.                         begin
  25.                         if(rst = '0')then
  26.                         cnt <= (others => '0');
  27.                         elsif(rising_edge(clk))then
  28.                                         cnt<= cnt + 1;
  29.                                         if(cnt = 0)then
  30.                                 Clk_Out <= not Clk_Out;
  31.                                         end if;
  32.                         end if;
  33.                    LCD_clk <= Clk_Out;
  34.                         --begin
  35.                         --if rst='0'then
  36.         --     cnt:=0;
  37.                         --elsif clk'event and clk='1' then
  38.                         --               
  39.                         --if cnt<=55555 then
  40.                         --                clk_buf<='0';
  41.                         --                cnt:=cnt+1;
  42.                         --else
  43.                         --        clk_buf<=not clk_buf;
  44.                         --        cnt:=0;
  45.                         --end if;
  46.                 --end if;
  47.                 --ren<=clk_buf;
  48. end process div_clk;
  49.                        
  50. lcd_ctrl:process(Lcd_clk,rst,current_state)
  51.                         variable cntt:integer:=0;
  52.                 begin
  53.                
  54.     if (rst='0') then
  55.                      rs<='0';
  56.                
  57.                     rw<='0';                         
  58.                          data_buf<="00000000";
  59.                  current_state<=set_clear;
  60.         elsif Lcd_clk'event and Lcd_clk='1' then
  61.                       --cntt:=cntt+1;
  62.                        
  63.                 case current_state is
  64.                    when set_clear=>rs<='0';
  65.                                                                 rw<='0';
  66.                                                         data_buf<="00000001";
  67.                                     current_state<=set_function;
  68.                         when set_function=>rs<='0';
  69.                                                                                 rw<='0';
  70.                                                                 data_buf<="00111000";
  71.                                                           current_state<=set_inmode;
  72.                         when set_inmode=>rs<='0';
  73.                                                                         rw<='0';
  74.                                                         data_buf<="00000110";
  75.                                                         current_state<=set_swtich;
  76.                         when set_swtich=>rs<='0';
  77.                                                                         rw<='0';
  78.                                                         data_buf<="00001100";
  79.                                                         current_state<=set_drram;
  80.                         when set_drram=>rs<='0';
  81.                                                                 rw<='0';
  82.                                                         data_buf<="10000000";
  83.                                                   current_state<=set_writeram_1;
  84.                
  85.                         when set_writeram_1=>rs<='1';                                                                    
  86.                                                                                 rw<='0';
  87.                                                                 if cntt=16 then
  88.                                                                    cntt:=0;       
  89.                                 rs<='0';       
  90.                                                                        
  91.                                                                         data_buf<="11000000";
  92.                                                                         current_state<=set_writeram_2;
  93.                                                                
  94.                                                                 else
  95.                                                                    cntt:=cntt+1;
  96.                                                                         case cntt is
  97.                                                                                         when        1=>data_buf<="01010111";
  98.                                                                                         when        2=>data_buf<="01010111";
  99.                                                                                         when        3=>data_buf<="01010111";
  100.                                                                                         when        4=>data_buf<="00101110";
  101.                                                                                         when        5=>data_buf<="01001110";
  102.                                                                                         when        6=>data_buf<="01000010";
  103.                                                                                         when        7=>data_buf<="01010101";
  104.                                                                                         when        8=>data_buf<="00101110";
  105.                                                                                         when        9=>data_buf<="01000101";
  106.                                                                                         when        10=>data_buf<="01000100";
  107.                                                                                         when        11=>data_buf<="01010101";
  108.                                                                                         when        12=>data_buf<="00101110";
  109.                                                                                         when        13=>data_buf<="01000011";
  110.                                                                                         when        14=>data_buf<="01001110";
  111.                                                                                         when        15=>data_buf<="10100000";
  112.                                                                                         when        16=>data_buf<="10100000";
  113.                                                                                                                        
  114.                                                                                                                         --current_state<=set_writeram_1;
  115.                                                                                         when others=>null;
  116.                                                                                                     --cntt:=0;
  117.                                                                         end case;
  118.                                                                    current_state<=set_writeram_1;
  119.                                                                 end if;               
  120.                  when set_writeram_2=>rs<='1';
  121.                                                                          rw<='0';                                                                                                                                                                                                                                                 
  122.                                                         if cntt=16 then
  123.                                                                    cntt:=0;
  124.                                                                    rs<='0';       
  125.                                                                         rw<='0';
  126.                                                                 current_state<=set_idle;
  127.                                                         else
  128.                                                                   --cntt:=0;
  129.                                                                   cntt:=cntt+1;
  130.                                                                   case cntt is
  131.                                                                                         when        1=>data_buf<="01010111";
  132.                                                                                         when        2=>data_buf<="01010111";
  133.                                                                                         when        3=>data_buf<="01010111";
  134.                                                                                         when        4=>data_buf<="00101110";
  135.                                                                                         when        5=>data_buf<="01001110";
  136.                                                                                         when        6=>data_buf<="01000010";
  137.                                                                                         when        7=>data_buf<="01010101";
  138.                                                                                         when        8=>data_buf<="00101110";
  139.                                                                                                                         current_state<=set_writeram_2;
  140.                                                                                         when        9=>data_buf<="01000101";
  141.                                                                                         when        10=>data_buf<="01000100";
  142.                                                                                         when        11=>data_buf<="01010101";
  143.                                                                                         when        12=>data_buf<="00101110";
  144.                                                                                         when        13=>data_buf<="01000011";
  145.                                                                                         when        14=>data_buf<="01001110";
  146.                                                                                         when        15=>data_buf<="10100000";
  147.                                                                                         when        16=>data_buf<="10100000";
  148.                                                                                                                
  149.                                                                                         when  others=>null;
  150.                                                                 end case;
  151.                                                                 current_state<=set_writeram_2;                                                                                                                               
  152.                                                         end if;
  153.                         when set_idle=>current_state<=set_idle;       
  154.       end case;
  155.           lcd_data<=data_buf;         
  156.     end if;
  157.        
  158.          
  159. end process lcd_ctrl;
  160. end behav;       


复制代码
我是要显示两行,因为lcd1602是两行的,但为什么程序写到第二行时(set_writeram_2)是从cntt=8那里执行,前面的不执行,结果第二行就显示了几个字符,第一行正常显示!
发表于 2011-11-4 19:25:20 | 显示全部楼层
这样一个代码,别人怎么可以帮你看这些细节的东西呀,还是自己跑跑仿真看看有什么问题吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-13 20:30 , Processed in 0.022319 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表