Please read the instructions carefully and write the code for problem. Display f
ID: 1846978 • Letter: P
Question
Please read the instructions carefully and write the code for problem.
Display following features on LCD. Use two switches as control signals S1 and S2.S1 S2 Functionality 0 0 Display 4 characters of your first name on the first row and left corner of LCD. Your name should be printed in reverse order. 0 1 Display 4 characters of your first name on the 2nd row and right corner of LCD. Your name should be printed in normal order. 1 0 Shift 4 characters of your first name on the 2nd row to the left.
Your name should be printed in normal order.
1 1 Display real time clock in the following format on the center of LCD. First Row: Design Engineer Name ( Note: This should be your name and you will be a good design engineer in the future! :) ) Second Row: # Note: replace "#" by decimal number and update this number in real time every second. This number should display from 1 to 10 repeatedly. The only accepted display format is 1, 2, 3, 4, ..., 9, 10. You should not display 01, 02, 03, 04 .... Reference: http://www.dinceraydin.com/lcd/commands.htm S1 S2 Functionality 0 0 Display 4 characters of your first name on the first row and left corner of LCD. Your name should be printed in reverse order. 0 1 Display 4 characters of your first name on the 2nd row and right corner of LCD. Your name should be printed in normal order. 1 0 Shift 4 characters of your first name on the 2nd row to the left.
Your name should be printed in normal order.
1 1 Display real time clock in the following format on the center of LCD. First Row: Design Engineer Name ( Note: This should be your name and you will be a good design engineer in the future! :) ) Second Row: # Note: replace "#" by decimal number and update this number in real time every second. This number should display from 1 to 10 repeatedly. The only accepted display format is 1, 2, 3, 4, ..., 9, 10. You should not display 01, 02, 03, 04 .... Reference: http://www.dinceraydin.com/lcd/commands.htm
Explanation / Answer
I have implemented a verilog code for the given conditions below.
The stategy is as follows:
I have stored in a array all the values that are to be passed to the LCD.
first 5 values have the general initialisations for the LCD.
starting 5 element array has the commands(5,6) and data(7,8,9,10) for 00 input condition and terminated by 0xFF
starting 15 element array has the commands(15,16) and data(17,18,19,20) for 01 input condition and terminated by 0xFF
starting 25 element array has the commands(25,26) and data(27,28,29,30) for 10 input condition and terminated by 0xFF
starting 35 element array has the commands(35,36) and data(37,38,39,40...) for 10 input condition and terminated by 0xFF
starting 45 element array has the commands(45) and data(46,47(occasionally to represent 10)) for 11 input condition and terminated by 0xFF.
I increment a counter count ever 1us(assuming input clock is 100MHz) and a countR(for real time 1s incremnt) every 2ms.
count is reloaded after 2000 clocks(2ms) and countR is reloaded after 500 ie 500*2000 = 1ms
every 2ms i check if there is any new input command and execute appropriately(commands and data are send to lcd every 2ms) and stop as soon as i see the terminator(0xFF). For the real time clock, at every reload of countR i increment 46th element in the array so that it can be shown on lcd. the trick part is for displaying 10, i set 46 as 0x31(to display 1) and set 47 as 0x30(to display zero) and shift the terminator to 48.
Hope you understood the flow...the verilog code is as follows....
module lcd(rs,rw,e,data_temp,clk,S1,S2);
output reg rs,rw,e;
input clk;
input S1,S2;
output reg [8:0] data_temp;
reg [15:0]count;
reg [8:0]countR; //maximum of 500
reg [8:0]init [48:0];
reg lcd;
reg ready; // flag to check if the initialising is done
reg read;
reg [1:0]command;
initial begin
rs = 0;
rw = 0;
e = 0;
count = 0;
//each command should be followed by delay of atleast the maximum execution time (1.64ms)
init[0]=0x38; // 2-line and 5x7 matrix
init[1]=0x0F; // Display ON cursor blinking(0x0C for with cursor OFF)
init[2]=0x06; // Increment cursor(right)
init[3]=0x01; // Clear display screan
init[4]=0x80; // Force cursor to begining of 1st line[80,81,....8F(16nos)]
init[5]=0x83; // cursor at 4 th position as we need the name to be in reverse order
init[6]=0x04; // decrement cursor
init[7]='A';//name0
init[8]='B';//name1
init[9]='C';//name2
init[10]='D';//name3
init[11]=0xFF;
init[12]=4;
init[13]=6;
init[14]=5;
init[15]=0xCC; // cursor at 4th last position on right bottom corner
init[16]=0x06; // increment cursor
init[17]='A';//name0
init[18]='B';//name1
init[19]='C';//name2
init[20]='D';//name3
init[21]=0xFF;
init[22]=5;
init[23]=0x83;
init[24]=0x04;
init[25]=0xC0; // cursor at 2nd row first position
init[26]=0x05; // cursor not moved, name shifted to left, so enter name in reverse direction to show correctly
init[27]='D';//name3
init[28]='C';//name2
init[29]='B';//name1
init[30]='A';//name0
init[31]=0xFF;
init[32]=4;
init[33]=6;
init[34]=4;
init[35]=0x80; // cursor at 1st position as we need the design engineer name -> assuming name is not larger than 6 chars
init[36]=0x06; // increment cursor
init[37]=6;//name0
init[38]=0;//name1
init[39]=1;//name2
init[40]=8;//name3
init[41]=0;//name4
init[42]=4;
init[43]=6;
init[44]=0xFF;
init[45]=0xC0;//cursor at 2nd row first position
init[46]=0x31; // to display the real time -> ascii equivalent of 1
init[47]=0xFF;
init[48]=0xFF;
command = 0;
read = 1;
initcount = 0;
lcd = 1;
ready = 0;
end
//assuming the input clock frequency is 100MHz -> 1us per clock
//we need delay of 1.64ms -> rounding it to 2ms -> 2000 clock
//also the input switches will be read every 2ms
//1s -> 2000ms * 500
always @(posedge clk) begin
count = count + 1;
if (count == 10 && e == 0) begin
e=1;//toggling the e of LCD
end
if (count == 20 && e == 1) begin
e=0;//toggling the e of LCD
rw = 1;
end
if(count == 2000) begin
countR = countR+1;
if(countR == 500) begin
countR = 0;
if(command==3) begin // checking if the part 4 is selected and incrementing real time count
done = 1; // to indicate a new real time value to be written
init[46] = init[46] + 1;
if(init[46] == 0x3A) begin
init[46] = 0x31;
init[47] = 0x30;
end
else if(init[47] == 0x30) begin
init[46] = 0x31;
init[47] = 0xFF;
end
end
end
end
if (count == 2000 && ready==0 ) begin // initialising the LCD
count = 0;
data_temp = init[initcount];
initcount = initcount + 1;
rw = 0; // write data/command to lcd
if (initcount == 5) begin
ready = 1; //initialising done
end
end
if (count == 2000 && ready==1 ) begin
count = 0;
if(read & (command !={S2:S1}) ) begin //read the input switch value if the previous
//value is different from now and the system is ready to take new command
command = {S2:S1};
case({S2:S1})
0:initcount = 5; //5-14 countains the instruction to enter the reverse order of name
1:initcount = 15;//15-24 countains the instruction to enter the right order of name
2:initcount = 25;//25-34 countains the instruction to enter the right order of name shifted
3:initcount = 35;//35-end countains the instruction to enter real time changing value
endcase
read = 0;
countR = 0;
end
if(read == 0) begin // check if a new value is read
if(initcount%10 == 7) begin
//change from command mode to data mode
rs = 1;
end
data_temp = init[initcount];//output data or command as per the index initcount
initcount = initcount + 1;
rw = 0; // write data/command to lcd
if(init[initcount] == 0xFF) begin
read = 1;// to enable reading the next input command
countR = 499;
rs = 0;//command mode
if (command == 3) begin
initcount = 45;
end
end
end
else if(done == 1) begin // a new value has been entered in the real time
if(initcount%10 == 6) begin
//change from command mode to data mode
rs = 1;
end
data_temp = init[initcount];//output data or command as per the index initcount
initcount = initcount + 1;
rw = 0; // write data/command to lcd.
if(init[initcount] == 0xFF) begin
done = 0;// to signal the end of current execution
rs = 0;//command mode
if (command == 3) begin
initcount = 45;
end
end
end
end
endmodule
Please let me know if you need any further clarifications..:)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.