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

📄 onewirespi.java

📁 Is a Application Demo (an example) of how to use the package LCD in order to make an application sta
💻 JAVA
字号:
package etaai.lcd.onewire.spi;import etaai.containers.DS2406;import com.dalsemi.onewire.adapter.*;import com.dalsemi.onewire.*;import etaai.lcd.onewire.spi.*;import com.dalsemi.onewire.container.OneWireContainer12;/** * Title:        Serial LCD * Description:  Comnada display lcd pe seriala * Copyright:    Copyright (c) 2001 * Company:      ETA AI * @author Mircea Pop * @version 1.0 */public class OneWireSPI{  /**The two DS2406 senzors that comunicate with Cristalfontz LCD*/  private DS2406 SPI_Data,SPI_CP;  /**   * The Class SPI implements  SPI comunication using 2 DS2406 chips from Dalas Semiconductors   * @param DSPortAdapter 1-wire port adapter   * @param String adresa1 First Ds2406 ship address   *        PIOA - data line (SPI_DATA)   *        PIOB - closk line (SPI_CLK)   * @param String adresa2 Second DS2406 chip address   *   *        PIOA - CHIP_SELECT   *        PIOB - /BUSY   * @throws Exception Whne cannot access either DS2406 chips   */  public OneWireSPI(DSPortAdapter adapter ,String adresa1,String adresa2) throws Exception  {    SPI_Data = new DS2406(adapter,adresa1,"Port Date",0);    SPI_CP   = new DS2406(adapter,adresa2,"Selectare Chip_BUSY",0);    //Initialization SPI_CLK and SPI_CS    SPI_Data.setStareCanal(1,false);//clock la 5V    SPI_CP.setStareCanal(0,false);//Chip_Select 5V  }  /**   * Data send method   * @param int Data that will be sent to lcd   *   * @throws SPIException When data error transmision occurs   */  public void sendSPIData(int data) throws OneWireSPIException  {      byte[] aux = new byte[1];      aux[0] = (byte)data;      sendSPIData(aux);  }  /**   * Data send method   * @param String Data that will be sent to lcd   *   * @throws SPIException When data error transmision occurs   */  public void sendSPIData(String data) throws OneWireSPIException  {    sendSPIData(data.getBytes());  }  /**   * Data send method   * @param byte[] data Data that will be sent to lcd   *   * @throws SPIException When data error transmision occurs   */  public void sendSPIData(byte[] data) throws OneWireSPIException  {    if(SPI_CP.getState() || SPI_Data.getState()) throw new OneWireSPIException("Dispozitiv comunicare este stricat!");    //calculate bits that will be sent    data = CalculVectorDate(data);    SPI_Data.setStareCanal(1,false);//sets clock 5V    SPI_CP.setStareCanal(0,true);//sels lcd_chip_select 0V    try{Thread.sleep(50);}catch(InterruptedException _){}    data = SPI_Data.channelAccess(data,false,false,OneWireContainer12.CRC_DISABLE,OneWireContainer12.CHANNEL_BOTH,false,false);    try{Thread.sleep(20);}catch(InterruptedException _){}    //Dezactivare SPI_CS & clock    SPI_Data.setStareCanal(1,false);//Sets clock output to 5V    SPI_CP.setStareCanal(0,false);//Sets SPI_CS to 5V  }  /**   * Calculates bit sequence that will be send to the lcd display   */  private byte[] CalculVectorDate(byte[] data)  {    int lungime = data.length * 4;    int lungime_data = data.length;    byte [] aux = new byte[lungime];    int k = 0;    int x,y,z;    for(int i=0;i<lungime_data;i++)    {      y = data[i];      x = y;      y = y >> 6;      z = 0x22 | (0x55 & ((y & 1) << 6) | ((y & 1) << 4) | ((y & 2) << 1) | ((y & 2) >> 1));      aux[k++] = (byte)z;      y = x >> 4;      z = 0x22 | (0x55 & ((y & 1) << 6) | ((y & 1) << 4) | ((y & 2) << 1) | ((y & 2) >> 1));      aux[k++] = (byte)z;      y = x >> 2;      z = 0x22 | (0x55 & ((y & 1) << 6) | ((y & 1) << 4) | ((y & 2) << 1) | ((y & 2) >> 1));      aux[k++] = (byte)z;      y = x;      z = 0x22 | (0x55 & ((y & 1) << 6) | ((y & 1) << 4) | ((y & 2) << 1) | ((y & 2) >> 1));      aux[k++] = (byte)z;    }    return aux;  }}

⌨️ 快捷键说明

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