Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Writing a variable on LCD Screen

Status
Not open for further replies.

vitruvius

Newbie level 5
Joined
Apr 13, 2012
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Germany
Activity points
1,342
Hi all. I'm begginer at both Fpga and Vhdl and i have got Spartan-3E Starter Kit. I can write every character i want. For example, the character "R" from the CG-ROM have the value "01010010". I send this data like this:

Code:
DATA<=X"52"; --R
            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';

But how can i write a variable on lcd screen? I have a variable (cnt: integer range 0 to 8) which counts up each time i press the button. I want to see this on the lcd screen.

This is what i use for counter: (I can see the value of the integer by using leds)
Code:
architecture Behavioral of debounce is

signal counter : integer range 0 to 15000000;
signal buton_b : std_logic;
signal buton_g : std_logic;
signal cnt : integer range 0 to 8;
signal ledg : 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) --Cnt
    begin
		if(clk'event and clk='1') then
			if(buton_g='1') then
			cnt<=cntc+1;
					if(cnt=8) then
					cnt<=0;
					end if;
			end if;
		end if;
    end process;
    
    process(cnt)
    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;

Thank you.
 

When i tried like this:

Code:
DATA<=(conv_std_logic_vector((cnt),8));

i see a character looks like || and it doesn't change when i press the button.
 

u have to convert the integer to ascii..

and this is how u can convert a number of the range 0-9

Code:
int i;
......

...
lcd_write_byte(i+48);
 

I tried this:
Code:
DATA<=(conv_std_logic_vector((cnt+48),8));

But this time, i just see a "0" and it doesn't change when i press the button.
 

if its so then it means that your index numb cnt is not incrementing ... its zero even if u press the key .. check your code
 

But this part works correctly.

Code:
process(cnt)
    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;

I mean i can see the value of the "cnt" on leds.
 

ok ! do you mean that LEDs show the correct values?

then try this . instead of
Code:
DATA<=(conv_std_logic_vector((cnt+48),8));

so this
Code:
cnt=cnt+48;
DATA<=(conv_std_logic_vector((cnt),8));

try this way!
 

It still doesn't work.

My entire code:

Code:
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;
signal ledg : std_logic_vector(7 downto 0);
-----------------------------------------------------------------------------

--------------- Signals for Lcd ------------------------------
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) --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 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;
    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"43"; -- C
            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"4E"; -- N
            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"54"; -- T
            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"3D"; -- =
            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<=(conv_std_logic_vector((cnt+48),8));
            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';                
            
            when 3000=> --StopTimer <='1';
            when others=>
            end case;
        
        end if;
    end if;
    end process;

end Behavioral;
 

which compiler are u using??

by the way try this instead of starting your cnt as 0 start it with value 3 and the check .. you would get 3 all the time with DATA<=(conv_std_logic_vector((cnt+48),8));
 

I'm using Xilinx ISE Design Suite 13.3.

I've changed this part
Code:
signal cnt : integer range 0 to 8 :=3;

And i get "CNT=3" all the time, it doesn't change when i press the button.
 

so the problem is in the code where you update the value of CNT. I havent used this Xilinx ISE Design Suite so I cant tell u the exact solution but check your syntax, there might be a problem , or may bethere is a problem with the logic you are following .

the root cause is your value of CNT doesnt change in the program!
 

I think the problem is with the StopTimer signal. My lcd process starts with:

Code:
begin
    if (clk'EVENT and clk='1') then
    if (StopTimer='0') then

But "StopTimer" never changes..
 

i dont know about the syntax of your ide but in c comparisons are == and if u declare int i='0' then its value is ASCII value of the number zero
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top