<commit_before>/**
 * ** project Arduino EEPROM programmer **
 * 
 * This sketch can be used to read and write data to a
 * AT28C64 or AT28C256 parallel EEPROM
 *
 * $Author: mario $
 * $Date: 2013/05/05 11:01:54 $
 * $Revision: 1.2 $
 *
 * This software is freeware and can be modified, reused or thrown away without any restrictions.
 *
 * Use this code at your own risk. I'm not responsible for any bad effect or damages caused by this software!!!
 *
 **/

#define VERSIONSTRING "MEEPROMMER $Revision: 1.2 $ $Date: 2013/05/05 11:01:54 $, CMD:B,b,w,W,V"

// shiftOut part
#define DS      A0
#define LATCH   A1
#define CLOCK   A2

#define PORTC_DS      0
#define PORTC_LATCH   1
#define PORTC_CLOCK   2


// eeprom stuff
// define the IO lines for the data - bus
#define D0 2
#define D1 3
#define D2 4
#define D3 5
#define D4 6
#define D5 7
#define D6 8
#define D7 9

// define the IO lines for the eeprom control
#define CE A3
#define OE A4
#define WE A5
#define PORTC_CE   3
#define PORTC_OE   4
#define PORTC_WE   5

//a buffer for bytes to burn
#define BUFFERSIZE 1024 
byte buffer[BUFFERSIZE];
//command buffer for parsing commands
#define COMMANDSIZE 32
char cmdbuf[COMMANDSIZE];

unsigned int startAddress,endAddress;
unsigned int lineLength,dataLength;

//define COMMANDS
#define NOCOMMAND    0
#define VERSION      1

#define READ_HEX    10
#define READ_BIN    11
#define READ_ITL    12

#define WRITE_HEX   20
#define WRITE_BIN   21
#define WRITE_ITL   22


/*****************************************************************
 *
 *  CONTROL and DATA functions
 *
 ****************************************************************/

// switch IO lines of databus to INPUT state
void	    data_bus_input() {
  pinMode(D0, INPUT);
  pinMode(D1, INPUT);
  pinMode(D2, INPUT);
  pinMode(D3, INPUT);
  pinMode(D4, INPUT);
  pinMode(D5, INPUT);
  pinMode(D6, INPUT);
  pinMode(D7, INPUT);
}

//switch IO lines of databus to OUTPUT state
void data_bus_output() {
  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
}

//set databus to input and read a complete byte from the bus
//be sure to set data_bus to input before
byte read_data_bus()
{
  return ((digitalRead(D7) << 7) +
    (digitalRead(D6) << 6) +
    (digitalRead(D5) << 5) +
    (digitalRead(D4) << 4) +
    (digitalRead(D3) << 3) +
    (digitalRead(D2) << 2) +
    (digitalRead(D1) << 1) +
    digitalRead(D0));

}


//write a byte to the data bus
//be sure to set data_bus to output before
void write_data_bus(byte data)
{
  //2 bits belong to PORTB and have to be set separtely 
  digitalWrite(D6, (data >> 6) & 0x01);
  digitalWrite(D7, (data >> 7) & 0x01);
  //bit 0 to 6 belong to bit 2 to 8 of PORTD
  PORTD = PIND | ( data << 2 );
}

//shift out the given address to the 74hc595 registers
void set_address_bus(unsigned int address)
{

  //get high - byte of 16 bit address
  byte hi = address >> 8;
  //get low - byte of 16 bit address
  byte low = address & 0xff;

  //disable latch line
  bitClear(PORTC,PORTC_LATCH);

  //shift out highbyte
  fastShiftOut(low);
  //shift out lowbyte
  fastShiftOut(hi);

  //enable latch and set address
  bitSet(PORTC,PORTC_LATCH);

}

