⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.java

📁 this software is making a conversion from TEXT to LCD / SPI. Is used to show a text on LCD Display.
💻 JAVA
字号:
package etaai.lcd;import java.io.*;import etaai.lcd.LCDException;import etaai.lcd.*;/** * Title:        Serial LCD * Description:  Comnada display lcd pe seriala * Copyright:    Copyright (c) 2001 * Company:      ETA AI * @author Mircea Pop * @version 1.0 */public class LCD{    /*Numarul de linii al LCD*/    private int linii = 2;    /*Numarul de coloane*/    private int coloane = 16;    /*Configuratie LCD*/    private boolean Scroll = true;    private boolean Wrap = true;    /*Daca LCD e comandat pe seriala - true; SPI - false*/    private boolean SPI_Serial = true;    private LCDPort portLCD = null;    /**     * The Class implements Cristalfontz lcd display commands     *     * @param LCDport portLCD Comunication Interface (serial or SPI)     * @param int linii LCD line number     * @param int coloane LCD column number     *     * @throws LCDException,Exception When initialization error occurs     */    public LCD(LCDPort portLCD, int linii, int coloane) throws LCDException,Exception    {      this.linii = linii;      this.coloane = coloane;      this.portLCD = portLCD;    }    /**     * Stergere afisajul LCD si pozitioneaza cursorul la (0,0)     * @throws LCDException Daca nu s-a putut efectua comanda     */    public void clearScreen() throws LCDException    {      //Control L : Clear Display :\012      portLCD.sendLCDData(12);    }    /**     * Setare caractere spaciale     * @param byte caracter Locatia de memorie unde va fi salvat(0:7)     * @param byte[] confBiti Configuratia de biti a caracterului     *     * @throws LCDException Daca nu s-a putut seta caracterul specia     */    public void setSpecialChar(byte caracter, byte[] confBiti) throws IOException,LCDException    {      if((caracter > 7) || (caracter < 0) || (confBiti.length != 8)) throw new LCDException("Date setare caracter special invalide!");      byte [] aux = new byte[10];      aux[0] = 25;//Control Y      aux[1] = caracter;      for(int i=0;i<8;i++)        aux[i+2] = confBiti[i];      delay(5000);      portLCD.sendLCDData(aux);      delay(10000);    }    /**     * Setare scroll     * @param boolean value  true  - scroll on;     *                       false - scroll off     * @throws LCDException Daca nu s-a putut seta scrol    */    public void setScroll(boolean value) throws LCDException    {      if(value) portLCD.sendLCDData(19);//Contro S : Scroll ON      else portLCD.sendLCDData(20);//Contro T : Scroll OFF      Scroll = value;    }    /**     * Returneaza starea scroll actuala a scroll.Default scroll on     * @return boolean true - scroll on     *                 false - scroll off     */    public boolean getScroll()    {      return Scroll;    }    /**     * Setare wrap .     * @param boolean value     *            true - wrap on;     *            false : wrap off     * @throws LCDException Daca nu s-a putut seta caracterul specia    */    public void setWrap(boolean value) throws LCDException    {      if(value) portLCD.sendLCDData(23);//Control W: Wrap ON      else portLCD.sendLCDData(24); //Control X : Wrap OFF      Wrap = value;    }    /**     * Returneaza starea wrap actuala a scroll.Default wrap on     * @return boolean true  - wrap on     *                 false - wrap off     */    public boolean getWrap()    {      return Wrap;    }    /**     * Ascunde cursorul     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void hideCursor()throws LCDException    {      portLCD.sendLCDData(4);//Control D: ascundere cursor    }    /**     * Afiseaza cursorul     * @param int type     *            value  1: underLine cursor     *            value  2: block cursor     *            value  3: inverting cursor     *     * @throws LCDException Daca nu s-a putut trimite comanda     * @throws IOException  Eroare comunicare     */    public void showCursor(int type) throws IOException,LCDException    {      switch(type)      {        case 1 : portLCD.sendLCDData(5);//Control E: underline cursor                 break;        case 2 : portLCD.sendLCDData(6);//Control F: block cursor                 break;        case 3 : portLCD.sendLCDData(7);//Control G: inverting cursor                 break;        default : throw new LCDException("Invalid cursor type.(type :1/2/3)");      }    }    /**     * Ascunde afisajul     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void hideDisplay() throws LCDException    {      portLCD.sendLCDData(2);//Control B: hide display    }    /**     * Activare afisajul     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void showDiplay() throws LCDException    {      portLCD.sendLCDData(3);//Control C: restore display    }    /**     * Duce cursorul in prima pozitie a afisajului (0,0)     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void setCursorPosition() throws LCDException    {        portLCD.sendLCDData(1);//Control A : cursor home    }    /**     * Duce cursorul in la pozitia indicata     *     * @param int linie Linia     * @param int coloana Coloana     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void setCursorPosition(int linie, int coloana) throws LCDException    {      if((linie > linii)|| (linie < 0)) throw new LCDException("Linie invalida.");      if((coloana > coloane) || (coloana < 0)) throw new LCDException("Coloana invalida.");      byte[] aux = new byte[3];      aux[0] = 17;//Control Q: set cursor position      aux[1] = (byte)coloana;      aux[2] = (byte)linie;      portLCD.sendLCDData(aux);    }    /**     * Resetare hard afisaj     */    public void resetDisplay()    {      portLCD.resetDisplay();    }    /**     * Resetare soft afisaj     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void resetDisplaySoft() throws LCDException    {      portLCD.sendLCDData(26);      try{Thread.currentThread().sleep(10000);}catch(InterruptedException _){}    }    /**     * Sterge caracterul de la pozitia curenta a cursorului si muta cursorul     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void backSpace() throws LCDException    {      portLCD.sendLCDData(8);//Control H L sterge caracterul de la pozitia curenta a cursorului si muta cursorul    }    /**     * Sterge caracterul de la pozitia curenta a cursorului fara a muta cursorul     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void delCurrentChar() throws LCDException    {      portLCD.sendLCDData(11);//Control K L sterge caracterul de la pozitia curenta a cursorului fara a muta cursorul    }    /**     *     * Sterge caracterul de la pozitia curenta a cursorului fara a muta cursorul     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void delChar(int linie, int coloana) throws LCDException    {      setCursorPosition(linie, coloana);      portLCD.sendLCDData(11);//Control K L sterge caracterul de la pozitia curenta a cursorului fara a muta cursorul    }    /**     * Afisare ecran INFO     */    public void showInfoScreen() throws LCDException    {      portLCD.sendLCDData(31);//    }    /**     * Setare intensitate led luminare afisaj     * Intensitea intre [0;100]     * @param int brightness     *    value 0: OFF     *    value 100: ON     *     * @throws LCDException Daca nu s-a putut trimite comanda    */    public void setBackLite(int brightness) throws LCDException    {      //0 - OFF      //100 - ON      if(brightness < 0) brightness = 0;      if(brightness > 100) brightness = 100;      byte[] aux = new byte[2];      aux[0] = 14;      aux[1] = (byte) brightness;      portLCD.sendLCDData(aux);    }    /**     * Setare intensitate contrast     * Intensitate intre[0;100]     * @param int level Value[0,100]     *     * @throws LCDException Daca nu s-a putut trimite comanda    */    public void setContrast(int level) throws LCDException    {      if(level < 0) level = 0;      if(level > 100) level = 100;      byte[] aux = new byte[2];      aux[0] = 15;//Control 0      aux[1] = (byte) level;      portLCD.sendLCDData(aux);    }    /**     * Sterge o linie a afisajului si pozitioneaza cursorul la inceputul ei     * @param int linie Linia ce va fi stearsa     * @throws LCDException Daca nu s-a putut trimite comanda sau linia nu carespunde     */    public void delLine(int linie) throws LCDException    {      if((linie < 0) || (linie > linii)) throw new LCDException("Linie invalida.");      StringBuffer buf = new StringBuffer();      for(int i=0;i<coloane;i++)        buf.append(" ");      setCursorPosition(linie, 0);      portLCD.sendLCDData(buf.toString());      setCursorPosition(linie, 0);    }    /**     * Afiseaza un mesaj pe display     *     * @param String mesaj Mesajul ce va fi afisat     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void println(String mesaj) throws LCDException    {      portLCD.sendLCDData(mesaj);      delay(200);    }    /**     * Afiseaza un mesaj pe display     *     * @param int linie Linia pe care se va afisa meajul     * @param, int coloana Coloana pe care se va afisa mesajul     *     * @throws LCDException Daca nu s-a putut trimite comanda sau linia nu carespunde     */    public void println(String mesaj, int linie, int coloana) throws LCDException    {      setCursorPosition(linie,coloana);      portLCD.sendLCDData(mesaj);      delay(200);    }    /**     * Introduce o intarziere     *     * @param long time     */    private void delay(long time)    {      try{Thread.currentThread().sleep(time);}catch(InterruptedException _){}    }    /**     * Setare caractere defilare     *     * @param String caractere Caracterele ce vor defila     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void setScrollMarqueeChars(String caractere) throws LCDException    {      clearScrollMarqueeChars();      byte [] cars = caractere.getBytes();      if(cars.length > 20) throw new LCDException("SetScrolling Marquee - maxim 20 de caractere!");      byte[] aux = new byte[3];        for(int i=0;i<cars.length;i++)        {          aux[0] = (byte)21;//Control U          aux[1] = (byte) i;//index          aux[2] = cars[i];          portLCD.sendLCDData(aux);        }    }    private void clearScrollMarqueeChars() throws LCDException    {      char spatiu = ' ';      byte[]aux = new byte[3];      aux[0] = 21;      aux[2] = (String.valueOf(spatiu).getBytes())[0];      for(int i=0;i<20;i++)      {        aux[1] = (byte) i;        portLCD.sendLCDData(aux);      }    }    /**     * Activare defilare     *     * @param int linie Linia pe care vor defila caracterele     * @param int coloane Coloana pe care vor defila caracterele     * @param int update_Speed Viteza de defilare     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void enableScrollMarqueeChars(int linie, int scroll_step_size, int update_speed) throws LCDException    {      if((linie < 0)||(linie > linii)) throw new LCDException("Indexul liniei nu corespunde tipului afisajului!");      if((scroll_step_size < 1)||(scroll_step_size > 6)) throw new LCDException("Invalid scroll step size!");      if(update_speed < 5) update_speed = 5;      if(update_speed > 100) update_speed = 100;      byte[] aux = new byte[4];      aux[0] = (byte)22;//Control V      aux[1] = (byte)linie;      aux[2] = (byte) scroll_step_size;      aux[3] = (byte) update_speed;      portLCD.sendLCDData(aux);    }    /**     * Setare bara orizontala     *     * @param int graph_index     * @param int style Stilul barii     * @param int start_coloane Coloana de inceput     * @param int end_coloane Coloana de sfarsit     * @param int lungime     * @param int linie Linia pe care vor defila caracterele     *     * @throws LCDException Daca nu s-a putut trimite comanda     */    public void setHorizontalBarGraph(int graph_index,int style,int start_coloana,int end_coloana, int lungime, int linie) throws IOException,LCDException    {      if((start_coloana < 0)||(start_coloana > coloane)||(start_coloana > end_coloana)) throw new LCDException("Coloana start invalida!");      if((end_coloana < 0) || (end_coloana > coloane)) throw new LCDException("Coloana end invalida!");      if((linie < 0) || (linie > linii))throw new LCDException("Linie invalida!");      if(lungime > coloane*6) throw new LCDException("Lungime bara invalida");      byte[] aux = new byte[7];      aux[0] = 18;      aux[1] = (byte)graph_index;      aux[2] = (byte)style;      aux[3] = (byte)start_coloana;      aux[4] = (byte)end_coloana;      aux[5] = (byte)lungime;      aux[6] = (byte)linie;      portLCD.sendLCDData(aux);    }    /**     * Inchidere LCD     */    public void close()    {      portLCD.close();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -