amaruk
Published © GPL3+

CSS555 EEPROM Programmer: Celebrate 50 years of 555 IC's!

Create amazingly long delays using this super low power 555 timer.

AdvancedFull instructions provided2,470
CSS555 EEPROM Programmer: Celebrate 50 years of 555 IC's!

Things used in this project

Hardware components

Arduino Mega 2560
×1
CSS555/CSS555C timer
×1
2N2222 NPN transistor
×1
2N2907 PNP transistor
×1
510 ohm resistor
×2
5.1 Kohm resistor
×1
20 Kohm resistor
×1
5 mm LED: Green
5 mm LED: Green
×1
4x4 keypad
×1
OLED display SSD1306
×1
Small solderless breadboard (400 point)
×1

Story

Read more

Schematics

Schematic showing the CSS555 connnections

Code

Arduino code for the EEPROM programmer (V2.47)

C/C++
Code for Arduino Mega 2560
///////////////////////////////////////////////////////////////////////////////////////////////////////
// How to use: Follow the online menu. Special keys:
// A: Go to main menu
// B: Next category
// C: Increase value
// D: Decrease value
// 7: Decrease value with large jumps
// 9: Increase value with large jumps
// #: Burn EEPROM
// The delay time is shown as T: [HH:MM:SS]
// The system capacitance is set to 26pH (from measurements)
// External R/C values are picked from the E6 series
// The green LED is on when the 555 has power (Vcc pin)
///////////////////////////////////////////////////////////////////////////////////////////////////////
const double EEPROM_VERSION = 2.47;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Connections: (Mega:Keypad)
// Keypad pins are numbered 8,7...,1 from left to 
// right when the pad is with the text up.
// D2 : Pin 1
// D3 : Pin 2
// D4 : Pin 3
// D5 : Pin 4
// D6 : Pin 5
// D7 : Pin 6
// D8 : Pin 7
// D9 : Pin 8
// Connections: (Mega:OLED)
// 5V : VCC
// GND : GND
// D20 (SDA) : SDA
// D21 (SCL) : SCL
// Connections: (Mega:555)
// D22 : Pin 2 (Trigger)
// D23 : Pin 3 (Output)
// D24 : Pin 4 (Reset)
// Connections to NPN (2N2222) and PNP (2N2907) transistors
// D25 : To 510 ohm to base on NPN transistor
// NPN emitter to Gnd
// NPN collector to Pin 5 on 555 (ProgEn)
// D26 : To 510 ohm to base on PNP transistor
// PNP emitter to 5V
// PNP collector to pin 8 on 555 (Vcc)
// Pin 8 on 555 (Vcc) to 20kohm to pin 5 on 555 (ProgEn)
// Pin 8 on 555 (Vcc) to green LED to 5.1K resistor to ground
///////////////////////////////////////////////////////////////////////////////////////////////////////

#include <Adafruit_SSD1306.h> // OLED
#include <EEPROM.h> // Local variables
#include <Keypad.h> // Keypad

// OLED constants
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 11 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Interface command constants
const byte  CONFIG_BYTE_READ = B00010001; // Read mode byte 1
const byte  CAP_BYTE_READ = B00100001; // Read mode byte 2
const byte  CONFIG_BYTE_WRITE = B00010010; // Write mode byte 1
const byte  CAP_BYTE_WRITE = B00100010; // Write mode byte 2

// Keypad constants
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = 
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
// Keypad pin asignments
byte rowPins[ROWS] = {9, 8, 7, 6}; 
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

// 555 pin assignments
const int SCLK_PIN = 22; //  Trigger pin on 555 (2)
const int DATA_OUT_PIN = 23; // Output pin on 555 (3). Data out from 555
const int DATA_IN_PIN = 24; // Reset pin on 555 (4). Data into 555 (OLED reset = 11 here)
const int PROGEN_PIN = 25; // Control pin on 555 (5)
const int POWER_PIN = 26; // Controls power to the 555

