Advertisement
Schupp

Nixie clock Siemens

Apr 21st, 2021
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. #include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
  2. #include <Time.h> //http://www.arduino.cc/playground/Code/Time
  3. #include <Wire.h> //http://arduino.cc/en/Reference/Wire (included withArduino IDE)
  4.  
  5. int latchPin = 10;
  6. int clockPin = 11;
  7. int dataPin = 12;
  8. int enablePin = 9;
  9. int hour_adjust=8;
  10. int mylasthour=0;
  11. int mylastminute=0;
  12. int MeineFolge[9] = { 2, 1, 0, 3, 6, 5, 4, 7 };
  13.  
  14.  
  15. void setup() {
  16.  
  17.   //RTC.set(1521872250);
  18.   pinMode(latchPin, OUTPUT);
  19.   pinMode(clockPin, OUTPUT);
  20.   pinMode(dataPin, OUTPUT);
  21.   pinMode(enablePin, OUTPUT);
  22.   pinMode(hour_adjust, INPUT);
  23.   digitalWrite(latchPin, 0);
  24.   digitalWrite(enablePin, 1);
  25.   digitalWrite(hour_adjust, HIGH);
  26.   if(digitalRead(hour_adjust)==HIGH)
  27.     setSyncProvider(summertime);
  28.   else
  29.     setSyncProvider(wintertime);
  30.   if (timeStatus() != timeSet)
  31.     Serial.println("Unable to sync with the RTC");
  32.   else
  33.     Serial.println("RTC has set the system time");
  34.   setSyncInterval(30);
  35. }
  36.  
  37. time_t wintertime(){
  38.   time_t time=RTC.get()+3600;
  39.   return time;
  40. }
  41. time_t summertime(){
  42.   time_t time=RTC.get()+7200;
  43.   return time;
  44. }
  45.  
  46. void loop() {
  47.  
  48.   if(mylasthour!=hour()|| mylastminute!=minute())            
  49.   {
  50.     settime(hour(), minute(), 0);
  51.     mylasthour=hour();
  52.     mylastminute=minute();
  53.   }
  54. }
  55.  
  56.  
  57. void settime(unsigned int Stunden, unsigned int Minuten, unsigned int temp) {
  58.   shiftOut(dataPin, clockPin, LSBFIRST,swapNibbles(reverse(mysort(uint2bcd(Minuten)))));
  59.   shiftOut(dataPin, clockPin, LSBFIRST,swapNibbles(reverse(mysort(uint2bcd(Stunden)))));
  60.   digitalWrite(latchPin, 1);                // flick the latch to putthe data on the output pins
  61.   delay(100);
  62.   digitalWrite(latchPin, 0);
  63.   delay(100);
  64. }
  65.  
  66. static unsigned int uint2bcd(unsigned int ival)// macht aus einem zweistelligem Int ein B11110000 Doppelbcd
  67. {
  68.   return ((ival / 10) << 4) | (ival % 10);
  69. }
  70.  
  71. unsigned char swapNibbles(unsigned char x) //macht aus B00001111 B11110000 Nibbles=halbes Byte
  72. {
  73.   return ( (x & 0x0F) << 4 | (x & 0xF0) >> 4 );
  74. }
  75.  
  76. unsigned char reverse(unsigned char b) { //macht aus einem B0000001 ein B1000000
  77.   b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
  78.   b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
  79.   b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
  80.   return b;
  81. }
  82.  
  83. unsigned int mysort(unsigned int ival) //sortiert BCD zu den Pins des Schieberegisters //Pins zu B ABCDABCD
  84. {
  85.   uint8_t mytempival = 0;
  86.   for (int i = 0; i < 7; i++) {
  87.     if (bitRead(ival, i) == 1) {
  88.       bitWrite(mytempival, MeineFolge[i], 1);
  89.  
  90.     }
  91.   }
  92.  
  93.   return mytempival;
  94. }
  95.  
  96.  
  97.  
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement