Chapter 4 – Using the DIO2 Board Part 2 (LCD Module)

 

1)      Create anew project (“chap4”)

2)      Add a new Verilog source (“LCD_data”) and paste in the following code.  It controls the LCD and writes a message.

 

module LCD_data(A, D0, D1, D2, D3, D4, D5, D6, D7, RS);

  input [4:0] A;

  output D0, D1, D2, D3, D4, D5, D6, D7, RS;

 

  reg [8:0] writedata;

 

  OBUF  U1 (.I(writedata[0]), .O(D0));

  OBUF  U2 (.I(writedata[1]), .O(D1));

  OBUF  U3 (.I(writedata[2]), .O(D2));

  OBUF  U4 (.I(writedata[3]), .O(D3));

  OBUF  U5 (.I(writedata[4]), .O(D4));

  OBUF  U6 (.I(writedata[5]), .O(D5));

  OBUF  U7 (.I(writedata[6]), .O(D6));

  OBUF  U8 (.I(writedata[7]), .O(D7));

  OBUF  U9 (.I(writedata[8]), .O(RS));

 

  always @ (A) begin

    if (A == 1)  writedata = 9'h38;

    if (A == 2)  writedata = 9'h6;

    if (A == 3)  writedata = 9'hE;

    if (A == 4)  writedata = 9'h1;

    if (A == 5)  writedata = 9'h80;

    if (A == 6)  writedata = 9'h143;  // first letter of message

    if (A == 7)  writedata = 9'h150;

    if (A == 8)  writedata = 9'h153;

    if (A == 9)  writedata = 9'h143;

    if (A == 10) writedata = 9'h134;

    if (A == 11) writedata = 9'h138;

    if (A == 12) writedata = 9'h133;

    if (A == 13) writedata = 9'h1A0;

    if (A == 14) writedata = 9'h172;

    if (A == 15) writedata = 9'h16F;

    if (A == 16) writedata = 9'h163;

    if (A == 17) writedata = 9'h16B;

    if (A == 18) writedata = 9'h173;

    if (A == 19) writedata = 9'h121;

    if (A == 20) writedata = 9'h121;

  end

 

endmodule

 

3)      Create another source called “CLK_DIV.v” and paste the following.  It slows the clock

 

module CLK_DIV (CLK, CLK2);

  input CLK;

  output CLK2;

 

  reg [17:0] counter;

  reg CLK2;

  wire CLKi;

 

  IBUFG U1 (.I(CLK), .O(CLKi));

 

  always @ (posedge CLKi) begin

    counter = counter + 1;

       if (counter == 0) CLK2 = ~CLK2;

  end

endmodule

 

4)      Create Schematic symbols from both Verilog files.

5)      Create a new schematic and draw the following:

 

6)      Put the following in the constraints file:

 

NET "CLK" LOC = "P80";

NET "D0" LOC = "P150";

NET "D1" LOC = "P149";

NET "D2" LOC = "P152";

NET "D3" LOC = "P151";

NET "D4" LOC = "P160";

NET "D5" LOC = "P154";

NET "D6" LOC = "P162";

NET "D7" LOC = "P161";

NET "button" LOC = "P77";

NET "E" LOC = "P148";

NET "RS" LOC = "P145";

NET "RW" LOC = "P146";

 

7)      Change the startup clock to JTAG, generate the programming file and program the chip.

8)      When you press the button on the D2E board, a message should flash on the LCD and erase.  As long as you hold the button down, this should repeat.

9)      To modify the message, change the Verilog code starting with the line that says “first letter of message”.  Use the following table for what number to use with each character.  The highest but (RS) must be 1 to write a character.  For more info, read the DIO2 manual on how to use the LCD.

 

Assignments

1)      Write any message on the screen, then make it stay when the button is pushed (not flashing like it does in the example).

2)      Modify assignment one to where the message appears automatically (at startup with no button pressed), and then use the button on the D2E board to make the message scroll left and right on the screen (the same button goes left until it hits the end and then starts going right and then back, etc.)  You can have the button be pressed each step the words move, or have it move as long as the button is being held.