// Timing constants
const int CLOCK_WIDTH_US = 1;
const int SAVE_DELAY_MS = 25;
const int REST_DELAY_MS = 2;
const int POWER_DELAY_MS = 1000;

// EEPROM constants
const byte FACTOR_BYTE_ADDR = 0;
const byte CAP_BYTE_ADDR = 1;
const byte CX_BYTE_ADDR = 2;
const byte RA_BYTE_ADDR = 3;
const byte RB_BYTE_ADDR = 4;

const double INTERNAL_CAP_PF = 26.0; // From experimental results

// State variables
byte menuID = 0; // 0: Main, 1: Read, 2: Set, 3: Set 555, 4: Set ext
byte categoryID = 5; // 0: Fact, 1: Stab, 2: Cap, 3: Volt, 4: Power, 5: Type
byte extCategoryID = 0; // 0: Cx, 1: Ra, 2: Rb
bool OKbuttonMode = false;
char customKey;

// EEPROM variables;
byte CxByte; // 0-19
byte RaByte; // 0-12
byte RbByte; // 0-12
byte factorByte; // default from local EEPROM
byte capacitorByte; // default from local EEPROM

///////////////////////////////////////////////////////////////////////////////////////////////////////
// Binary help functions
///////////////////////////////////////////////////////////////////////////////////////////////////////
void toggleBit(byte& dataByte, const int& n)
{
  if (bitRead(dataByte,n))
  {
    storeBit(dataByte,n,0);
  }
  else
  {
    storeBit(dataByte,n,1);
  }
}

void storeBit(byte& dataByte, const int& n, const bool& dataBit)
{
  if(dataBit)
  {
    bitSet(dataByte,n);
  }
  else
  {
    bitClear(dataByte,n);
  }
}

void formatByteAsBits(char bArray[10], const byte& b)
{
  for (int i=0;i<8;i++)
  {
    if (i<4) // first four bits 0..3
    {
      if (bitRead(b,7-i))
      {
        bArray[i] = '1';
      }
      else
      {
        bArray[i] = '0';
      }
    }
    else
    {
      if (i>=4) // last four bits 4..7
      {
        if (i==4)
        {
          bArray[i] = '-'; // separation between first/last four bits
        }
        if (bitRead(b,7-i))
        {
          bArray[i+1] = '1';
        }
        else
        {
          bArray[i+1] = '0';
        }  
      }
    }
  }
  bArray[9] = '\0'; // end character 
}
///////////////////////////////////////////////////////////////////////////////////////////////////////


void readLastValues() // From local EEPROM
{
  factorByte = EEPROM.read(FACTOR_BYTE_ADDR);
   if (factorByte == 255) // Invalid value (first time use). Set to 0 instead
   {
    factorByte = 0;
   }
  capacitorByte = EEPROM.read(CAP_BYTE_ADDR);
  CxByte =  EEPROM.read(CX_BYTE_ADDR);
  if (CxByte>19) // Invalid value (first time use). Set to 0 instead
  {
    CxByte = 0;
  }
  RaByte =  EEPROM.read(RA_BYTE_ADDR);
  if (RaByte>12) // Invalid value (first time use). Set to 0 instead
  {
    RaByte = 0;
  }
  RbByte =  EEPROM.read(RB_BYTE_ADDR);
  if (RbByte>12) // Invalid value (first time use). Set to 0 instead
  {
    RbByte = 0;
  }
}

void saveLastValues() // To local EEPROM
{
    // Only write if different
    if (EEPROM.read(FACTOR_BYTE_ADDR)!=factorByte)
    {
       EEPROM.write(FACTOR_BYTE_ADDR,factorByte); 
    }
    if (EEPROM.read(CAP_BYTE_ADDR)!=capacitorByte)
    {
       EEPROM.write(CAP_BYTE_ADDR,capacitorByte);
    }  
    if (EEPROM.read(CX_BYTE_ADDR)!=CxByte)
    {
       EEPROM.write(CX_BYTE_ADDR,CxByte);
    }  
    if (EEPROM.read(RA_BYTE_ADDR)!=RaByte)
    {
       EEPROM.write(RA_BYTE_ADDR,RaByte);
    }
    if (EEPROM.read(RB_BYTE_ADDR)!=RbByte)
    {
       EEPROM.write(RB_BYTE_ADDR,RbByte);
    }  
}


double calcResistance_E6_Kohm(const byte& rID) // 0...12
{ 
  const int resistorArray[13] = {100,150,220,330,470,680,1000,1500,2200,3300,4700,6800,10000};
  if (rID>12)
  {
    return 100;
  }
 return resistorArray[rID];
}

double calcCapacitance_E6_pF(const byte& cID) // 0...19
{
  const int capacitorArray[20] = {0,10,15,22,33,47,68,100,150,220,330,470,680,1000,1500,2200,3300,4700,6800,10000};
  if (cID>19)
  {
    return 0;
  }
 return capacitorArray[cID];
}

bool capacitorMode(const byte& dataByte)
{
  return bitRead(dataByte,7);
}

bool lowVoltageMode(const byte& dataByte)
{
  return bitRead(dataByte,5);
}

bool lowPowerMode(const byte& dataByte)
{
  return bitRead(dataByte,4);
}

bool monostableMode(const byte& dataByte)
{
  return bitRead(dataByte,3);
}

void changeFactorBits(byte& dataByte, const bool& up)
{
  int lastThree = dataByte % 8; // 0 - 7
  if (up)
  {
    lastThree = (lastThree + 1) % 8;
    if (lastThree == 7) // Don't allow setting it to 7
    {
        lastThree = 0; // skip up to 0
    }
  }
  else
  {
    lastThree = (lastThree + 7) % 8; // Adding 7 is the same as subtracting 1
    if (lastThree == 7) // Don't allow setting it to 7
    {
        lastThree = 6; // skip down to 0
    }
  }
  dataByte = 8*(dataByte/8) + lastThree;
}

double calcCap(const byte& i)
{
  return 85 + double(i)*30/255; // 85-115 pF (8 bits)
}


void showDelay()
{
  int hh,mm, ss;
  char tArray[11];
  long delay_s;
  double ra, rb, cap, f;
  byte lastThreeBits;

  lastThreeBits = factorByte % 8 ; // 0-7. f=10^x
  if (lastThreeBits==7) // illegal setting
  {
      lastThreeBits = 0;
  }
  f = pow(10.0,double(lastThreeBits));
  ra = calcResistance_E6_Kohm(RaByte); // Kohm
  rb = calcResistance_E6_Kohm(RbByte); // Kohm
  cap = calcCapacitance_E6_pF(CxByte); // pF
  if(capacitorMode(factorByte))
  {
    cap += calcCap(capacitorByte);
  }
  else
  {
     cap += INTERNAL_CAP_PF; // 555C has this capacitance included in its value
  }
  delay_s = long(round(0.695*(ra+2*rb)*cap*f*1E-9));
  hh = delay_s / 3600;
  mm = (delay_s - hh*3600) / 60;
  ss = delay_s - hh*3600 - mm*60;
  if (hh>99)
  {
    sprintf(tArray,"T: >100hrs");
  }
  else
  {
    if (delay_s<1)
    {
      sprintf(tArray,"T: <1s");
    }
    else
    {
      sprintf(tArray,"T:%02d:%02d:%02d",hh,mm,ss);
    }
  }
  tArray[10] = '\0'; // IMPORTANT
  display.println(tArray);
}

void showByte(const bool& isConfig)
{
  char bitArray[10];
  byte b;
  if (isConfig)
  {
    b=factorByte;
  }
  else
  {
    b=capacitorByte;
  }
  formatByteAsBits(bitArray,b); // e.g. 255-> 1111-1111
  OKbuttonMode = true;
  prepareDisplay();
  display.println("**CSS555**");
  if (isConfig)
  {
    display.println("Config=");
  }
  else
  {
    display.println("Capacitor=");
  }
  display.println(bitArray);
  display.println("1: OK");
  display.display();
}


void prepareDisplay()
{
  display.clearDisplay();
  display.setTextSize(2);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(0,0); // Start at top-left corner 
}


void showInfo()
{
  prepareDisplay();
  display.println("**CSS555**");
  switch (menuID)
  {
    case 0:
          display.println("Main menu"); 
          display.println("1: Read..."); 
          display.println("2: Set..."); 
          break;
    case 1: 
          display.println("Read");
          display.println("1: Conf..."); 
          display.println("2: Cap..."); 
          break;
    case 2: 
          display.println("Set"); 
          display.println("1: 555..."); 
          display.println("2: Ext..."); 
          break;
    case 3:
          switch(categoryID)
          { // 0: Fact, 1: Stab, 2: Cap, 3: Volt, 4: Power, 5: Type
            case 0: 
                    display.println("Factor:");
                    switch (factorByte % 8) 
                    {
                      case 0: display.println("1"); break;
                      case 1: display.println("10"); break;
                      case 2: display.println("100"); break;
                      case 3: display.println("1000"); break;
                      case 4: display.println("10,000"); break;
                      case 5: display.println("100,000"); break;
                      case 6: display.println("1,000,000"); break;
                      default: break;
                    } 
                    break;
            case 1: 
                    display.println("Stabilty:");
                    if(monostableMode(factorByte))
                    {
                      display.println("Monostable");
                    }
                    else
                    {
                      display.println("Astable");
                    }
                    break;
            case 2: 
                    display.println("Capacitor:"); 
                    if(capacitorMode(factorByte))
                    {
                      display.print(calcCap(capacitorByte));
                      display.println(" pF");   
                    }
                    else
                    {
                      display.println("N/A"); // This category skipped if CSS555
                    }
                    break;
            case 3: 
                    display.println("Voltage:"); 
                    if(lowVoltageMode(factorByte))
                    {
                       display.println("Low 10-90%");
                    }
                    else
                    {
                      display.println("Standard");
                    }
                    break;
            case 4: 
                    display.println("Power:"); 
                    if(lowPowerMode(factorByte))
                    {
                      display.println("Low");
                    }
                    else
                    {
                      display.println("Micro(std)");
                    }
                    break;
            case 5: 
                    display.println("Type:"); 
                    if(capacitorMode(factorByte))
                    {
                      display.println("CSS-555C");
                    }
                    else
                    {
                      display.println("CSS-555");
                    }
                    break;
            default: break;       
          }
          showDelay();
          break;
    case 4: 
          switch(extCategoryID)
          {
            case 0: 
                  display.println("Cx [pF]:"); 
                  display.println(calcCapacitance_E6_pF(CxByte),0);
                  break;
            case 1: 
                  display.println("Ra [KOhm]:"); 
                  display.println(calcResistance_E6_Kohm(RaByte),0);
                  break;
            case 2: 
                  display.println("Rb [Kohm]:"); 
                  display.println(calcResistance_E6_Kohm(RbByte),0);
                  break;
            default: break;       
          }
          showDelay();
          break;
    default: break;
  }
 display.display();
}

void showWriteResults(const bool error)
{
  prepareDisplay();
  display.println("**CSS555**");
  OKbuttonMode = true;
  if(!error)
  {
    display.println("Success!!");
  }
  else
  {
    display.println("Error!!");
  }
  display.println("");
  display.println("1: OK");
  display.display();
 }


 void showSplashScreen()
{
  prepareDisplay();
  display.println("**CSS555**");
  // EEPROM_VERSION
  display.println("Loading...");
  display.println("Version: ");
  display.println(EEPROM_VERSION);
  display.display();
  delay(2000);
 }

