arishsu
Member level 3
I tried to run this code on the fpga, but it is showing some garbage characters.
I got this code from the web. Please help me to correct the code.
And this is the ucf file.
I got this code from the web. Please help me to correct the code.
Code:
module test_lcd(clk,sf_e,rs,rw,a,b,c,d,e);
input clk;//50Mhz onboard clk
output reg sf_e;//1 lcd access (0 strataFlash access)
output reg e;//enable(1)
output reg rs;//Register select(1 data bits for R/W)
output reg rw;//Read/Write, 1/0
output reg a;//1st data bits (to form a nibble)
output reg b;//2nd data bits (to form a nibble)
output reg c;//3rd data bits (to form a nibble)
output reg d;//4th data bits (to form a nibble)
reg[26:0] count=0;//27-bit count. 0 to 128M-1, over 2 secs
reg[5:0] code;//6-bit different signals to give out
reg refresh;//refresh lcd rate @ about 25Hz
always@(posedge clk)
begin
count <= count+1;
case (count[26:21]) //as top 6 bits change
//power on init can be carried out before this loop to avoid the flickers
0: code <= 6'h03;//power on init sequence
1: code <= 6'h03;//this is needed atleast once
2: code <= 6'h03;//when LCD is powered on
3: code <= 6'h03;//it flickers existing char display
//table 5-3 function set
//send 00 and upper nibble 0010, then 00 and lower nibble 10xx
4: code <= 6'h02;//function set, upper nibble 0010
5: code <= 6'h08;//lower nibble 1000(10xx)
//table 5-3, entry mode
//send 00 and upper nibble 0000, then 00 and lower nibble 01 I/D S
//last 2 bit of the lower nibble I/D bit(increment 1 decrement 0)
6: code <= 6'h00;//see table, upper nibble 0000, then lower nibble
7: code <= 6'h06;//0110 incr, shift disabled
//table 5-3,display on/off
//send 00 and upper nibble 0000, then 00 and lower nibble 1DCB
//D:1, show char represented by code in DDR, 0, don't but code remains
//B:1, show cursor, 0, don't
//C:1, cursor blinks (if shown), 0, dont blink (if shown)
8: code <= 6'h00;//display on/off, upper nibble 0000
9: code <= 6'h0C;//lower nibble 1100(1 D C B)
//table 5-3 clear display, 00 and upper nibble 0000, then 00 and lower nibble 0001
10: code <= 6'h00;//clear display, 00 and upper nibble 0000
11: code <= 6'h01;//then 00 and lower nibble 0001
//charecters are then given out. cursor will advance to the right
//table 5-3, write data to DD RAM (or CG RAM)
//fig 5-4, 'H,' send 10 and upper nibble 0100, then 10 and lower nibble 1000
12: code <= 6'h24;//'H' higher nibble
13: code <= 6'h28;//'H'lower nibble
14: code <= 6'h26;//e
15: code <= 6'h25;
16: code <= 6'h26;//l
17: code <= 6'h2C;
18: code <= 6'h26;//l
19: code <= 6'h2C;
20: code <= 6'h26;//o
21: code <= 6'h2F;
22: code <= 6'h22;//,
23: code <= 6'h2C;
//table 5-3, set DDR address
//position the cursor on to the start of the 2nd line
//send 00 and upper nibble 1???, ??? is the highest 3 bit of the DDR
//address to move the cursor to, then 00 and lower 4 bits of the address
//so ??? is 100 and then 0000 for h40
24: code <= 6'b001100;//position cursor to 2nd line upper nibble
25: code <= 6'b000000;//lower nibble: h0
//charecters are then given out. cursor will advance to the right
26: code <= 6'h25;//W
27: code <= 6'h27;
28: code <= 6'h26;//o
29: code <= 6'h2F;
30: code <= 6'h27;//r
31: code <= 6'h22;
32: code <= 6'h26;//l
33: code <= 6'h2C;
34: code <= 6'h26;//d
35: code <= 6'h24;
36: code <= 6'h22;//!
37: code <= 6'h21;
//Table 5-3, Read Busy Flag and address
//send 01 BF (Busy Flag) xxx, then, 01xxxx
//idling
default: code <=6'h10;//the rest unused time
endcase
//refresh (enable) LCD when bit 20 of the count is 1
//it flips when counted up to 2M, and flips again after another 2M
refresh <=count[20];//flip rate about 25(50MHz/2^21=2M)
sf_e <= 1;
{e,rs,rw,a,b,c,d} <= {refresh, code};
end //always
endmodule
And this is the ucf file.
Code:
NET "clk" LOC = "C9" | IOSTANDARD = LVCMOS33 ;
NET "sf_e" LOC = "D16" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
NET "e" LOC = "M18" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
NET "rs" LOC = "L18" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
NET "rw" LOC = "L17" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
# The LCD four-bit data interface is shared with the StrataFlash.
NET "a" LOC = "R15" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
NET "b" LOC = "R16" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
NET "c" LOC = "P17" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
NET "d" LOC = "M15" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;