Verilog and a HD44780 LCD module

Discussion in 'Programmer's Corner' started by Daniel.Ferguson, Mar 5, 2007.

  1. Daniel.Ferguson

    Thread Starter New Member

    Mar 5, 2007
    1
    0
    Hi Folks,
    I'm trying to initialize and use a HD44780 LCD module that is connected to my Spartan 3A starter board from Xilinx. I've written some verilog and, presumably, correctly followed the section titled "Character LCD Screen" in their manual. http://www.xilinx.com/bvdocs/userguides/ug330.pdf

    Alas, being new to Verilog and everything else, i'm hard pressed to figure how close i may *really* be :)

    I've used Several Sites to help guide me, but they mostly use microcontrollers in their examples.

    http://www.fpga4fun.com/TextLCDmodule.html
    http://www.myke.com/lcd.htm
    http://home.iae.nl/users/pouweha/lcd/lcd.shtml

    here is the code i've written so far...
    i have no style, and know nothing about best-practices yet...sorry. But maybe someone could give me a clue/hint or some good old fashion guidance!

    Thanks!!

    Code ( (Unknown Language)):
    1.  
    2. `timescale 1ns / 1ps
    3.  
    4. module LCDTest1(iClock, LCD_E, LCD_RS, LCD_RW, LCD_DB);
    5.     input  iClock;
    6.     output LCD_E;
    7.     output LCD_RS;
    8.     output LCD_RW;
    9.     output LCD_DB;
    10.    
    11.     wire LCD_E;
    12.     wire LCD_RS;
    13.     wire LCD_RW;
    14.     wire[7:0] LCD_DB;
    15.    
    16.     reg         e;
    17.     reg         rs;
    18.     reg         rw;
    19.     reg[7:0] db;
    20.    
    21.    
    22.     //Responsible for putting the data on the bus
    23.     // and then pulsing the LCD_E line for 12 clocks
    24.     task WriteNybble;
    25.         input reg[3:0] nyb;
    26.         begin      
    27.             db[7:4] = nyb;         
    28.             #40     e   = 1'b1;        
    29.             #12     e   = 1'b0;
    30.         end
    31.     endtask
    32.    
    33.     initial
    34.         begin
    35.             #100;   //Waiting for global reset to complete
    36.  
    37.             //initialize my variables
    38.             e           =0;
    39.             rs          =0;
    40.             rw          =0;
    41.             db          =8'b0000_0000;
    42.            
    43.             #750000;//Wait for LCD to come on line ~15 ms          
    44.            
    45.             //Do the initialization sequence.
    46.             WriteNybble(4'b0011);
    47.             #250000;//5 ms
    48.             WriteNybble(4'b0011);
    49.             #8000;//160 us
    50.             WriteNybble(4'b0011);
    51.             #8000;//160 us
    52.             WriteNybble(4'b0010);
    53.             #8000;//160 us
    54.            
    55.             //Function Set  0x28
    56.             WriteNybble(4'b0010);
    57.             #50;
    58.             WriteNybble(4'b1000);
    59.             #8000;//160 us
    60.            
    61.             //Entry Mode Set 0x06
    62.             WriteNybble(4'b0000);
    63.             #50;//1 us
    64.             WriteNybble(4'b0110);
    65.             #8000;//160 us
    66.            
    67.             //Display On 0x0C
    68.             WriteNybble(4'b0000);
    69.             #50;//1 us
    70.             WriteNybble(4'b1100);
    71.             #8000;//160 us
    72.            
    73.             //Clear display  0x01
    74.             WriteNybble(4'b0000);
    75.             #50;//1 us
    76.             WriteNybble(4'b0001);
    77.  
    78.            
    79.             #85000;//1.64 MS
    80.            
    81.             //Set Initial DD Ram
    82.             WriteNybble(4'b1000);//sets to the first spot, upper  left
    83.             #50;//1 us
    84.             WriteNybble(4'b0000);//
    85.             #8000;//160 us
    86.            
    87.             rs = 1;
    88.             #50;
    89.             //0100_0001 - write an 'A'  to the screen!!!!
    90.             WriteNybble(4'b0100);
    91.             #50;//1 us
    92.             WriteNybble(4'b0001);
    93.             #8000;//160 us
    94.             rs=0;
    95.            
    96.         end
    97.        
    98.  
    99.     //and finally, connect the wires
    100.     assign LCD_E    = e;
    101.     assign LCD_RS   = rs;
    102.     assign LCD_RW   = rw;
    103.     assign LCD_DB   = db;
    104.    
    105. endmodule
    106.  
     
  2. Dave

    Retired Moderator

    Nov 17, 2003
    6,960
    143
    Hi Daniel and Welcome to All About Circuits.

    I can't help specifically with the Verilog since I've never used it, and it may seem a crazy question but does your design download and work on the Spartan board? If so, I would say you are 90% there irrespective of formatting or structure. I would also recommend you make all initialisations at the start of the code (even if the language does not require it) - you appear to have done this in a clear and well structured manner, generously comment you code for future reference (it doesn't matter how trivial the comment is, it will stand you in good stead later in the day), take extra care with your indents (improves reability and helps avoid problems later should you choose to modify the code), and some would argue make generous use of white-space (I personally don't like white-space in code, but again people suggest that it improves readability).

    Dave
     
  3. alvieboy

    New Member

    Aug 30, 2008
    1
    0
    You cannot use delays in verilog for synthesis. That is used only for simulation.

    I am writing a simple LCD controller (wishbone) for my Spartan 3E and using a ZPU, so please contact me if you want it.
     
  4. rana840

    New Member

    Nov 11, 2008
    1
    0
    hi, i am new to verilog and want to program a LCD, i need verilog code for lcd, can anyone help me??
     
Loading...