Components and supplies
1
5 mm LED: Green
1
2N2907 PNP transistor
1
Arduino Mega 2560
2
510 ohm resistor
1
OLED display SSD1306
1
4x4 keypad
1
20 Kohm resistor
1
Small solderless breadboard (400 point)
1
CSS555/CSS555C timer
1
2N2222 NPN transistor
1
5.1 Kohm resistor
Project description
Code
Arduino code for the EEPROM programmer (V2.47)
c_cpp
Code for Arduino Mega 2560
1/////////////////////////////////////////////////////////////////////////////////////////////////////// 2// How to use: Follow the online menu. Special keys: 3// A: Go to main menu 4// B: Next category 5// C: Increase value 6// D: Decrease value 7// 7: Decrease value with large jumps 8// 9: Increase value with large jumps 9// #: Burn EEPROM 10// The delay time is shown as T: [HH:MM:SS] 11// The system capacitance is set to 26pH (from measurements) 12// External R/C values are picked from the E6 series 13// The green LED is on when the 555 has power (Vcc pin) 14/////////////////////////////////////////////////////////////////////////////////////////////////////// 15const double EEPROM_VERSION = 2.47; 16/////////////////////////////////////////////////////////////////////////////////////////////////////// 17// Connections: (Mega:Keypad) 18// Keypad pins are numbered 8,7...,1 from left to 19// right when the pad is with the text up. 20// D2 : Pin 1 21// D3 : Pin 2 22// D4 : Pin 3 23// D5 : Pin 4 24// D6 : Pin 5 25// D7 : Pin 6 26// D8 : Pin 7 27// D9 : Pin 8 28// Connections: (Mega:OLED) 29// 5V : VCC 30// GND : GND 31// D20 (SDA) : SDA 32// D21 (SCL) : SCL 33// Connections: (Mega:555) 34// D22 : Pin 2 (Trigger) 35// D23 : Pin 3 (Output) 36// D24 : Pin 4 (Reset) 37// Connections to NPN (2N2222) and PNP (2N2907) transistors 38// D25 : To 510 ohm to base on NPN transistor 39// NPN emitter to Gnd 40// NPN collector to Pin 5 on 555 (ProgEn) 41// D26 : To 510 ohm to base on PNP transistor 42// PNP emitter to 5V 43// PNP collector to pin 8 on 555 (Vcc) 44// Pin 8 on 555 (Vcc) to 20kohm to pin 5 on 555 (ProgEn) 45// Pin 8 on 555 (Vcc) to green LED to 5.1K resistor to ground 46/////////////////////////////////////////////////////////////////////////////////////////////////////// 47 48#include <Adafruit_SSD1306.h> // OLED 49#include <EEPROM.h> // Local variables 50#include <Keypad.h> // Keypad 51 52// OLED constants 53#define SCREEN_WIDTH 128 // OLED display width, in pixels 54#define SCREEN_HEIGHT 64 // OLED display height, in pixels 55#define OLED_RESET 11 // Reset pin # (or -1 if sharing Arduino reset pin) 56Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 57 58// Interface command constants 59const byte CONFIG_BYTE_READ = B00010001; // Read mode byte 1 60const byte CAP_BYTE_READ = B00100001; // Read mode byte 2 61const byte CONFIG_BYTE_WRITE = B00010010; // Write mode byte 1 62const byte CAP_BYTE_WRITE = B00100010; // Write mode byte 2 63 64// Keypad constants 65const byte ROWS = 4; 66const byte COLS = 4; 67char hexaKeys[ROWS][COLS] = 68{ 69 {'1','2','3','A'}, 70 {'4','5','6','B'}, 71 {'7','8','9','C'}, 72 {'*','0','#','D'} 73}; 74// Keypad pin asignments 75byte rowPins[ROWS] = {9, 8, 7, 6}; 76byte colPins[COLS] = {5, 4, 3, 2}; 77Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 78 79// 555 pin assignments 80const int SCLK_PIN = 22; // Trigger pin on 555 (2) 81const int DATA_OUT_PIN = 23; // Output pin on 555 (3). Data out from 555 82const int DATA_IN_PIN = 24; // Reset pin on 555 (4). Data into 555 (OLED reset = 11 here) 83const int PROGEN_PIN = 25; // Control pin on 555 (5) 84const int POWER_PIN = 26; // Controls power to the 555 85 86// Timing constants 87const int CLOCK_WIDTH_US = 1; 88const int SAVE_DELAY_MS = 25; 89const int REST_DELAY_MS = 2; 90const int POWER_DELAY_MS = 1000; 91 92// EEPROM constants 93const byte FACTOR_BYTE_ADDR = 0; 94const byte CAP_BYTE_ADDR = 1; 95const byte CX_BYTE_ADDR = 2; 96const byte RA_BYTE_ADDR = 3; 97const byte RB_BYTE_ADDR = 4; 98 99const double INTERNAL_CAP_PF = 26.0; // From experimental results 100 101// State variables 102byte menuID = 0; // 0: Main, 1: Read, 2: Set, 3: Set 555, 4: Set ext 103byte categoryID = 5; // 0: Fact, 1: Stab, 2: Cap, 3: Volt, 4: Power, 5: Type 104byte extCategoryID = 0; // 0: Cx, 1: Ra, 2: Rb 105bool OKbuttonMode = false; 106char customKey; 107 108// EEPROM variables; 109byte CxByte; // 0-19 110byte RaByte; // 0-12 111byte RbByte; // 0-12 112byte factorByte; // default from local EEPROM 113byte capacitorByte; // default from local EEPROM 114 115/////////////////////////////////////////////////////////////////////////////////////////////////////// 116// Binary help functions 117/////////////////////////////////////////////////////////////////////////////////////////////////////// 118void toggleBit(byte& dataByte, const int& n) 119{ 120 if (bitRead(dataByte,n)) 121 { 122 storeBit(dataByte,n,0); 123 } 124 else 125 { 126 storeBit(dataByte,n,1); 127 } 128} 129 130void storeBit(byte& dataByte, const int& n, const bool& dataBit) 131{ 132 if(dataBit) 133 { 134 bitSet(dataByte,n); 135 } 136 else 137 { 138 bitClear(dataByte,n); 139 } 140} 141 142void formatByteAsBits(char bArray[10], const byte& b) 143{ 144 for (int i=0;i<8;i++) 145 { 146 if (i<4) // first four bits 0..3 147 { 148 if (bitRead(b,7-i)) 149 { 150 bArray[i] = '1'; 151 } 152 else 153 { 154 bArray[i] = '0'; 155 } 156 } 157 else 158 { 159 if (i>=4) // last four bits 4..7 160 { 161 if (i==4) 162 { 163 bArray[i] = '-'; // separation between first/last four bits 164 } 165 if (bitRead(b,7-i)) 166 { 167 bArray[i+1] = '1'; 168 } 169 else 170 { 171 bArray[i+1] = '0'; 172 } 173 } 174 } 175 } 176 bArray[9] = '\\0'; // end character 177} 178/////////////////////////////////////////////////////////////////////////////////////////////////////// 179 180 181void readLastValues() // From local EEPROM 182{ 183 factorByte = EEPROM.read(FACTOR_BYTE_ADDR); 184 if (factorByte == 255) // Invalid value (first time use). Set to 0 instead 185 { 186 factorByte = 0; 187 } 188 capacitorByte = EEPROM.read(CAP_BYTE_ADDR); 189 CxByte = EEPROM.read(CX_BYTE_ADDR); 190 if (CxByte>19) // Invalid value (first time use). Set to 0 instead 191 { 192 CxByte = 0; 193 } 194 RaByte = EEPROM.read(RA_BYTE_ADDR); 195 if (RaByte>12) // Invalid value (first time use). Set to 0 instead 196 { 197 RaByte = 0; 198 } 199 RbByte = EEPROM.read(RB_BYTE_ADDR); 200 if (RbByte>12) // Invalid value (first time use). Set to 0 instead 201 { 202 RbByte = 0; 203 } 204} 205 206void saveLastValues() // To local EEPROM 207{ 208 // Only write if different 209 if (EEPROM.read(FACTOR_BYTE_ADDR)!=factorByte) 210 { 211 EEPROM.write(FACTOR_BYTE_ADDR,factorByte); 212 } 213 if (EEPROM.read(CAP_BYTE_ADDR)!=capacitorByte) 214 { 215 EEPROM.write(CAP_BYTE_ADDR,capacitorByte); 216 } 217 if (EEPROM.read(CX_BYTE_ADDR)!=CxByte) 218 { 219 EEPROM.write(CX_BYTE_ADDR,CxByte); 220 } 221 if (EEPROM.read(RA_BYTE_ADDR)!=RaByte) 222 { 223 EEPROM.write(RA_BYTE_ADDR,RaByte); 224 } 225 if (EEPROM.read(RB_BYTE_ADDR)!=RbByte) 226 { 227 EEPROM.write(RB_BYTE_ADDR,RbByte); 228 } 229} 230 231 232double calcResistance_E6_Kohm(const byte& rID) // 0...12 233{ 234 const int resistorArray[13] = {100,150,220,330,470,680,1000,1500,2200,3300,4700,6800,10000}; 235 if (rID>12) 236 { 237 return 100; 238 } 239 return resistorArray[rID]; 240} 241 242double calcCapacitance_E6_pF(const byte& cID) // 0...19 243{ 244 const int capacitorArray[20] = {0,10,15,22,33,47,68,100,150,220,330,470,680,1000,1500,2200,3300,4700,6800,10000}; 245 if (cID>19) 246 { 247 return 0; 248 } 249 return capacitorArray[cID]; 250} 251 252bool capacitorMode(const byte& dataByte) 253{ 254 return bitRead(dataByte,7); 255} 256 257bool lowVoltageMode(const byte& dataByte) 258{ 259 return bitRead(dataByte,5); 260} 261 262bool lowPowerMode(const byte& dataByte) 263{ 264 return bitRead(dataByte,4); 265} 266 267bool monostableMode(const byte& dataByte) 268{ 269 return bitRead(dataByte,3); 270} 271 272void changeFactorBits(byte& dataByte, const bool& up) 273{ 274 int lastThree = dataByte % 8; // 0 - 7 275 if (up) 276 { 277 lastThree = (lastThree + 1) % 8; 278 if (lastThree == 7) // Don't allow setting it to 7 279 { 280 lastThree = 0; // skip up to 0 281 } 282 } 283 else 284 { 285 lastThree = (lastThree + 7) % 8; // Adding 7 is the same as subtracting 1 286 if (lastThree == 7) // Don't allow setting it to 7 287 { 288 lastThree = 6; // skip down to 0 289 } 290 } 291 dataByte = 8*(dataByte/8) + lastThree; 292} 293 294double calcCap(const byte& i) 295{ 296 return 85 + double(i)*30/255; // 85-115 pF (8 bits) 297} 298 299 300void showDelay() 301{ 302 int hh,mm, ss; 303 char tArray[11]; 304 long delay_s; 305 double ra, rb, cap, f; 306 byte lastThreeBits; 307 308 lastThreeBits = factorByte % 8 ; // 0-7. f=10^x 309 if (lastThreeBits==7) // illegal setting 310 { 311 lastThreeBits = 0; 312 } 313 f = pow(10.0,double(lastThreeBits)); 314 ra = calcResistance_E6_Kohm(RaByte); // Kohm 315 rb = calcResistance_E6_Kohm(RbByte); // Kohm 316 cap = calcCapacitance_E6_pF(CxByte); // pF 317 if(capacitorMode(factorByte)) 318 { 319 cap += calcCap(capacitorByte); 320 } 321 else 322 { 323 cap += INTERNAL_CAP_PF; // 555C has this capacitance included in its value 324 } 325 delay_s = long(round(0.695*(ra+2*rb)*cap*f*1E-9)); 326 hh = delay_s / 3600; 327 mm = (delay_s - hh*3600) / 60; 328 ss = delay_s - hh*3600 - mm*60; 329 if (hh>99) 330 { 331 sprintf(tArray,"T: >100hrs"); 332 } 333 else 334 { 335 if (delay_s<1) 336 { 337 sprintf(tArray,"T: <1s"); 338 } 339 else 340 { 341 sprintf(tArray,"T:%02d:%02d:%02d",hh,mm,ss); 342 } 343 } 344 tArray[10] = '\\0'; // IMPORTANT 345 display.println(tArray); 346} 347 348void showByte(const bool& isConfig) 349{ 350 char bitArray[10]; 351 byte b; 352 if (isConfig) 353 { 354 b=factorByte; 355 } 356 else 357 { 358 b=capacitorByte; 359 } 360 formatByteAsBits(bitArray,b); // e.g. 255-> 1111-1111 361 OKbuttonMode = true; 362 prepareDisplay(); 363 display.println("**CSS555**"); 364 if (isConfig) 365 { 366 display.println("Config="); 367 } 368 else 369 { 370 display.println("Capacitor="); 371 } 372 display.println(bitArray); 373 display.println("1: OK"); 374 display.display(); 375} 376 377 378void prepareDisplay() 379{ 380 display.clearDisplay(); 381 display.setTextSize(2); // Normal 1:1 pixel scale 382 display.setTextColor(SSD1306_WHITE); // Draw white text 383 display.setCursor(0,0); // Start at top-left corner 384} 385 386 387void showInfo() 388{ 389 prepareDisplay(); 390 display.println("**CSS555**"); 391 switch (menuID) 392 { 393 case 0: 394 display.println("Main menu"); 395 display.println("1: Read..."); 396 display.println("2: Set..."); 397 break; 398 case 1: 399 display.println("Read"); 400 display.println("1: Conf..."); 401 display.println("2: Cap..."); 402 break; 403 case 2: 404 display.println("Set"); 405 display.println("1: 555..."); 406 display.println("2: Ext..."); 407 break; 408 case 3: 409 switch(categoryID) 410 { // 0: Fact, 1: Stab, 2: Cap, 3: Volt, 4: Power, 5: Type 411 case 0: 412 display.println("Factor:"); 413 switch (factorByte % 8) 414 { 415 case 0: display.println("1"); break; 416 case 1: display.println("10"); break; 417 case 2: display.println("100"); break; 418 case 3: display.println("1000"); break; 419 case 4: display.println("10,000"); break; 420 case 5: display.println("100,000"); break; 421 case 6: display.println("1,000,000"); break; 422 default: break; 423 } 424 break; 425 case 1: 426 display.println("Stabilty:"); 427 if(monostableMode(factorByte)) 428 { 429 display.println("Monostable"); 430 } 431 else 432 { 433 display.println("Astable"); 434 } 435 break; 436 case 2: 437 display.println("Capacitor:"); 438 if(capacitorMode(factorByte)) 439 { 440 display.print(calcCap(capacitorByte)); 441 display.println(" pF"); 442 } 443 else 444 { 445 display.println("N/A"); // This category skipped if CSS555 446 } 447 break; 448 case 3: 449 display.println("Voltage:"); 450 if(lowVoltageMode(factorByte)) 451 { 452 display.println("Low 10-90%"); 453 } 454 else 455 { 456 display.println("Standard"); 457 } 458 break; 459 case 4: 460 display.println("Power:"); 461 if(lowPowerMode(factorByte)) 462 { 463 display.println("Low"); 464 } 465 else 466 { 467 display.println("Micro(std)"); 468 } 469 break; 470 case 5: 471 display.println("Type:"); 472 if(capacitorMode(factorByte)) 473 { 474 display.println("CSS-555C"); 475 } 476 else 477 { 478 display.println("CSS-555"); 479 } 480 break; 481 default: break; 482 } 483 showDelay(); 484 break; 485 case 4: 486 switch(extCategoryID) 487 { 488 case 0: 489 display.println("Cx [pF]:"); 490 display.println(calcCapacitance_E6_pF(CxByte),0); 491 break; 492 case 1: 493 display.println("Ra [KOhm]:"); 494 display.println(calcResistance_E6_Kohm(RaByte),0); 495 break; 496 case 2: 497 display.println("Rb [Kohm]:"); 498 display.println(calcResistance_E6_Kohm(RbByte),0); 499 break; 500 default: break; 501 } 502 showDelay(); 503 break; 504 default: break; 505 } 506 display.display(); 507} 508 509void showWriteResults(const bool error) 510{ 511 prepareDisplay(); 512 display.println("**CSS555**"); 513 OKbuttonMode = true; 514 if(!error) 515 { 516 display.println("Success!!"); 517 } 518 else 519 { 520 display.println("Error!!"); 521 } 522 display.println(""); 523 display.println("1: OK"); 524 display.display(); 525 } 526 527 528 void showSplashScreen() 529{ 530 prepareDisplay(); 531 display.println("**CSS555**"); 532 // EEPROM_VERSION 533 display.println("Loading..."); 534 display.println("Version: "); 535 display.println(EEPROM_VERSION); 536 display.display(); 537 delay(2000); 538 } 539 540/////////////////////////////////////////////////////////////////////////////////////////////////////// 541// I/O functions for the 555 542/////////////////////////////////////////////////////////////////////////////////////////////////////// 543void turnPowerON_555() 544{ 545 digitalWrite(POWER_PIN,LOW); // -> Vgs=-5V=ON 546 delay(POWER_DELAY_MS); 547} 548 549void turnPowerOFF_555() 550{ 551 digitalWrite(POWER_PIN,HIGH); // -> Vgs=0V=OFF 552 digitalWrite(SCLK_PIN,LOW); 553 digitalWrite(DATA_IN_PIN,LOW); 554} 555 556void enable_555() 557{ 558 digitalWrite(SCLK_PIN,LOW); 559 delayMicroseconds(2*CLOCK_WIDTH_US); 560 digitalWrite(PROGEN_PIN,HIGH); // Inverted by transistor 561 delayMicroseconds(2*CLOCK_WIDTH_US); 562} 563 564void sendBurnPulse_555() 565{ 566 digitalWrite(DATA_IN_PIN,LOW); 567 delayMicroseconds(CLOCK_WIDTH_US); // 17:th clock pulse. Added this as we removed the end delay in send() 568 digitalWrite(SCLK_PIN,LOW); 569 delay(SAVE_DELAY_MS); 570 digitalWrite(SCLK_PIN,HIGH); 571 delayMicroseconds(CLOCK_WIDTH_US); 572 digitalWrite(PROGEN_PIN,LOW); // Inverted by transistor 573 delay(REST_DELAY_MS); 574} 575 576void sendByteNegativeEdge_555(const byte& dByte) 577{ 578 for (int i = 0; i<8; i++) 579 { 580 digitalWrite(DATA_IN_PIN,bitRead(dByte, i)); 581 delayMicroseconds(CLOCK_WIDTH_US); 582 digitalWrite(SCLK_PIN,LOW); // Trigger point 583 delayMicroseconds(CLOCK_WIDTH_US); 584 digitalWrite(SCLK_PIN,HIGH); 585 } 586} 587 588void sendBytePositiveEdge_555(const byte& dByte) 589{ 590 for (int i = 0; i<8; i++) 591 { 592 digitalWrite(DATA_IN_PIN,bitRead(dByte, i)); 593 digitalWrite(SCLK_PIN,LOW); 594 delayMicroseconds(CLOCK_WIDTH_US); 595 digitalWrite(SCLK_PIN,HIGH); // Trigger point 596 delayMicroseconds(CLOCK_WIDTH_US); 597 } 598} 599 600byte readByte_555(const bool& isConfig) 601{ 602 byte dByte = B00000000; 603 enable_555(); 604 if (isConfig) 605 { 606 sendBytePositiveEdge_555(CONFIG_BYTE_READ); 607 } 608 else 609 { 610 sendBytePositiveEdge_555(CAP_BYTE_READ); 611 } 612 for (int i = 0; i<8; i++) 613 { 614 delayMicroseconds(CLOCK_WIDTH_US); 615 digitalWrite(SCLK_PIN,LOW); 616 if (digitalRead(DATA_OUT_PIN)) 617 { 618 bitSet(dByte,i); 619 } 620 delayMicroseconds(CLOCK_WIDTH_US); 621 digitalWrite(SCLK_PIN,HIGH); 622 } 623 delayMicroseconds(CLOCK_WIDTH_US); 624 digitalWrite(PROGEN_PIN,LOW); // Inverted by transistor 625 return dByte; 626} 627 628 629void writeByte_555(const bool& isConfig) 630{ 631 byte local_factorByte = factorByte; 632 if (isConfig) 633 { 634 bitClear(local_factorByte,6); // Set un-used bit 6 to 0 635 bitClear(local_factorByte,7); // Set read-only bit 7 to 0 636 enable_555(); 637 sendBytePositiveEdge_555(CONFIG_BYTE_WRITE); 638 sendByteNegativeEdge_555(local_factorByte); 639 sendBurnPulse_555(); 640 } 641 else 642 { 643 enable_555(); 644 sendBytePositiveEdge_555(CAP_BYTE_WRITE); 645 sendByteNegativeEdge_555(capacitorByte); 646 sendBurnPulse_555(); 647 } 648} 649 650bool program_555() 651{ 652 turnPowerON_555(); // Powers up the 555 653 writeByte_555(true); 654 if (readByte_555(true)!=factorByte) 655 { 656 turnPowerOFF_555(); 657 return 1; 658 } 659 delay(SAVE_DELAY_MS); 660 if (capacitorMode(factorByte)) 661 { 662 writeByte_555(false); 663 if (readByte_555(false)!=capacitorByte) 664 { 665 turnPowerOFF_555(); 666 return 1; 667 } 668 } 669 turnPowerOFF_555(); 670 return 0; 671} 672/////////////////////////////////////////////////////////////////////////////////////////////////////// 673 674 675 676void setup() 677{ 678 // Initiate pins 679 pinMode(SCLK_PIN, OUTPUT); 680 pinMode(DATA_OUT_PIN, INPUT); // Out from 555 in to UNO 681 pinMode(DATA_IN_PIN, OUTPUT); // In to 555 out from UNO 682 pinMode(PROGEN_PIN, OUTPUT); 683 pinMode(POWER_PIN, OUTPUT); 684 685 turnPowerOFF_555(); // Just in case it was left on from previous run. 686 readLastValues(); 687 688 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) // Address set to 0x3C here 689 { 690 while(1); // Don't proceed, loop forever 691 } 692 display.clearDisplay(); 693 display.display(); 694 showSplashScreen(); 695 showInfo(); 696} 697 698void loop() 699{ 700 customKey = customKeypad.getKey(); 701 if (customKey) // This is only true if a key has been pressed 702 { 703 switch (customKey) 704 { 705 case 'A': // Main menu key 706 if (OKbuttonMode) 707 { 708 OKbuttonMode = false; // to reset the action 709 } 710 else 711 { 712 menuID = 0; 713 } 714 showInfo(); 715 break; 716 case 'B': // Next category menu key 717 if (OKbuttonMode) 718 { 719 OKbuttonMode = false; // to reset the action 720 } 721 else 722 { 723 if (menuID==3) // Set 555 724 { 725 if(!capacitorMode(factorByte) && (categoryID==1)) 726 { 727 categoryID = 3; // skip cap for CSS555 728 } 729 else 730 { 731 categoryID = (categoryID + 1) % 6; // 0 to 5 732 } 733 } 734 else 735 { 736 if (menuID==4) // Set Ext 737 { 738 extCategoryID = (extCategoryID + 1) % 3; // 0 to 2 739 } 740 } 741 } 742 showInfo(); 743 break; 744 case 'C': // Increase value key 745 if (OKbuttonMode) 746 { 747 OKbuttonMode = false; // to reset the action 748 } 749 else 750 { 751 if (menuID==3) // Set 555 752 { 753 switch (categoryID) 754 { 755 case 0: changeFactorBits(factorByte,true); break; // Factor 756 case 1: toggleBit(factorByte,3); break; // Stable 757 case 2: capacitorByte = (capacitorByte + 1) % 256; break; // Cap 758 case 3: toggleBit(factorByte,5); break; // Voltage 759 case 4: toggleBit(factorByte,4); break; // Power 760 case 5: toggleBit(factorByte,7); break; // Type 761 default: break; 762 } 763 } 764 else 765 { 766 if (menuID==4) // Set Ext 767 { 768 switch (extCategoryID) 769 { 770 case 0: CxByte = (CxByte + 1) % 20 ; break; 771 case 1: RaByte = (RaByte + 1) % 13 ; break; 772 case 2: RbByte = (RbByte + 1) % 13 ; break; 773 default: break; 774 } 775 } 776 } 777 showInfo(); 778 break; 779 } 780 case 'D': // Decrease value key 781 if (OKbuttonMode) 782 { 783 OKbuttonMode = false; // to reset the action 784 } 785 else 786 { 787 if (menuID==3) // Set 555 788 { 789 switch (categoryID) 790 { 791 case 0: changeFactorBits(factorByte,false); break; // Factor 792 case 1: toggleBit(factorByte,3); break; // Stable 793 case 2: capacitorByte = (capacitorByte + 255) % 256; break; // Cap // -1 794 case 3: toggleBit(factorByte,5); break; // Voltage 795 case 4: toggleBit(factorByte,4); break; // Power 796 case 5: toggleBit(factorByte,7); break; // Type 797 default: break; 798 } 799 } 800 else 801 { 802 if (menuID==4) // Set Ext 803 { 804 switch (extCategoryID) 805 { 806 case 0: CxByte = (CxByte + 19) % 20 ; break; // -1 807 case 1: RaByte = (RaByte + 12) % 13 ; break; // -1 808 case 2: RbByte = (RbByte + 12) % 13 ; break; // -1 809 default: break; 810 } 811 } 812 } 813 } 814 showInfo(); 815 break; 816 case '#': // Write key 817 if (OKbuttonMode) 818 { 819 OKbuttonMode = false; // to reset the action 820 } 821 else 822 { // Write to EEPROM 823 saveLastValues(); 824 showWriteResults(program_555()); 825 } 826 break; 827 showInfo(); 828 case '1': 829 if (OKbuttonMode) 830 { 831 OKbuttonMode = false; // to reset the action 832 } 833 else 834 { 835 switch(menuID) 836 { 837 case 0: 838 menuID = 1; // Main menu. Pressed 1 -> Go to Read menu... 839 break; 840 case 1: // Read menu. Pressed 1 - > Read and display config 841 turnPowerON_555(); 842 factorByte=readByte_555(true); 843 turnPowerOFF_555(); 844 showByte(true); 845 OKbuttonMode=true; 846 break; 847 case 2: 848 menuID = 3; // Set menu. Pressed 1 -> Set 555... 849 break; 850 default: break; 851 } //readByte_555(true) 852 } 853 if(!OKbuttonMode) // Do not show info if we showed byte 854 { 855 showInfo(); 856 } 857 break; 858 case '2': 859 if (OKbuttonMode) 860 { 861 OKbuttonMode = false; // to reset the action 862 } 863 else 864 { 865 switch(menuID) 866 { 867 case 0: // Main menu. Pressed 2 -> Go to Set menu... 868 menuID = 2; 869 break; 870 case 1: // Read menu. Pressed 2 - > Read and display cap 871 turnPowerON_555(); 872 capacitorByte=readByte_555(false); 873 turnPowerOFF_555(); 874 showByte(false); 875 OKbuttonMode=true; 876 break; 877 case 2: // Set menu. Pressed 2 -> Set Ext... 878 menuID = 4; 879 break; 880 default: break; 881 } 882 } 883 if(!OKbuttonMode) // Do not show info if we showed byte 884 { 885 showInfo(); 886 } 887 break; 888 case '7': 889 if (OKbuttonMode) 890 { 891 OKbuttonMode = false; // to reset the action 892 } 893 else 894 { 895 if ((menuID==3) && (categoryID==2)) // Internal cap selection 896 { 897 capacitorByte = (capacitorByte + 224) % 256; // -32 898 } 899 else 900 { 901 if (menuID==4) 902 { 903 switch (extCategoryID) 904 { 905 case 0: CxByte = (CxByte + 16) % 20; break; // -4 906 case 1: RaByte = (RaByte + 9) % 13; break; // -4 907 case 2: RbByte = (RbByte + 9) % 13; break; // -4 908 default: break; 909 } 910 } 911 } 912 } 913 showInfo(); 914 break; 915 case '9': 916 if (OKbuttonMode) 917 { 918 OKbuttonMode = false; // to reset the action 919 } 920 else 921 { 922 if ((menuID==3) && (categoryID==2)) 923 { 924 capacitorByte = (capacitorByte + 32) % 256; 925 } 926 else 927 { 928 if (menuID==4) 929 { 930 switch (extCategoryID) 931 { 932 case 0: CxByte = (CxByte + 4) % 20; break; 933 case 1: RaByte = (RaByte + 4) % 13; break; 934 case 2: RbByte = (RbByte + 4) % 13; break; 935 default: break; 936 } 937 } 938 } 939 } 940 showInfo(); 941 break; 942 default: 943 break; 944 } // switch cases 945 } // if key pressed 946 } // Loop 947
Downloadable files
Schematic showing the CSS555 connnections
Schematic showing the CSS555 connnections

Schematic showing the CSS555 connnections
Schematic showing the CSS555 connnections

Comments
Only logged in users can leave comments