{"id":726,"date":"2020-12-02T15:59:39","date_gmt":"2020-12-02T15:59:39","guid":{"rendered":"http:\/\/dsd.webs.upv.es\/?p=726"},"modified":"2021-05-12T07:16:03","modified_gmt":"2021-05-12T07:16:03","slug":"verificacion-fisisca-risc-v-con-lcd","status":"publish","type":"post","link":"https:\/\/dsd.webs.upv.es\/?p=726","title":{"rendered":"Verificaci\u00f3n f\u00edsica RISC-V con LCD"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">El planteamiento de esta entrada es si podemos hacer una verificaci\u00f3n f\u00edsica del RISC-V, en la placa DE2-115 mediante el LCD.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<iframe loading=\"lazy\" allowfullscreen=\"\" src=\"https:\/\/media.upv.es\/player\/embed.html?id=0dac3490-34b0-11eb-a886-e59b4ce73a01\" style=\"border:0px #FFFFFF none;\" name=\"Paella Player\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0px\" marginwidth=\"0px\" width=\"640\" height=\"360\"> <\/iframe>\n\n\n\n<p class=\"wp-block-paragraph\">La controladora verilog de LCD proviene de la siguiente direcci\u00f3n y autor\u00eda:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/gist.github.com\/windhooked\/40f6c9a6d35062a5d24503d2bcb07ddd\">https:\/\/gist.github.com\/windhooked\/40f6c9a6d35062a5d24503d2bcb07ddd<\/a> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">La adaptaci\u00f3n que he realizado ha consistido fundamentalmente en generar una salida adicional que resetee el micro RISC-V mientras el LCD arranca, de forma que cuando est\u00e9 el LCD inicializado, liberemos el micro RISC-V y pueda empezar a ejecutar sus instrucciones. Esa salida adicional se denomina RST_output. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">Otro cambio que introduje fue un enable general denominado TC_general de un contador m\u00f3dulo 20 que nos garantice que los niveles a 1 de LCD_E sean superiores  a 400 ns (trabajamos con un reloj de 50 MHz), aunque c\u00f3mo ver\u00e9is he multiplicado por 20 todas las temporizaciones y solo as\u00ed he conseguido que funcionara.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:verilog decode:true \">module FPGA_2_LCD_RAFA(\n\tCLK, LCD_RS, LCD_RW, LCD_E, LCD_DB, RDY, DATA, OPER, ENB, RST, \t\tRST_output \n);\ninput CLK;\t\t\t\/\/ For this code to work without modification, CLK should equal 24MHz\ninput [7:0] DATA;\t\t\t\/\/ The Data to send to the LCD Module\ninput [1:0] OPER;\t\t\t\/\/ The Type of operation to perform (data or instruction) \ninput ENB;\t\t\t\/\/ Tells the module that the data is valid and start reading DATA and OPER\ninput RST;\n \noutput RDY;\t\t\t\/\/ Indicates that the module is Idle and ready to take more data\noutput RST_output;\noutput LCD_RS, LCD_RW, LCD_E;\noutput [7:0] LCD_DB;\n \nreg RST_output;\nwire [7:0] DATA;\nwire [1:0] OPER;\nwire ENB;\nreg RDY;\n \nreg [7:0] LCD_DB=0;\nreg LCD_RW=0;\t\t\t\/\/ always write to (and never read from) the LCD\nreg LCD_RS=0;\t\t\t\/\/ HI means Data, LOW means Instruction\/Command\nreg LCD_E=0;\n \n\/*----------------------SOME NOTES-------------------\nwhen RS and R\/W change STATE...wait for at least 20ns ( ~1clock cycle )\nafter that period of time bring E high and invert E every 400 ns (can be larger) ( ~20 clock cycles)\nwhile E is HI, set DATA\nwhen E goes LOW, maintain DATA for atleast 10ns\n \nCLOCK=50MHz ==&gt; 20 ns\n-------------------------END OF NOTES-------------------*\/\n\/\/===============================================================================================\n\/\/------------------------------Define the Timing Parameters-------------------------------------\n\/\/===============================================================================================\nparameter [19:0] t_40ns \t= 1;\t\t\/\/20ns \t\t== ~1clk\nparameter [19:0] t_250ns \t= 6;\t\t\/\/400ns \t== ~20clks\nparameter [19:0] t_42us \t= 1008;\t\t\/\/21us \t\t== ~1008clks\nparameter [19:0] t_100us \t= 2400;\t\t\/\/50us\t\t== ~2400clks\nparameter [19:0] t_1640us \t= 39360;\t\/\/0.82ms \t== ~39360clks\nparameter [19:0] t_4100us \t= 98400;\t\/\/2.05ms    \t== ~98400clks\nparameter [19:0] t_15000us\t= 360000;\t\/\/7,5ms \t\t== ~360000clks\n \n\/\/===============================================================================================\n\/\/------------------------------Define the BASIC Command Set-------------------------------------\n\/\/===============================================================================================\nparameter [7:0] SETUP\t\t= 8'b00111000;\t\/\/Execution time = 42us, sets to 8-bit interface, 2-line display, 5x7 dots\nparameter [7:0] DISP_ON\t\t= 8'b00001100;\t\/\/Execution time = 42us, Turn ON Display\nparameter [7:0] ALL_ON\t\t= 8'b00001111;\t\/\/Execution time = 42us, Turn ON All Display\nparameter [7:0] ALL_OFF\t\t= 8'b00001000;\t\/\/Execution time = 42us, Turn OFF All Display\nparameter [7:0] CLEAR \t\t= 8'b00000001; \t\/\/Execution time = 1.64ms, Clear Display\nparameter [7:0] ENTRY_N\t\t= 8'b00000110;\t\/\/Execution time = 42us, Normal Entry, Cursor increments, Display is not shifted\nparameter [7:0] HOME \t\t= 8'b00000010; \t\/\/Execution time = 1.64ms, Return Home\nparameter [7:0] C_SHIFT_L \t= 8'b00010000; \t\/\/Execution time = 42us, Cursor Shift\nparameter [7:0] C_SHIFT_R \t= 8'b00010100; \t\/\/Execution time = 42us, Cursor Shift\nparameter [7:0] D_SHIFT_L \t= 8'b00011000; \t\/\/Execution time = 42us, Display Shift\nparameter [7:0] D_SHIFT_R \t= 8'b00011100; \t\/\/Execution time = 42us, Display Shift\n \n\/\/===============================================================================================\n\/\/-----------------------------Create the counting mechanisms------------------------------------\n\/\/===============================================================================================\nreg [19:0] cnt_timer=0; \t\t\t\/\/39360 clks, used to delay the STATEmachine during a command execution (SEE above command set)\nreg flag_250ns=0,flag_42us=0,flag_100us=0,flag_1640us=0,flag_4100us=0,flag_15000us=0;\nreg flag_rst=1;\t\t\t\t\t\/\/Start with flag RST set. so that the counting has not started\nreg flag_40ns;\nreg  [4:0] idea;\n\nwire TC_general;\nassign TC_general=(idea==5'b10011)?1'b1:1'b0;\nalways @(posedge CLK, negedge RST) begin\nif (!RST)\nbegin\n\t\tflag_40ns   &lt;=1'b0;\n\t\tflag_250ns\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\tflag_42us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\tflag_100us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\tflag_1640us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\tflag_4100us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\tflag_15000us    &lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\tcnt_timer\t&lt;=\t20'b0;\n\t\tidea&lt;=5'b00000;\n\nend\nelse\nbegin\nif (idea==5'b10011)\n\tidea&lt;=5'b00000;\nelse\n\tidea&lt;=idea+1;\nif (TC_general)\n\t\tif(flag_rst ) begin\n\t\t\tflag_40ns   &lt;=1'b0;\n\t\t\tflag_250ns\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\t\tflag_42us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\t\tflag_100us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\t\tflag_1640us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\t\tflag_4100us\t&lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\t\tflag_15000us    &lt;=\t1'b0;\t\t\/\/Unlatch the flag\n\t\t\tcnt_timer\t&lt;=\t20'b0;\t\t\n\t\tend\n\t\telse \n\t\tbegin\n\t\t\tflag_40ns&lt;=\tcnt_timer[0]; \/\/si el reloj es de 50 MHz , esta se\u00f1al es de 25 MHz\n\t\t\tif(cnt_timer&gt;=t_250ns) begin\t\t\t\n\t\t\t\tflag_250ns\t&lt;=\t1'b1;\n\t\t\tend\n\t\t\telse begin\t\t\t\n\t\t\t\tflag_250ns\t&lt;=\tflag_250ns;\n\t\t\tend\n\t\t\t\/\/----------------------------\n\t\t\tif(cnt_timer&gt;=t_42us) begin\t\t\t\n\t\t\t\tflag_42us\t&lt;=\t1'b1;\n\t\t\tend\n\t\t\telse begin\t\t\t\n\t\t\t\tflag_42us\t&lt;=\tflag_42us;\n\t\t\tend\n\t\t\t\/\/----------------------------\n\t\t\tif(cnt_timer&gt;=t_100us) begin\t\t\t\n\t\t\t\tflag_100us\t&lt;=\t1'b1;\n\t\t\tend\n\t\t\telse begin\t\t\t\n\t\t\t\tflag_100us\t&lt;=\tflag_100us;\n\t\t\tend\n\t\t\t\/\/----------------------------\n\t\t\tif(cnt_timer&gt;=t_1640us) begin\t\t\t\n\t\t\t\tflag_1640us\t&lt;=\t1'b1;\n\t\t\tend\n\t\t\telse begin\t\t\t\n\t\t\t\tflag_1640us\t&lt;=\tflag_1640us;\n\t\t\tend\n\t\t\t\/\/----------------------------\n\t\t\tif(cnt_timer&gt;=t_4100us) begin\t\t\t\n\t\t\t\tflag_4100us\t&lt;=\t1'b1;\n\t\t\tend\n\t\t\telse begin\t\t\t\n\t\t\t\tflag_4100us\t&lt;=\tflag_4100us;\n\t\t\tend\n\t\t\t\/\/----------------------------\n\t\t\tif(cnt_timer&gt;=t_15000us) begin\t\t\t\n\t\t\t\tflag_15000us\t&lt;=\t1'b1;\n\t\t\tend\n\t\t\telse begin\t\t\t\n\t\t\t\tflag_15000us\t&lt;=\tflag_15000us;\n\t\t\tend\n\t\t\t\/\/----------------------------\n\t\t\tcnt_timer\t&lt;= cnt_timer + 1;\n\t\tend\nend\nend\n \n\/\/##########################################################################################\n\/\/-----------------------------Create the STATE MACHINE------------------------------------\n\/\/##########################################################################################\nreg [3:0] STATE;\nreg [1:0] SUBSTATE;\n \nalways @(posedge CLK, negedge RST) begin\nif (!RST)\nbegin\n\t\t\tLCD_RS\t&lt;=\t\t1'b0;\t\t\t\t\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t&lt;= \t1'b0;\t\t\t\t\t\t\t\t\t\t\/\/Indicate a write operation\n\t\t\tLCD_E\t\t&lt;=\t\t1'b0;\t\t\t\t\t\t\t\t\t\t\/\/We are in the initial setup, keep low until 250ns has past\n\t\t\tLCD_DB \t&lt;= \t8'b00000000;\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tSUBSTATE\t&lt;=\t\t0;\n\t\t\tSTATE&lt;=0;\n\t\t\tflag_rst\t\t\t&lt;=\t1'b0; \n\t\t   RST_output &lt;=1'b0;\nend\nelse\n   if (TC_general)\n \tcase(STATE)\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t0: begin \/\/---------------Initiate Command Sequence (RS=LOW)-----------------------------\n\t\t\tLCD_RS\t&lt;=\t\t1'b0;\t\t\t\t\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t&lt;= \t1'b0;\t\t\t\t\t\t\t\t\t\t\/\/Indicate a write operation\n\t\t\tLCD_E\t\t&lt;=\t\t1'b0;\t\t\t\t\t\t\t\t\t\t\/\/We are in the initial setup, keep low until 250ns has past\n\t\t\tLCD_DB \t&lt;= \t8'b00000000;\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tSUBSTATE\t&lt;=\t\t0;\n\t\t\tif(!flag_15000us) begin\t\t\t\t\t\t\t\t\t\/\/WAIT 15ms...worst case scenario\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\t\t\/\/Remain in current STATE\n\t\t\t\tflag_rst\t\t\t&lt;=\t1'b0; \t\t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\n\t\t\tend\n\t\t\telse begin \t\t\t\t\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\tflag_rst\t\t\t&lt;=\t1'b1; \t\t\t\t\t\t\/\/Stop counting\t\t\t\t\n\t\t\tend\t\t\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t1: begin \/\/-----------SET FUNCTION #1, 8-bit interface, 2-line display, 5x7 dots---------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= SETUP;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_4100us) begin\t\t\t\t\t\t\/\/WAIT at least 4.1ms (required for Initialization)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\t\n\t\tend\t\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t2: begin \/\/-----------SET FUNCTION #2, 8-bit interface, 2-line display, 5x7 dots---------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= SETUP;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_100us) begin\t\t\t\t\t\t\/\/WAIT at least 100us (required for Initialization)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\t\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t3: begin \/\/-----------SET FUNCTION #3, 8-bit interface, 2-line display, 5x7 dots---------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= SETUP;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_100us) begin\t\t\t\t\t\t\/\/WAIT at least 100us (required for Initialization)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t4: begin \/\/-----------SET FUNCTION #4, 8-bit interface, 2-line display, 5x7 dots---------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= SETUP;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_100us) begin\t\t\t\t\t\t\/\/WAIT at least 100us (required for Initialization)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t5: begin \/\/-----------------DISPLAY, Display OFF, Cursor OFF, Blinking OFF------------------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= ALL_OFF;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_42us) begin\t\t\t\t\t\t\t\/\/WAIT at least 42us (required for operation to process)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t6: begin \/\/-------------------DISPLAY CLEAR, clear the display screen--------------------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= CLEAR;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_1640us) begin\t\t\t\t\t\t\/\/WAIT at least 1640us (required for operation to process)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\t\t\t\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t7: begin \/\/---------Normal ENTRY, Cursor increments, Display is not shifted--------------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= ENTRY_N;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_42us) begin\t\t\t\t\t\t\t\/\/WAIT at least 42us (required for operation to process)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t8: begin \/\/-----------------DISPLAY, Display ON, Cursor ON, Blinking ON------------------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= DISP_ON;\/\/ALL_ON;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_42us) begin\t\t\t\t\t\t\t\/\/WAIT at least 42us (required for operation to process)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE+1;\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t9: begin \/\/-------------------DISPLAY CLEAR, clear the display screen--------------------\t\t\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= CLEAR;\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_1640us) begin\t\t\t\t\t\t\/\/WAIT at least 1640us (required for operation to process)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\t15;\t\t\t\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t10: begin\/\/----------------------------- WRITE DATA -------------------------------------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= DATA;\t\t\t\t\t\t\/\/WRITE THE CHARACTER\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(flag_250ns&amp;&amp; !flag_rst) begin\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\t15;\/\/STATE+1;\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \n\t\t\t\tend\t\n\t\t\t\telse begin \t\t\n\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\t\t\n\t\tend\t\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\t11: begin\/\/----------------------- WRITE INSTRUCTION ------------------------------------\n\t\t\tLCD_RS\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Indicate a write operation\t\n\t\t\tRDY\t\t\t\t\t&lt;= 1'b0;\t\t\t\t\t\t\/\/Indicate that the module is busy\n\t\t\tif(SUBSTATE==0)begin\t \t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus\n\t\t\t\tLCD_DB \t\t\t&lt;=\tLCD_DB;\t\t\t\t\t\/\/Maintain Previous Data on the Bus\n\t\t\t\tSTATE\t\t\t\t&lt;=\tSTATE;\t\t\t\t\n\t\t\t\tSUBSTATE\t\t\t&lt;=\t1;\n\t\t\tend\t\t\t\n\t\t\tif(SUBSTATE==1)begin\t\t\t\t\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b1;\t\t\t\t\t\t\/\/Enable Bus\t\t\n\t\t\t\tLCD_DB \t\t\t&lt;= DATA;\t\t\t\t\t\t\/\/Data Valid\n\t\t\t\tif(!flag_250ns) begin\t\t\t\t\t\t\/\/WAIT at least 250ns (required for LCD_E)\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\t\t\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE+1;\t\t\t\t\/\/Go to next SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\t\tif(SUBSTATE==2)begin\n\t\t\t\tLCD_E\t\t\t\t&lt;=\t1'b0;\t\t\t\t\t\t\/\/Disable Bus, Triggers LCD to read BUS\n\t\t\t\tLCD_DB \t\t\t&lt;= LCD_DB;\t\t\t\t\t\/\/Keep Data Valid\n\t\t\t\tif(!flag_42us) begin\t\t\t\t\t\t\t\/\/WAIT at least 49us (required for operation to process)\n\t\t\t\t\tSTATE\t\t\t&lt;=\tSTATE;\t\t\t\t\t\/\/Maintain current STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\tSUBSTATE;\t\t\t\t\/\/Maintain current SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b0; \t\t\t\t\t\/\/Start or Continue counting\t\t\t\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\t\telse begin \t\t\n\t\t\t\t\tSTATE\t\t\t&lt;=\t15;\/\/STATE+1;\t\t\t\/\/Go to next STATE\n\t\t\t\t\tSUBSTATE\t\t&lt;=\t0;\t\t\t\t\t\t\t\/\/Reset SUBSTATE\n\t\t\t\t\tflag_rst\t\t&lt;=\t1'b1; \t\t\t\t\t\/\/Stop counting\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t\/\/---------------------------------------------------------------------------------------\n\t\tdefault: begin\/\/----------This is the IDLE STATE, DO NOTHING UNTIL OPER is set-----------\n\t\t\tLCD_RS\t&lt;=\t\tLCD_RS;\t\t\t\t\t\t\t\t\/\/Indicate an instruction is to be sent soon\n\t\t\tLCD_RW\t&lt;= \t1'b0;\t\t\t\t\t\t\t\t\t\/\/Indicate a write operation\n\t\t\tLCD_DB \t&lt;= \tLCD_DB;\t\t\t\t\t\t\t\t\/\/Maintain Data Bus\n\t\t\tLCD_E\t\t&lt;=\t\t1'b0;\t\t\t\t\t\t\t\t\t\/\/Disable Bus\n\t\t\tRDY\t\t&lt;=\t\t1'b1;\t\n\t\t\tRST_output &lt;=1'b1;\t\t\t\/\/Indicate that the system is ready to taking in data\n\t\t\tif(ENB==1)begin\n\t\t\t\tcase(OPER)\n\t\t\t\t\t0:STATE&lt;=STATE; \t\/\/IDLE\n\t\t\t\t\t1:STATE&lt;=10;\t\t\/\/WRITE CHARACTER\n\t\t\t\t\t2:STATE&lt;=11;\t\t\/\/WRITE INSTRUCTION (assumes 49us or less time to process instr)\n\t\t\t\t\t3:STATE&lt;=0;\t\t\t\/\/RESET\n\t\t\t\tendcase\n\t\t\tend\n\n\t\tend\n\tendcase\nend\nendmodule<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>El planteamiento de esta entrada es si podemos hacer una verificaci\u00f3n f\u00edsica del RISC-V, en la placa DE2-115 mediante el LCD. La controladora verilog de LCD proviene de la siguiente direcci\u00f3n y autor\u00eda: https:\/\/gist.github.com\/windhooked\/40f6c9a6d35062a5d24503d2bcb07ddd La adaptaci\u00f3n que he realizado ha consistido fundamentalmente en generar una salida adicional que resetee el micro RISC-V mientras el LCD arranca, de forma que cuando est\u00e9 el LCD inicializado, liberemos el micro RISC-V y pueda empezar a ejecutar sus instrucciones. Esa salida adicional se denomina RST_output.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,5,29],"tags":[43,44],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-risc-v","category-verificacion","category-verificacion-fisica","tag-lcd","tag-risc-v"],"featured_image_src":null,"author_info":{"display_name":"ralfgad","author_link":"https:\/\/dsd.webs.upv.es\/?author=2"},"_links":{"self":[{"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=726"}],"version-history":[{"count":6,"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions"}],"predecessor-version":[{"id":1046,"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions\/1046"}],"wp:attachment":[{"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dsd.webs.upv.es\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}