///////////////////////////////////////////////////////////////////////////////////////////////////////
// I/O functions for the 555
///////////////////////////////////////////////////////////////////////////////////////////////////////
void turnPowerON_555()
{
  digitalWrite(POWER_PIN,LOW); // -> Vgs=-5V=ON
  delay(POWER_DELAY_MS);
}

void turnPowerOFF_555()
{
  digitalWrite(POWER_PIN,HIGH); // -> Vgs=0V=OFF
  digitalWrite(SCLK_PIN,LOW);
  digitalWrite(DATA_IN_PIN,LOW);
}

void enable_555()
{
  digitalWrite(SCLK_PIN,LOW);
  delayMicroseconds(2*CLOCK_WIDTH_US);
  digitalWrite(PROGEN_PIN,HIGH); // Inverted by transistor
  delayMicroseconds(2*CLOCK_WIDTH_US);
}

void sendBurnPulse_555()
{
  digitalWrite(DATA_IN_PIN,LOW);
  delayMicroseconds(CLOCK_WIDTH_US); // 17:th clock pulse. Added this as we removed the end delay in send()
  digitalWrite(SCLK_PIN,LOW);
  delay(SAVE_DELAY_MS);
  digitalWrite(SCLK_PIN,HIGH);
  delayMicroseconds(CLOCK_WIDTH_US);
  digitalWrite(PROGEN_PIN,LOW); // Inverted by transistor
  delay(REST_DELAY_MS);
}

void sendByteNegativeEdge_555(const byte& dByte)
{
  for (int i = 0; i<8; i++)
  {
      digitalWrite(DATA_IN_PIN,bitRead(dByte, i));
      delayMicroseconds(CLOCK_WIDTH_US);
      digitalWrite(SCLK_PIN,LOW); // Trigger point
      delayMicroseconds(CLOCK_WIDTH_US);
      digitalWrite(SCLK_PIN,HIGH);
  }
}

void sendBytePositiveEdge_555(const byte& dByte)
{
  for (int i = 0; i<8; i++)
  {
      digitalWrite(DATA_IN_PIN,bitRead(dByte, i));
      digitalWrite(SCLK_PIN,LOW);
      delayMicroseconds(CLOCK_WIDTH_US);
      digitalWrite(SCLK_PIN,HIGH); // Trigger point
      delayMicroseconds(CLOCK_WIDTH_US);
  }
}

byte readByte_555(const bool& isConfig)
{
  byte dByte = B00000000;
  enable_555();
  if (isConfig)
  {
    sendBytePositiveEdge_555(CONFIG_BYTE_READ);
  }
  else
  {
    sendBytePositiveEdge_555(CAP_BYTE_READ);
  }
  for (int i = 0; i<8; i++)
  {
      delayMicroseconds(CLOCK_WIDTH_US); 
      digitalWrite(SCLK_PIN,LOW);
      if (digitalRead(DATA_OUT_PIN))
      {
        bitSet(dByte,i);
      }
      delayMicroseconds(CLOCK_WIDTH_US);
      digitalWrite(SCLK_PIN,HIGH);
  }
  delayMicroseconds(CLOCK_WIDTH_US);
  digitalWrite(PROGEN_PIN,LOW); // Inverted by transistor
  return dByte;
}


void writeByte_555(const bool& isConfig)
{
  byte local_factorByte = factorByte;
  if (isConfig)
  {
    bitClear(local_factorByte,6); // Set un-used bit 6 to 0
    bitClear(local_factorByte,7); // Set read-only bit 7 to 0
    enable_555();
    sendBytePositiveEdge_555(CONFIG_BYTE_WRITE);
    sendByteNegativeEdge_555(local_factorByte);
    sendBurnPulse_555();
  }
  else
  {
    enable_555();
    sendBytePositiveEdge_555(CAP_BYTE_WRITE);
    sendByteNegativeEdge_555(capacitorByte);
    sendBurnPulse_555();
  }
}