//faster shiftOut function then normal IDE function (about 4 times)
void fastShiftOut(byte data) {
  //clear data pin<commit_msg>Shift high byte of address bus first.<commit_after>/**
 * ** project Arduino EEPROM programmer **
 * 
 * This sketch can be used to read and write data to a
 * AT28C64 or AT28C256 parallel EEPROM
 *
 * $Author: mario $
 * $Date: 2013/05/05 11:01:54 $
 * $Revision: 1.2 $
 *
 * This software is freeware and can be modified, reused or thrown away without any restrictions.
 *
 * Use this code at your own risk. I'm not responsible for any bad effect or damages caused by this software!!!
 *
 **/

#define VERSIONSTRING "MEEPROMMER $Revision: 1.2 $ $Date: 2013/05/05 11:01:54 $, CMD:B,b,w,W,V"

// shiftOut part
#define DS      A0
#define LATCH   A1
#define CLOCK   A2

#define PORTC_DS      0
#define PORTC_LATCH   1
#define PORTC_CLOCK   2


// eeprom stuff
// define the IO lines for the data - bus
#define D0 2
#define D1 3
#define D2 4
#define D3 5
#define D4 6
#define D5 7
#define D6 8
#define D7 9

// define the IO lines for the eeprom control
#define CE A3
#define OE A4
#define WE A5
#define PORTC_CE   3
#define PORTC_OE   4
#define PORTC_WE   5

//a buffer for bytes to burn
#define BUFFERSIZE 1024 
byte buffer[BUFFERSIZE];
//command buffer for parsing commands
#define COMMANDSIZE 32
char cmdbuf[COMMANDSIZE];

unsigned int startAddress,endAddress;
unsigned int lineLength,dataLength;

//define COMMANDS
#define NOCOMMAND    0
#define VERSION      1

#define READ_HEX    10
#define READ_BIN    11
#define READ_ITL    12

#define WRITE_HEX   20
#define WRITE_BIN   21
#define WRITE_ITL   22


/*****************************************************************
 *
 *  CONTROL and DATA functions
 *
 ****************************************************************/

// switch IO lines of databus to INPUT state
void	    data_bus_input() {
  pinMode(D0, INPUT);
  pinMode(D1, INPUT);
  pinMode(D2, INPUT);
  pinMode(D3, INPUT);
  pinMode(D4, INPUT);
  pinMode(D5, INPUT);
  pinMode(D6, INPUT);
  pinMode(D7, INPUT);
}

//switch IO lines of databus to OUTPUT state
void data_bus_output() {
  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
}

//set databus to input and read a complete byte from the bus
//be sure to set data_bus to input before
byte read_data_bus()
{
  return ((digitalRead(D7) << 7) +
    (digitalRead(D6) << 6) +
    (digitalRead(D5) << 5) +
    (digitalRead(D4) << 4) +
    (digitalRead(D3) << 3) +
    (digitalRead(D2) << 2) +
    (digitalRead(D1) << 1) +
    digitalRead(D0));

}


//write a byte to the data bus
//be sure to set data_bus to output before
void write_data_bus(byte data)
{
  //2 bits belong to PORTB and have to be set separtely 
  digitalWrite(D6, (data >> 6) & 0x01);
  digitalWrite(D7, (data >> 7) & 0x01);
  //bit 0 to 6 belong to bit 2 to 8 of PORTD
  PORTD = PIND | ( data << 2 );
}

//shift out the given address to the 74hc595 registers
void set_address_bus(unsigned int address)
{

  //get high - byte of 16 bit address
  byte hi = address >> 8;
  //get low - byte of 16 bit address
  byte low = address & 0xff;

  //disable latch line
  bitClear(PORTC,PORTC_LATCH);

  //shift out highbyte
  fastShiftOut(hi);
  //shift out lowbyte
  fastShiftOut(low);

  //enable latch and set address
  bitSet(PORTC,PORTC_LATCH);

}

//faster shiftOut function then normal IDE function (about 4 times)
void fastShiftOut(byte data) {
  //clear data pin
{'fraction_non_alphanumeric': 0.14091308165057068, 'fraction_numerical': 0.04331284752707053, 'mean_word_length': 3.5145310435931307, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '364633', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2418, 'n_words': 849}