Vhdl'de Lcd'ye değişken yazdırmak.

Başlatan vitruvius, 06 Mayıs 2012, 13:47:16

yamak

Şimdilik şunu söyleleyim.Şu kodlarda if(tekrar=0) koşulunun altına 2. kez girmiyo. Bunun üzeirne düşünebilirsin.Benim şu an okula gitmem gerekiyo :)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity tplcdvebuton is
port (
         buton : in std_logic;
         led : out std_logic_vector(7 downto 0);
         clk : in std_logic;		 
         DB : out  STD_LOGIC_VECTOR (7 downto 4); 
       LCD_E :out STD_LOGIC;
       LCD_RS :out STD_LOGIC;
       LCD_RW :out STD_LOGIC
);
end tplcdvebuton;

architecture Behavioral of tplcdvebuton is
--------------- Signals for Button and Debounce ----------------
signal counter : integer range 0 to 15000000;
signal buton_b : std_logic;
signal buton_g : std_logic;
signal cnt : integer range 0 to 8 :=3;
signal ledg : std_logic_vector(7 downto 0);
-----------------------------------------------------------------------------

--------------- Signals for Lcd ------------------------------
Signal DATA : STD_LOGIC_VECTOR (7 downto 0);
signal ayar : std_logic:='1'; -- Bu ayar, lcd konfigurasyonunu başlatacak olan signal.
signal dongu : std_logic; -- Bu dongu de karakter yollama kısmını başlatacak kısım.
signal tekrar: std_logic; -- Bu tekrar da dongunun ismine yakışır olabilmesi için.
signal say3_signal: integer range 0 to 40000;
-----------------------------------------------------------------------------

begin
    led <= ledg;

    process(clk) -- Debounce
    begin
        if(clk'event and clk='1') then
            if(buton_b <= '1') then
            counter<=counter+1;
            buton_g<='0';
            elsif(buton='1') then
            buton_b<='1';
            end if;
                if(counter=15000000) then --300ms
                counter<=0;
                buton_b<='0';
                    if(buton='1') then
                    buton_g<='1';
                    end if;
                end if;
        end if;
    end process;
    
    process(clk) --Cnt
    begin
        if(clk'event and clk='1') then
            if(buton_g='1') then
            cnt<=cnt+1;
                    if(cnt=8) then
                    cnt<=0;
                    end if;
            end if;
        end if;
    end process;
    
--    process(cnt) -- Checking the value of the cnt with using LEDs
--    begin
--        case cnt is
--            when 0 => ledg <= "00000000";
--            when 1 => ledg <= "00000001";
--            when 2 => ledg <= "00000010";
--            when 3 => ledg <= "00000100";
--            when 4 => ledg <= "00001000";
--            when 5 => ledg <= "00010000";
--            when 6 => ledg <= "00100000";
--            when 7 => ledg <= "01000000";				
--            when others => ledg <= "10000000";
--        end case;
--   end process;
    
    
    ------------------------------------- LCD ------------------------------------
    process (clk)
    variable say1:integer;
    variable say2:integer;
     variable say3:integer; -- Bu say3 de karakter yollayacagım kısmın sayacı
    begin
    if (clk'EVENT and clk='1') then    
    say1:=say1+1;    			
        if (say1>50000) then	--1 KHZ
        say1:=0; -- Burada da kafamı karıştıran bir şey var. say1 0 olunca bu if hala nasıl işliyor?
          --ayar<='1'; --Şimdi 1KHZ olduğunda ayar signal 1 olsun ve konfigurasyon başlasın.
             if(ayar='1') then -- Konfigurasyon başladı
             say2:=say2+1; -- Bu kısımları ellemedim.
            case say2 is
            when 90=>
                LCD_RW<='0';
                LCD_RS<='0'; --CMD
                DB<="0011";
            when 99=>LCD_E<='1';
            when 100=>LCD_E<='0';
            when 115=>LCD_E<='1';
            when 116=>LCD_E<='0';
            when 121=>LCD_E<='1';
            when 122=>LCD_E<='0';
            when 127=>DB<="0010";
            when 128=>LCD_E<='1';
            when 129=>LCD_E<='0';

            
            when 149=>DATA<=X"28";
            when 150=>DB<=DATA(7 downto 4);
            when 151=>LCD_E<='1';			
            when 152=>LCD_E<='0';
            when 153=>DB<=DATA(3 downto 0);
            when 154=>LCD_E<='1';
            when 155=>LCD_E<='0';			
            DATA<=X"08";

            when 156=>DB<=DATA(7 downto 4);
            when 157=>LCD_E<='1';			
            when 158=>LCD_E<='0';
            when 159=>DB<=DATA(3 downto 0);
            when 160=>LCD_E<='1';
            when 161=>LCD_E<='0';				
                DATA<=X"01"; 
            when 162=>
                DB<=DATA(7 downto 4);
            when 163=>LCD_E<='1';			
            when 164=>LCD_E<='0';
            when 165=>DB<=DATA(3 downto 0);
            when 166=>LCD_E<='1';
            when 167=>LCD_E<='0';	
                DATA<=X"06";
            when 168=>
                DB<=DATA(7 downto 4);
            when 169=>LCD_E<='1';			
            when 170=>LCD_E<='0';
            when 171=>DB<=DATA(3 downto 0);
            when 172=>LCD_E<='1';
            when 173=>LCD_E<='0';
                DATA<=X"0C";
            when 174=>
                DB<=DATA(7 downto 4);
            when 175=>LCD_E<='1';			
            when 176=>LCD_E<='0';
            when 177=>DB<=DATA(3 downto 0);
            when 178=>LCD_E<='1';
            when 179=>LCD_E<='0';			
            
            when 180=>LCD_RS<='1'; --Chr
                when 181=> -- Konfigurasyon bitti
                             --say3:=1; -- Say3 karakter göndereceğim sayac ve konfugirasyon bitince 1 oluyor.
                             ayar<='0'; -- Ayar'ı 0 yaptım ki bir daha konfigurasyon yapılmasın.
                            -- dongu<='1'; -- Konfigurasyon bitince dongu 1 oldu ve karakter gönderecegim kısım başlayacak.
                when others => -- others mecburiyetten.
                end case;
            end if;		
                
------------------------- SINIR -----------------------------
        if(tekrar='0') then --Bu tekrar StopTimer işini görüyor aslında burada
            --if(dongu='1') then -- Karakter yollama kısmı başladı
                say3:=say3+1; -- Yukarıda değeri 1 olmuştu, artmaya devam ediyor.
                say3_signal<=say3;
					 ledg(6)<=not ledg(6);
                    case say3 is -- Bu saatten sonra da say3'ün degerine bakılarak kaldıgı yerden devam ediliyor.
                
                when 2=>
                DATA<=X"43"; -- C
            when 3=>
                DB<=DATA(7 downto 4);
            when 4=>LCD_E<='1';			
            when 5=>LCD_E<='0';
            when 6=>DB<=DATA(3 downto 0);
            when 7=>LCD_E<='1';
            when 8=>LCD_E<='0';	
                
                DATA<=X"4E"; -- N
            when 9=>
                DB<=DATA(7 downto 4);
            when 10=>LCD_E<='1';			
            when 11=>LCD_E<='0';
            when 12=>DB<=DATA(3 downto 0);
            when 13=>LCD_E<='1';
            when 14=>LCD_E<='0';	
                
                DATA<=X"54"; -- T
            when 15=>
                DB<=DATA(7 downto 4);
            when 16=>LCD_E<='1';			
            when 17=>LCD_E<='0';
            when 18=>DB<=DATA(3 downto 0);
            when 19=>LCD_E<='1';
            when 20=>LCD_E<='0';
                
                DATA<=X"3D"; -- =
            when 21=>
                DB<=DATA(7 downto 4);
            when 22=>LCD_E<='1';			
            when 23=>LCD_E<='0';
            when 24=>DB<=DATA(3 downto 0);
            when 25=>LCD_E<='1';
            when 26=>LCD_E<='0';
                
                DATA<=(conv_std_logic_vector((cnt+48),8));
            when 27=>
                DB<=DATA(7 downto 4);
            when 28=>LCD_E<='1';			
            when 29=>LCD_E<='0';
            when 30=>DB<=DATA(3 downto 0);
            when 31=>LCD_E<='1';
            when 32=>LCD_E<='0';        
                when others=>
            end case;
          --end if;
             
             elsif(tekrar='1')then -- Burada say3'ü sıfırladım.
             say3:=0;
        end if;
        end if;
    end if;
   end process;
     
     
--     process(clk) -- Burada dongu'yu resetleyecegim.
--     begin
--        if(clk'event and clk='1') then
--            if(say3_signal=33) then
--            tekrar<='1';
--            elsif(buton_g='1') then --Butona bastığımda dongunun tekrar baştan başlaması için.
--            tekrar<='0';
--            end if;			
--        end if;
--    end process;
	 
	 tekrar<='1' when say3_signal=33 else 
				'0' when buton_g='1';
    
end Behavioral;

turkplc

$FE, 1 Clear display
$FE, 2 Return home (beginning of first line)
$FE, $0C Cursor off
$FE, $0E Underline cursor on
$FE, $0F Blinking cursor on
$FE, $10 Move cursor left one position
$FE, $14 Move cursor right one position
$FE, $C0 Move cursor to beginning of second line
$FE, $94 Move cursor to beginning of third line (if applicable)
$FE, $D4 Move cursor to beginning of fourth line (if applicable)

vitruvius

Hocam nereden baktınız bu komut serisine? 3E-Starter Kit User Guide'dan bakıyorum ben de arama yapmama rağmen bulamadım. Sorgulamıyorum, $FE, $10 şu ifadenin ne anlama geldiğini bilmediğimden datasheeti okuyacağım.

turkplc

Proton'un yardımından,
hex 10 komutunu gönderdiğinde kursoru 1 sola taşır,
LCD konfig ayarlarını yaparken cmd göndermeyle ilgili kısım var oraya bakarak yapmalısın,

iyi günler

vitruvius

Nihayet bu işi bitirdim. Yardımlarınız için çok teşekkür ederim. Sırada adc okuma ve o değeri lcd'ye yazdırma var  :)

Çalışan kodu aşağıda veriyorum.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity lcd_deneme_3 is
port (
         buton : in std_logic;
         led : out std_logic_vector(7 downto 0);
         clk : in std_logic;		 
         DB : out  STD_LOGIC_VECTOR (7 downto 4); 
       LCD_E :out STD_LOGIC;
       LCD_RS :out STD_LOGIC;
       LCD_RW :out STD_LOGIC
);
end lcd_deneme_3;

architecture Behavioral of lcd_deneme_3 is
--------------- Buton ve Debounce için Kullanılan Signal'ler ----------------
signal counter : integer range 0 to 15000000;
signal buton_b : std_logic;
signal buton_g : std_logic;
signal sayac : integer range 0 to 8;
signal ledg : std_logic_vector(7 downto 0);
-----------------------------------------------------------------------------

--------------- Lcd için Kullanılan Signal'ler ------------------------------
Signal StopTimer:std_logic;
Signal DATA : STD_LOGIC_VECTOR (7 downto 0);
-----------------------------------------------------------------------------

begin
    led <= ledg;

    process(clk) -- Debounce
    begin
        if(clk'event and clk='1') then
            if(buton_b <= '1') then
            counter<=counter+1;
            buton_g<='0';
            elsif(buton='1') then
            buton_b<='1';
            end if;
                if(counter=15000000) then --300ms
                counter<=0;
                buton_b<='0';
                    if(buton='1') then
                    buton_g<='1';
                    end if;
                end if;
        end if;
    end process;
    
    process(clk) --Sayaç
    begin
        if(clk'event and clk='1') then
            if(buton_g='1') then
            sayac<=sayac+1;
                    if(sayac=8) then
                    sayac<=0;
                    end if;
            end if;
        end if;
    end process;
    
    process(sayac)
    begin
        case sayac is
            when 0 => ledg <= "00000000";
            when 1 => ledg <= "00000001";
            when 2 => ledg <= "00000010";
            when 3 => ledg <= "00000100";
            when 4 => ledg <= "00001000";
            when 5 => ledg <= "00010000";
            when 6 => ledg <= "00100000";
            when 7 => ledg <= "01000000";				
            when others => ledg <= "10000000";
        end case;
   end process;
    
    ------------------------------------- LCD ------------------------------------
    process (clk)
    variable say1:integer;
    variable say2:integer;
    begin
    if (clk'EVENT and clk='1') then
    if (StopTimer='0') then 
    say1:=say1+1;
    end if;				
        if (say1>50000) then	--1 KHZ
        say1:=0;
        say2:=say2+1;
            case say2 is
            when 90=>
                LCD_RW<='0';
                LCD_RS<='0'; --CMD
                DB<="0011";
            when 99=>LCD_E<='1';
            when 100=>LCD_E<='0';
            when 115=>LCD_E<='1';
            when 116=>LCD_E<='0';
            when 121=>LCD_E<='1';
            when 122=>LCD_E<='0';
            when 127=>DB<="0010";
            when 128=>LCD_E<='1';
            when 129=>LCD_E<='0';

            
            when 149=>DATA<=X"28";
            when 150=>DB<=DATA(7 downto 4);
            when 151=>LCD_E<='1';			
            when 152=>LCD_E<='0';
            when 153=>DB<=DATA(3 downto 0);
            when 154=>LCD_E<='1';
            when 155=>LCD_E<='0';			
            DATA<=X"08";

            when 156=>DB<=DATA(7 downto 4);
            when 157=>LCD_E<='1';			
            when 158=>LCD_E<='0';
            when 159=>DB<=DATA(3 downto 0);
            when 160=>LCD_E<='1';
            when 161=>LCD_E<='0';				
                DATA<=X"01"; 
            when 162=>
                DB<=DATA(7 downto 4);
            when 163=>LCD_E<='1';			
            when 164=>LCD_E<='0';
            when 165=>DB<=DATA(3 downto 0);
            when 166=>LCD_E<='1';
            when 167=>LCD_E<='0';	
                DATA<=X"06";
            when 168=>
                DB<=DATA(7 downto 4);
            when 169=>LCD_E<='1';			
            when 170=>LCD_E<='0';
            when 171=>DB<=DATA(3 downto 0);
            when 172=>LCD_E<='1';
            when 173=>LCD_E<='0';
                DATA<=X"0C";
            when 174=>
                DB<=DATA(7 downto 4);
            when 175=>LCD_E<='1';			
            when 176=>LCD_E<='0';
            when 177=>DB<=DATA(3 downto 0);
            when 178=>LCD_E<='1';
            when 179=>LCD_E<='0';			
            
            when 180=>LCD_RS<='1'; --Chr
                 DATA<=X"42"; -- B
            when 181=>
                DB<=DATA(7 downto 4);
            when 182=>LCD_E<='1';			
            when 183=>LCD_E<='0';
            when 184=>DB<=DATA(3 downto 0);
            when 185=>LCD_E<='1';
            when 186=>LCD_E<='0';	
                
                DATA<=X"41"; -- A
            when 187=>
                DB<=DATA(7 downto 4);
            when 188=>LCD_E<='1';			
            when 189=>LCD_E<='0';
            when 190=>DB<=DATA(3 downto 0);
            when 191=>LCD_E<='1';
            when 192=>LCD_E<='0';	
                
                DATA<=X"53"; -- S
            when 193=>
                DB<=DATA(7 downto 4);
            when 194=>LCD_E<='1';			
            when 195=>LCD_E<='0';
            when 196=>DB<=DATA(3 downto 0);
            when 197=>LCD_E<='1';
            when 198=>LCD_E<='0';
                
                DATA<=X"4D"; -- M
            when 199=>
                DB<=DATA(7 downto 4);
            when 200=>LCD_E<='1';			
            when 201=>LCD_E<='0';
            when 202=>DB<=DATA(3 downto 0);
            when 203=>LCD_E<='1';
            when 204=>LCD_E<='0';
                
                DATA<=X"41"; -- A
            when 205=>
                DB<=DATA(7 downto 4);
            when 206=>LCD_E<='1';			
            when 207=>LCD_E<='0';
            when 208=>DB<=DATA(3 downto 0);
            when 209=>LCD_E<='1';
            when 210=>LCD_E<='0';
                
                DATA<=X"3D"; -- =
            when 211=>
                DB<=DATA(7 downto 4);
            when 212=>LCD_E<='1';			
            when 213=>LCD_E<='0';
            when 214=>DB<=DATA(3 downto 0);
            when 215=>LCD_E<='1';
            when 216=>LCD_E<='0';
				
				DATA<=(x"30"+(conv_std_logic_vector((sayac),7)));
                when 217=>
                DB<=DATA(7 downto 4);
            when 218=>LCD_E<='1';			
            when 219=>LCD_E<='0';
            when 220=>DB<=DATA(3 downto 0);
            when 221=>LCD_E<='1';
            when 222=>LCD_E<='0';
				
				when 223=> LCD_RW<='0';
							  LCD_RS<='0'; --CMD							  
							  DB<="0011";
            when 232=>LCD_E<='1';
            when 233=>LCD_E<='0';
            when 238=>LCD_E<='1';
            when 239=>LCD_E<='0';
            when 244=>LCD_E<='1';
            when 245=>LCD_E<='0';
            when 250=>DB<="0010";
            when 251=>LCD_E<='1';
            when 252=>LCD_E<='0';
				
				
				when 272=>DATA<=X"10";
            when 273=>DB<=DATA(7 downto 4);
            when 274=>LCD_E<='1';			
            when 275=>LCD_E<='0';
            when 276=>DB<=DATA(3 downto 0);
            when 277=>LCD_E<='1';
            when 278=>LCD_E<='0';
				when 279=>LCD_RS<='1';             
                
				when 280=>say2:=215;
            
            when 3000=>--StopTimer<='1';
            when others=>
            end case;
        
        end if;
    end if;
    end process;

end Behavioral;

demorgan

bende alteranın de0 boardu var bu programı onda çalıştırabilirmiyim? Birde input olarak tanımladığımız clk girişini nerden alıcaz mantığını tam anlayamadım.Bu işte çok yeniyim saçma sorular sormuş olabilirim şimdiden çok teşekkürler.

vitruvius

Alıntı yapılan: demorgan - 19 Mayıs 2012, 17:44:21
bende alteranın de0 boardu var bu programı onda çalıştırabilirmiyim? Birde input olarak tanımladığımız clk girişini nerden alıcaz mantığını tam anlayamadım.Bu işte çok yeniyim saçma sorular sormuş olabilirim şimdiden çok teşekkürler.

Deneyebilirsiniz fakat de0'da lcd yok. Kendiniz eklemeniz gerekir. Ayrıca de0 board'unun bağlantı şemasına göre butona basılma durumunu if(buton='1') then ile değil if(buton='0') then şeklinde kontrol etmeniz gerekir. Clock da board'da zaten var. Board'un bilgilerinde nereye bağlı olduğunu görebilirsiniz. De0'da PIN_G21'e bağlıdır.

kamber7373

ELİNE EMEĞİNE SAĞLIK SPARTAN 3E DE DENEDİM GAYET İYİ ÇALIŞIYOR.  ;D