/**
 * Read bytes from the EEPROM using sequential read.
 */
void
eeprom_read(unsigned short addr, unsigned char *buf, int size)
{
  unsigned int i;

  if(size <= 0) {
    return;
  }
  
  do {
    /* Wait if the writecycle has not finished. */
    start();
    /* 1010 control, 000 address, 0=write  --- but only inits address */
  } while(!write_bus(0xa0 | EEPROMADDRESS));
           

  /* Write address to bus, low byte first. */
  write_bus(addr >> 8);
  write_bus(addr & 0xff);
  start();
  /* 1010 control, 000 address, 1=read */
  write_bus(0xa1 | EEPROMADDRESS); 

  for(i = 0; i < (size - 1); ++i){
    buf[i] = read_bus(1);
  }
  buf[size - 1] = read_bus(0);
  stop();
}
示例#2
0
文件: UNIO.cpp 项目: martmaiste/UNIO
static volatile boolean rwbit(boolean w) {
  boolean a,b;
  set_bus(!w);
  delayMicroseconds(UNIO_QUARTER_BIT);
  a=read_bus();
  delayMicroseconds(UNIO_QUARTER_BIT);
  set_bus(w);
  delayMicroseconds(UNIO_QUARTER_BIT);
  b=read_bus();
  delayMicroseconds(UNIO_QUARTER_BIT);
  return b&&!a;
}