EmbDev.net

Forum: FPGA, VHDL & Verilog Displaying characters to the LCD screen verilog.


von Jond L. (204_proj)


Rate this post
useful
not useful
Hello everyone.

At the moment I am trying to create a maze game on a DE2-115 FPGA board.
Here is a video showing what I am trying to replicate.
https://www.youtube.com/watch?v=rNZkd0Rqhp8

So, how it works is that you first draw out any maze you want. You then 
assign rooms in the maze to any symbol or letter.
These symbols correspond to the room you are in at any moment in the 
maze.

Also, there are four push buttons. [up] [down] [left] [right]
As you can tell these push buttons change your position to another 
symbol depending on what button you press.

So, for example if you are in room X and then you press the [right] 
button, the LCD will display the room Y. So, you shifted from X --> Y.

Right now, I just managed to get Verilog code working that sends 
characters to the LCD screen.

Hence, my LCD on my board the moment just display [ Room: X ]

I'm wondering if you guys can help me figure out code that will allow me 
to change that letter "X" to any other letter depending on the button I 
push.

This is the code I have so far:

always @ (posedge clk) begin
    count <= count + 1;
    case (count[k+7:k+2])
      0: lcd_code <= 6'b000010;    // function set
      1: lcd_code <= 6'b000010;
      2: lcd_code <= 6'b001100;
      3: lcd_code <= 6'b000000;    // display on/offcontrol
      4: lcd_code <= 6'b001100;
      5: lcd_code <= 6'b000000;    // display clear
      6: lcd_code <= 6'b000001;
      7: lcd_code <= 6'b000000;    // entry mode set
      8: lcd_code <= 6'b000110;
      9: lcd_code <= 6'h25;        // R
     10: lcd_code <= 6'h22;
     11: lcd_code <= 6'h26;        // o
     12: lcd_code <= 6'h2F;
     13: lcd_code <= 6'h26;        // o
     14: lcd_code <= 6'h2F;
     15: lcd_code <= 6'h26;        // m
     16: lcd_code <= 6'h2D;
     17: lcd_code <= 6'h23;        // :
     18: lcd_code <= 6'h2A;
     19: if (buttonRight)  // if buttonRight = 1
             lcd_code <= 6'h25; //send higher value of "X"
          else // if buttonRight = 0
             lcd_code <= 6'h25;// send higher value of "R"
     20: if (buttonRight) // If buttonright = 1
            lcd_code <= 6'h28; // send lower value of "X"
          else // if buttonRight = 0
             lcd_code <= 6'h22; // send lower value of "R"
      21: count <= 7;
      default: lcd_code <= 6'b010000;
               endcase

   if (lcd_rw)
   lcd_busy <= 0;
   lcd_stb <= ^count[k+1:k+0] & ~lcd_rw & lcd_busy;  // clkrate/2^(k+2)
   lcd_stuff <= {lcd_stb,lcd_code};
   {lcd_e,lcd_rs,lcd_rw,lcd_7,lcd_6,lcd_5,lcd_4} <= lcd_stuff;

  end

This is pretty simple code that initalizes the LCD screen and makes the 
LCD screen output the word "Room: "

Then on line 19, it checks the push button to see if its pressed, if it 
is then send the letter "X" if not send the letter "R"
The part of the code from line 19 and 20 is just something I made up 
that doesn't really work as I intend.
To summarize my question, I'm just trying to display characters on the 
LCD Screen and have them change depending on one of the push buttons 
thats pressed.

Any feedback is appreciated.

von Klakx (Guest)


Rate this post
useful
not useful
Sounds like you need pushbutton debouncing

von Jond L. (204_proj)


Rate this post
useful
not useful
Yes, I later did add a debouncing module and it helped with changing the 
symbols.

I kind of changed my code, so now I added a counter that increases by 
one every time the push button is pressed (positive edge of the push 
button).

I made a case statement

 case (counter)
 0: lcd display A
 1: lcd display B

etc..

This kind of works but it just makes you move across different letters 
sequentially. I still am trying to figure out how to move for example in 
4 directions. What I mean is have it so that the letter B will change to 
4 different letters depending if you press up, down, left, right. Right 
now I just have it going to C when you push the right button.

Thanks for the feedback though. :)

von Verilog hotline (Guest)


Rate this post
useful
not useful
Make an array of rooms (of the lcd codes). Write the first n rooms of a 
horizontal row into the array, then the next n of the next horizontal 
row and so on. Then you have an array of rooms with the index 0..n-1 
first row, n..2*n-1 second row and so on.
Initialize your actual_index with 0. Always print the 
array(actual_index). On button push, increment/decrement the 
actual_index. When pressing button right/left, calculate +/-1, when 
pressing down/up +/-n.
Mind the wrap at the borders of the maze and the valid number range of 
your index when you calculate it.

This solution is neither perfect in resource usage nor in flexibility 
but it is a starting point.

von Dhiya (Guest)


Rate this post
useful
not useful
What does line 21 implement

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.