示例#1
1
// write either command or data, with automatic 4/8-bit selection
void PCFCrystal::send(uint8_t value, uint8_t mode) {
/*  
  // ORIGINAL CODE
  digitalWrite(_rs_pin, mode);

  // if there is a RW pin indicated, set it low to Write
  if (_rw_pin != -1) { 
    digitalWrite(_rw_pin, LOW);
  }
*/

  setBit(modeBuffer(), _rs_pin, mode);
  // if there is a RW pin indicated, set it low to Write
  if (_rw_pin) { 
    setBit(modeBuffer(), _rw_pin, LOW);
  }
  writePCF(modeAddress(), *modeBuffer());
//return;

  if (_displayfunction & LCD_8BITMODE) {
    write8bits(value); 
  } else {
    write4bits(value>>4);
    write4bits(value);
  }
}
示例#2
0
void PCFCrystal::pulseEnable(void) {
  // Set the value if it's in a separate PCF
  if (_addressextra)
    writePCF(_address, *_data);

/*
  // ORIGINAL CODE
  digitalWrite(_enable_pin, LOW);
  delayMicroseconds(1);    
  digitalWrite(_enable_pin, HIGH);
  delayMicroseconds(1);    // enable pulse must be >450ns
  digitalWrite(_enable_pin, LOW);
  delayMicroseconds(100);   // commands need > 37us to settle
*/
  uint8_t *buff = modeBuffer();
  uint8_t address = modeAddress();
  
  setBit(buff, _enable_pin, LOW);
  writePCF(address, *buff);
// ORIGINAL CODE. These 3 delays are omitted as the PCF writing takes longer
//  delayMicroseconds(1);
  
  setBit(buff, _enable_pin, HIGH);
  writePCF(address, *buff);
//  delayMicroseconds(1);    // enable pulse must be >450ns
  
  setBit(buff, _enable_pin, LOW);
  writePCF(address, *buff);
//  delayMicroseconds(100);   // commands need > 37us to settle
}
GS_CHANGE_MODE()
{
  mem_req_t memReq;
  memReq.rw = WRITE;
  memReq.size = WORD;
  memReq.addr = modeAddress(Input.pageId) 
  memReq.data = modeChange(memRep.data, Input.pageId)
  memRep = mem(memReq); 
  rank = Input.rankUpdate; 
  State = GS_WRITE_RANK; 
}
GS_CHANGE_MODE()
{
  mem_req_t memReq2;
  memReq2.rw = WRITE;
  memReq2.size = WORD;
  memReq2.addr = modeAddress(Input.pageId); 
  memReq2.data = modeWrite(memRep.data, Input.pageId);
  memRep = mem(memReq2); 
  //rank = Input.rankUpdate; 
  State = GS_WRITE_RANK; 
}
//Then see if page rank is initialized yet
//If not, zero it out. If yest, go to add. 
GS_READ_MODE()
{
  bit oldMode;
  mem_req_t memReq;
  memReq.rw = READ;
  memReq.size = WORD;
  memReq.addr = modeAddress(Input.pageId); 
  memRep = mem(memReq); 
  oldMode = modeRead(memRep.data);
  if (oldMode ^ mode) {
    State = GS_READ_RANK; 
  } else {
    State = GS_CHANGE_MODE; 
  }
}
//Then see if page rank is initialized yet
//If not, zero it out. If yes, go to add. 
GS_READ_MODE()
{
  bit oldMode;
  mem_req_t memReq1;
  memReq1.rw = READ;
  memReq1.size = WORD;
  memReq1.addr = modeAddress(Input.pageId); 
  memRep = mem(memReq1); 
  oldMode = modeRead(memRep.data, Input.pageId);
//  if (oldMode ^ mode) {
    State = GS_READ_RANK; 
//  } else {
//    State = GS_CHANGE_MODE; 
//  }
}
示例#7
0
void PCFCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
  if (lines > 1) {
    _displayfunction |= LCD_2LINE;
  }
  _numlines = lines;
  _currline = 0;

  // for some 1 line displays you can select a 10 pixel high font
  if ((dotsize != 0) && (lines == 1)) {
    _displayfunction |= LCD_5x10DOTS;
  }

  // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
  // according to datasheet, we need at least 40ms after power rises above 2.7V
  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
  delayMicroseconds(50000); 
  // Now we pull both RS and R/W low to begin commands
/*
  // ORIGINAL CODE
  digitalWrite(_rs_pin, LOW);
  digitalWrite(_enable_pin, LOW);
  if (_rw_pin != -1) { 
    digitalWrite(_rw_pin, LOW);
  }
*/

  uint8_t *buff = modeBuffer();
  setBit(buff, _rs_pin, LOW);
  setBit(buff, _enable_pin, LOW);
  if (_rw_pin)
    setBit(buff, _rw_pin, LOW);
  writePCF(modeAddress(), *buff);
  
  //put the LCD into 4 bit or 8 bit mode
  if (! (_displayfunction & LCD_8BITMODE)) {
    // this is according to the hitachi HD44780 datasheet
    // figure 24, pg 46

    // we start in 8bit mode, try to set 4 bit mode
    write4bits(0x03);
    delayMicroseconds(4500); // wait min 4.1ms

    // second try
    write4bits(0x03);
    delayMicroseconds(4500); // wait min 4.1ms
    
    // third go!
    write4bits(0x03); 
    delayMicroseconds(150);

    // finally, set to 8-bit interface
    write4bits(0x02); 
  } else {
    // this is according to the hitachi HD44780 datasheet
    // page 45 figure 23

    // Send function set command sequence
    command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(4500);  // wait more than 4.1ms

    // second try
    command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(150);

    // third go
    command(LCD_FUNCTIONSET | _displayfunction);
  }

  // finally, set # lines, font size, etc.
  command(LCD_FUNCTIONSET | _displayfunction);  

  // turn the display on with no cursor or blinking default
  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
  display();

  // clear it off
  clear();

  // Initialize to default text direction (for romance languages)
  _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
  // set the entry mode
  command(LCD_ENTRYMODESET | _displaymode);

}