在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<abbr id="27omo"></abbr>

<menu id="27omo"><dl id="27omo"></dl></menu>
    • <label id="27omo"><tt id="27omo"></tt></label>

      新聞中心

      文本LCD模塊的控制FPGA

      作者: 時(shí)間:2023-12-22 來(lái)源:電子森林 收藏

      文本便宜且易于使用微控制器或進(jìn)行接口。

      本文引用地址:http://www.biyoush.com/article/202312/454184.htm

      這是一個(gè)1行x 16個(gè)字符的模塊:

      要控制,您需要11個(gè)IO引腳來(lái)驅(qū)動(dòng)8位數(shù)據(jù)總線和3個(gè)控制信號(hào)。3個(gè)控制信號(hào)是:

      • E:?jiǎn)⒂没颉?LCD選擇”。高活躍。
      • 讀/寫(xiě):讀/寫(xiě)。0寫(xiě)入,1讀取。
      • RS:寄存器選擇,0表示命令字節(jié),1表示數(shù)據(jù)字節(jié)。

      大多數(shù)都基于HD44780芯片或是兼容的。查閱Wikipedia以獲取更多信息。

      7位設(shè)計(jì)

      讓我們用板驅(qū)動(dòng)LCD模塊。
      這是我們?cè)O(shè)計(jì)的框圖:

      Pluto從PC串行端口接收數(shù)據(jù),對(duì)其進(jìn)行反序列化,然后將其發(fā)送到LCD模塊。解串器與串行接口項(xiàng)目中的模塊相同,因此此處僅對(duì)其進(jìn)行實(shí)例化。

      module LCDmodule(clk, RxD, LCD_RS, LCD_RW, LCD_E, LCD_DataBus);
      input clk, RxD;
      output LCD_RS, LCD_RW, LCD_E;
      output [7:0] LCD_DataBus; 
      wire RxD_data_ready;
      wire [7:0] RxD_data;
      async_receiver deserializer(.clk(clk), .RxD(RxD), .RxD_data_ready(RxD_data_ready), .RxD_data(RxD_data));

      每當(dāng)串行端口提供一個(gè)字節(jié)時(shí),“ RxDdataready”將在一個(gè)時(shí)鐘周期內(nèi)處于活動(dòng)狀態(tài)。
      PC通過(guò)串口以8位模式向我們發(fā)送數(shù)據(jù)。理想情況下,我們需要從PC接收9位,以便我們可以驅(qū)動(dòng)8位數(shù)據(jù)總線和LCD模塊的“ RS”線?,F(xiàn)在,讓我們使用接收到的數(shù)據(jù)的MSB(第7位)來(lái)驅(qū)動(dòng)“ RS”,并將僅7位發(fā)送到數(shù)據(jù)總線。

      assign LCD_RS = RxD_data[7];
      assign LCD_DataBus = {1'b0, RxD_data[6:0]};   
      // sends only 7 bits to the module, padded with a '0' in front to make 8 bits 
      assign LCD_RW = 0;

      我們從不讀取LCD模塊,所以R / W線是接地的。

      最后一個(gè)麻煩是“ E”信號(hào)需要長(zhǎng)時(shí)間激活,即220ns。從的角度來(lái)看,這很長(zhǎng),因?yàn)槲沂褂玫氖?5MHz時(shí)鐘(周期為40ns)。因此,“ E”至少需要驅(qū)動(dòng)5.5個(gè)時(shí)鐘。在這里,我們使用一個(gè)計(jì)數(shù)器對(duì)時(shí)鐘進(jìn)行計(jì)數(shù),將其驅(qū)動(dòng)7個(gè)時(shí)鐘。

      reg [2:0] count;
      always @(posedge clk) if(RxD_data_ready | (count!=0)) count <= count + 1;

      “ E”信號(hào)是通過(guò)寄存器創(chuàng)建的,因此可以保證無(wú)干擾。

      reg LCD_E;
      always @(posedge clk) LCD_E <= (count!=0);

      波形如下所示:

      HDL設(shè)計(jì)在這里。

      軟件方面

      我們對(duì)LCD進(jìn)行初始化并發(fā)送一些要顯示的數(shù)據(jù)。

      以下是初始化LCD模塊并顯示“ hello”的C代碼。

      void main(){
        OpenComm();   // initialize the LCD module
        WriteCommByte(0x38);   // "Function Set" in 8 bits mode
        WriteCommByte(0x0F);   // "Display ON" with cursors ON
        WriteCommByte(0x01);   // "Clear Display", can take up to 1.64ms, so the delay
        Sleep(2);   // display "hello"
        WriteCommByte('h' + 0x80);
        WriteCommByte('e' + 0x80);
        WriteCommByte('l' + 0x80);
        WriteCommByte('l' + 0x80);
        WriteCommByte('o' + 0x80); 
        CloseComm();
        }

      完整的代碼在這里。

      要獲取有關(guān)HD44780指令集的更多信息,請(qǐng)?jiān)诖颂帣z查。

      8位設(shè)計(jì)

      主要缺點(diǎn)是較早的設(shè)計(jì)是我們僅向LCD數(shù)據(jù)總線發(fā)送7位。這是一個(gè)問(wèn)題,因?yàn)闊o(wú)法再使用LCD模塊的設(shè)置DD RAM地址命令。

      一種簡(jiǎn)單的解決方法是使用轉(zhuǎn)義符。我們選擇了字符0x00。

      新協(xié)議如下:

      • 要發(fā)送命令字節(jié),請(qǐng)?jiān)谄淝懊婕由?x00。
      • 要發(fā)送數(shù)據(jù)字節(jié),只需發(fā)送它,不需要前綴。

      新的C代碼是:

      void main(){
        OpenComm();   // initialize the LCD module
        WriteCommByte(0x00);  WriteCommByte(0x38);   // "Function Set" in 8 bits mode
        WriteCommByte(0x00);  WriteCommByte(0x0F);   // "Display ON" with cursors ON
        WriteCommByte(0x00);  WriteCommByte(0x01);   // "Clear Display", can take up to 1.64ms, so the delay
        Sleep(2); 
        WriteCommByte('h');
        WriteCommByte('e');
        WriteCommByte('l');
        WriteCommByte('l');
        WriteCommByte('o'); 
        WriteCommByte(0x00);  WriteCommByte(0xC0);   // go on second half of LCD
        WriteCommByte('e');
        WriteCommByte('v');
        WriteCommByte('e');
        WriteCommByte('r');
        WriteCommByte('y');
        WriteCommByte('o');
        WriteCommByte('n');
        WriteCommByte('e'); 
        CloseComm();
        }

      新的HDL代碼如下所示:

      module LCDmodule(clk, RxD, LCD_RS, LCD_RW, LCD_E, LCD_DataBus);
      input clk, RxD;output LCD_RS, LCD_RW, LCD_E;
      output [7:0] LCD_DataBus; 
      wire RxD_data_ready;
      wire [7:0] RxD_data;
      async_receiver deserialer(.clk(clk), .RxD(RxD), .RxD_data_ready(RxD_data_ready), .RxD_data(RxD_data)); 
      assign LCD_RW = 0;assign LCD_DataBus = RxD_data; 
      wire Received_Escape = RxD_data_ready & (RxD_data==0);
      wire Received_Data = RxD_data_ready & (RxD_data!=0); reg [2:0] count;
      always @(posedge clk) if(Received_Data | (count!=0)) count <= count + 1; 
      // activate LCD_E for 6 clocks, so at 25MHz, that's 6x40ns=240ns
      reg LCD_E;
      always @(posedge clk)if(LCD_E==0)
        LCD_E <= Received_Data;
        else
        LCD_E <= (count!=6); 
        reg LCD_instruction;
        always @(posedge clk)if(LCD_instruction==0)
        LCD_instruction <= Received_Escape;
        else
        LCD_instruction <= (count!=7); 
        assign LCD_RS = ~LCD_instruction; 
        endmodule

      HD44780規(guī)范顯示,“ E”變低后,“ RS”必須在10ns內(nèi)有效。因此,您會(huì)注意到這里“ E”僅被驅(qū)動(dòng)6個(gè)時(shí)鐘,并且“ LCDinstruction”標(biāo)志僅在時(shí)鐘7之后被復(fù)位,以提供25ns的空間。

      That's all folks!輪到您嘗試了。



      關(guān)鍵詞: FPGA LCD模塊

      評(píng)論


      相關(guān)推薦

      技術(shù)專區(qū)

      關(guān)閉