bool program_555()
{
  turnPowerON_555(); // Powers up the 555
  writeByte_555(true);
  if (readByte_555(true)!=factorByte)
  {
    turnPowerOFF_555();
    return 1;
  }
  delay(SAVE_DELAY_MS);
  if (capacitorMode(factorByte))
  {
     writeByte_555(false);
     if (readByte_555(false)!=capacitorByte)
     {
        turnPowerOFF_555();
        return 1;
     }
  }
  turnPowerOFF_555();
  return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////



void setup()
{
  // Initiate pins
  pinMode(SCLK_PIN, OUTPUT);
  pinMode(DATA_OUT_PIN, INPUT); // Out from 555 in to UNO
  pinMode(DATA_IN_PIN, OUTPUT); // In to 555 out from UNO
  pinMode(PROGEN_PIN, OUTPUT); 
  pinMode(POWER_PIN, OUTPUT);

  turnPowerOFF_555(); // Just in case it was left on from previous run.
  readLastValues();

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) // Address set to 0x3C here
  {
    while(1); // Don't proceed, loop forever
  }
  display.clearDisplay();
  display.display();
  showSplashScreen();
  showInfo();
}
  
void loop()
{
  customKey = customKeypad.getKey();
  if (customKey) // This is only true if a key has been pressed
  {
    switch (customKey)
    {
      case 'A':  // Main menu key
              if (OKbuttonMode)
              {
                OKbuttonMode = false; // to reset the action
              }
              else
              {
                menuID = 0;
              }
            showInfo();
            break;
      case 'B': // Next category menu key
              if (OKbuttonMode)
              {
                OKbuttonMode = false; // to reset the action
              }
              else
              {
                if (menuID==3) // Set 555
                {
                  if(!capacitorMode(factorByte) && (categoryID==1))
                  {
                    categoryID = 3; // skip cap for CSS555
                  }
                  else
                  {
                    categoryID = (categoryID + 1) % 6; // 0 to 5
                  }
                }
                else
                {
                  if (menuID==4) // Set Ext
                  {
                    extCategoryID = (extCategoryID + 1) % 3; // 0 to 2
                  }
                }
              }
            showInfo();
            break;
      case 'C': // Increase value key
              if (OKbuttonMode)
              {
                OKbuttonMode = false; // to reset the action
              }
              else
              {
                if (menuID==3) // Set 555
                {
                  switch (categoryID)
                  {
                    case 0: changeFactorBits(factorByte,true); break;   // Factor
                    case 1: toggleBit(factorByte,3); break;             // Stable
                    case 2: capacitorByte = (capacitorByte + 1) % 256; break;   // Cap
                    case 3: toggleBit(factorByte,5); break;             // Voltage 
                    case 4: toggleBit(factorByte,4); break;             // Power
                    case 5: toggleBit(factorByte,7); break;             // Type     
                    default: break;
                  }
                }
                else
                {
                  if (menuID==4) // Set Ext
                  {
                    switch (extCategoryID)
                    {
                        case 0: CxByte = (CxByte + 1) % 20 ; break;
                        case 1: RaByte = (RaByte + 1) % 13 ; break;
                        case 2: RbByte = (RbByte + 1) % 13 ; break;
                        default: break;
                    }
                  }
                }
              showInfo();
              break;
              }
       case 'D': // Decrease value key
               if (OKbuttonMode)
               {
                 OKbuttonMode = false; // to reset the action
               }
               else
               {
                 if (menuID==3) // Set 555
                 {
                   switch (categoryID)
                   {
                    case 0: changeFactorBits(factorByte,false); break;   // Factor
                    case 1: toggleBit(factorByte,3); break;             // Stable
                    case 2: capacitorByte = (capacitorByte + 255) % 256; break;   // Cap // -1
                    case 3: toggleBit(factorByte,5); break;             // Voltage 
                    case 4: toggleBit(factorByte,4); break;             // Power
                    case 5: toggleBit(factorByte,7); break;             // Type     
                    default: break;
                  }
                 }
                 else
                 {
                   if (menuID==4) // Set Ext
                   {
                    switch (extCategoryID)
                    {
                        case 0: CxByte = (CxByte + 19) % 20 ; break; // -1
                        case 1: RaByte = (RaByte + 12) % 13 ; break; // -1
                        case 2: RbByte = (RbByte + 12) % 13 ; break; // -1
                        default: break;
                    }
                   }
                 }
               }
            showInfo();
            break;
       case '#': // Write key
              if (OKbuttonMode)
              {
                OKbuttonMode = false; // to reset the action
              }
              else
              { // Write to EEPROM
                saveLastValues();
                showWriteResults(program_555());
              }
            break;
            showInfo();
        case '1':
              if (OKbuttonMode)
              {
                OKbuttonMode = false; // to reset the action
              }
              else
              {
                switch(menuID)
                {
                  case 0: 
                      menuID = 1; // Main menu. Pressed 1 -> Go to Read menu...
                      break; 
                  case 1: // Read menu. Pressed 1 - > Read and display config
                      turnPowerON_555();
                      factorByte=readByte_555(true);
                      turnPowerOFF_555();
                      showByte(true); 
                      OKbuttonMode=true; 
                      break; 
                  case 2: 
                      menuID = 3; // Set menu. Pressed 1 -> Set 555...
                      break; 
                  default: break;
                } //readByte_555(true)
              }
            if(!OKbuttonMode) // Do not show info if we showed byte
            {
             showInfo();
            }
            break;
        case '2':     
            if (OKbuttonMode)
            {
              OKbuttonMode = false; // to reset the action
            }
            else
            {
              switch(menuID)
              {
                case 0: // Main menu. Pressed 2 -> Go to Set menu...
                      menuID = 2; 
                      break; 
                case 1: // Read menu. Pressed 2 - > Read and display cap
                      turnPowerON_555();
                      capacitorByte=readByte_555(false);
                      turnPowerOFF_555();
                      showByte(false); 
                      OKbuttonMode=true; 
                      break; 
                case 2: // Set menu. Pressed 2 -> Set Ext...
                      menuID = 4; 
                      break; 
                default: break;
              }
            }
            if(!OKbuttonMode) // Do not show info if we showed byte
            {
              showInfo();
            }
            break;
            case '7':     
            if (OKbuttonMode)
            {
              OKbuttonMode = false; // to reset the action
            }
            else
            {
              if ((menuID==3) && (categoryID==2)) // Internal cap selection
              {
                 capacitorByte = (capacitorByte + 224) % 256; // -32
              }
              else
              {
                if (menuID==4)
                {
                  switch (extCategoryID)
                  {
                    case 0: CxByte = (CxByte + 16) % 20; break; // -4
                    case 1: RaByte = (RaByte + 9) % 13; break; // -4
                    case 2: RbByte = (RbByte + 9) % 13; break; // -4
                    default: break;
                  }
                 }
               }
            }
            showInfo();
            break;
            case '9':   
            if (OKbuttonMode)
            {
              OKbuttonMode = false; // to reset the action
            }
            else
            {
              if ((menuID==3) && (categoryID==2))
              {
                 capacitorByte = (capacitorByte + 32) % 256;
              }
              else
              {
                if (menuID==4)
                {
                  switch (extCategoryID)
                  {
                    case 0: CxByte = (CxByte + 4) % 20; break;
                    case 1: RaByte = (RaByte + 4) % 13; break;
                    case 2: RbByte = (RbByte + 4) % 13; break;
                    default: break;
                  }
                }
              }
            }
            showInfo();
            break;
       default:
            break;
    } // switch cases      
  } // if key pressed       
 } // Loop

Credits

amaruk

amaruk

0 projects • 0 followers

Comments