Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.92 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_PCF8574.h>
  3.  
  4. LiquidCrystal_PCF8574 lcd(0x20);
  5.  
  6. //назначение пинов
  7. const int data_pin = 26;
  8. const int sh_pin = 24;
  9. const int st_pin = 22;
  10. const int g5_54_int = 28;
  11. const int knopka = 30;
  12. const int svetodiod = 12;
  13. /*
  14. //нумерация регистров в байте
  15. const int rw = 7;
  16. const int sample = 6;
  17. const int mux_a2 = 5;
  18. const int mux_a1 = 4;
  19. const int mux_a0 = 3;
  20. const int mux_enable = 2;
  21. const int allow_g5_54 = 1;
  22. const int allow_knopka = 0;
  23. */
  24. // целые переменные с АЦП, их аналоговые значения, и итераторы
  25. int a0, a1, a2, a3, a4, i, j, time0, temp, Rn;
  26. float Un, In, Uo, Io, Ud, In0, Io0, Ud0;
  27.  
  28. //байты управляющие ключами и состояниями шунта, мультиплексора, выборки и прерываний
  29. byte kluchi_Uo;
  30. byte kluchi_In;
  31. byte states;
  32. const byte ones = B11111111;
  33. const byte zeros = B00000000;
  34. volatile boolean state;
  35. volatile int allow_switch;
  36.  
  37. //====================================================================================
  38.  
  39. void setup() {
  40.   state = true;
  41.   allow_switch = 1;
  42.   // инициализация дисплея и периферии
  43.   lcd.begin(16, 2);
  44.  
  45.   // настройка цифровых выходов
  46.   pinMode(data_pin, OUTPUT);
  47.   pinMode(sh_pin, OUTPUT);
  48.   pinMode(st_pin, OUTPUT);
  49.   pinMode(svetodiod, OUTPUT);
  50.   pinMode(g5_54_int, INPUT_PULLUP);
  51.   pinMode(knopka, INPUT_PULLUP);
  52.   //PULLUP!!!
  53.   // Назначение прерываний
  54.   attachInterrupt(digitalPinToInterrupt(knopka), button, FALLING);
  55.  
  56.   ///Обнуление регистров к начальному состоянию
  57.   kluchi_Uo = B11111111;
  58.   kluchi_In = B00000000;
  59.   states = B00000000;
  60.   shiftOut(data_pin,sh_pin,LSBFIRST,states);
  61.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_Uo);
  62.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_In);
  63.   digitalWrite(st_pin,HIGH);
  64.   digitalWrite(st_pin,LOW);
  65. }
  66.  
  67. //=====================================================================================
  68.  
  69.  
  70. void loop() {
  71.   state = true;
  72.   allow_switch = 1;
  73.   ///Обнуление регистров к начальному состоянию
  74.   kluchi_Uo = B11111111;
  75.   kluchi_In = B00000000;
  76.   states = B00000000;
  77.   shiftOut(data_pin,sh_pin,LSBFIRST,states);
  78.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_Uo);
  79.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_In);
  80.   digitalWrite(st_pin,HIGH);
  81.   digitalWrite(st_pin,LOW);
  82.  
  83.   //очистка дисплея и приветствие
  84.   lcd.setBacklight(255);
  85.   lcd.clear();
  86.   lcd.setCursor(0, 0);
  87.   lcd.print("npuBemcmBue...");
  88.   delay(1000);
  89.   lcd.clear();
  90.   lcd.setCursor(0, 0);
  91.   lcd.print("dla CTAPTA");
  92.   lcd.setCursor(0, 1);
  93.   lcd.print("HA)|(MUTE KHOnKy");
  94.   while (state) {
  95.     continue;
  96.   };
  97.   delay(200);
  98.   state = true;
  99.   digitalWrite(svetodiod,HIGH);
  100.   delay(1000);
  101.   digitalWrite(svetodiod,LOW);
  102. //========================================================================================
  103.  
  104.   // обнуляем переменные, в которых хранится значение прямого тока и напряжения
  105.   a0 = 0; a1 = 0;
  106.   //установка нуля
  107.   for (j=0; j <2000; j++) {
  108.     a1 += analogRead(A1);
  109.   };
  110.   In0 = a1/2000 * 0.351;
  111.  
  112.  
  113.    /// ЦИКЛ ПРЯМОГО ТОКА
  114.   /// выключаем прямой ток
  115.   kluchi_In = B00000000;
  116.   kluchi_Uo = B00000000;
  117.   states = B00000000;
  118.   for (i=0; i<9; i++) {
  119.     shiftOut(data_pin,sh_pin,LSBFIRST,states);
  120.     shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_Uo);
  121.     shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_In);
  122.     digitalWrite(st_pin,HIGH);
  123.     digitalWrite(st_pin,LOW);
  124.     while (state) {
  125.       a0 = 0; a1 = 0;
  126.       for (j=0; j <2000; j++) {
  127.         a0 += analogRead(A0);
  128.         a1 += analogRead(A1);
  129.       };
  130.       Un = a0/2000 * 0.01464;
  131.       In = a1/2000 * 0.351;
  132.       Rn = (Un-0.85)/In*1000;
  133.       if (i == 0) {
  134.         In = 0;
  135.         Rn = 0;
  136.       };
  137.       lcd.setCursor(0,0);
  138.       lcd.clear();
  139.       lcd.print(i);
  140.       lcd.print(" guog nog Inp");
  141.       lcd.setCursor(0, 1);
  142.       lcd.print(Un);
  143.       lcd.print(" ");
  144.       lcd.print(In);
  145.       lcd.print(" ");
  146.       lcd.print(Rn);
  147.       delay(100);
  148.     };
  149.     delay(200);
  150.     state = true;
  151.     digitalWrite(svetodiod,HIGH);
  152.     delay(1000);
  153.     digitalWrite(svetodiod,LOW);
  154.  
  155.     //выключение текущего диода и включение следующего, после которого цикл повторится
  156.     bitSet(kluchi_In,7-i);
  157.     bitClear(kluchi_In,8-i);
  158.     bitSet(kluchi_Uo,7-i);
  159.     bitClear(kluchi_Uo,8-i);
  160.   };
  161.  
  162. //=============================================================================================
  163.  
  164. /// ОБЩИЙ ток
  165.   kluchi_In = B11111111;
  166.   kluchi_Uo = B11111111;
  167.   states = B00000000;
  168.   shiftOut(data_pin,sh_pin,LSBFIRST,states);
  169.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_Uo);
  170.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_In);
  171.   digitalWrite(st_pin,HIGH);
  172.   digitalWrite(st_pin,LOW);
  173.   while (state) {
  174.     a0 = 0; a1 = 0;
  175.     //цикл измерения и усреднения значений напряжения с шунта, усилителя и делителя
  176.     for (i=0; i <2000; i++) {
  177.       a0 += analogRead(A0);
  178.       a1 += analogRead(A1);
  179.     };
  180.     Un = a0/2000 * 0.01464;
  181.     In = a1/2000 * 0.351;
  182.     Rn = (Un-0.85)/In*1000;
  183.     //вывод полученных данных на дисплей
  184.     lcd.setCursor(0,0);
  185.     lcd.clear();
  186.     lcd.print("BCE guogbI Inp");
  187.     lcd.setCursor(0, 1);
  188.     lcd.print(Un);
  189.     lcd.print(" ");
  190.     lcd.print(In);
  191.     lcd.print(" ");
  192.     lcd.print(Rn);
  193.     delay(100);
  194.   };
  195.   delay(200);
  196.   state = true;
  197.   digitalWrite(svetodiod,HIGH);
  198.   delay(1000);
  199.   digitalWrite(svetodiod,LOW);
  200.  
  201. //=================================================================================================
  202. //запирание
  203.  
  204.   kluchi_In = B00000000;
  205.   kluchi_Uo = B11111111;
  206.   states = B00000000;
  207.   shiftOut(data_pin,sh_pin,LSBFIRST,states);
  208.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_Uo);
  209.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_In);
  210.   digitalWrite(st_pin,HIGH);
  211.   digitalWrite(st_pin,LOW);
  212.   lcd.setCursor(0,0);
  213.   lcd.clear();
  214.   lcd.print("BCE 3AnEPTbI");
  215.   lcd.setCursor(0, 1);
  216.   lcd.print("CJIeg. npu6op");
  217.   while (state) {
  218.     continue;
  219.   };
  220.   delay(200);
  221.   state = true;
  222.   digitalWrite(svetodiod,HIGH);
  223.   delay(1000);
  224.   digitalWrite(svetodiod,LOW);
  225.  
  226. //==================================================================================================
  227. // переключение от генератора
  228.   attachInterrupt(digitalPinToInterrupt(g5_54_int), trigger, RISING);
  229.  
  230.     lcd.setCursor(0,0);
  231.     lcd.clear();
  232.     lcd.print("TEnEpb BKL");
  233.     lcd.setCursor(0, 1);
  234.     lcd.print("reHepamop");
  235.     delay(3000);
  236.     lcd.setCursor(0, 1);
  237.     lcd.print("         ");
  238.     for (i=5; i=0; i--) {
  239.       lcd.print(i);
  240.       delay(1000);
  241.       lcd.setCursor(0, 1);
  242.       lcd.print("  ");
  243.     };
  244.     lcd.clear();
  245.     lcd.setCursor(0,0);
  246.     lcd.print("cMompume Ha");
  247.     lcd.setCursor(0,1);
  248.     lcd.print("ocquLorpaMMbl");
  249.    
  250.     while (state) {
  251.       continue;
  252.     };
  253.     detachInterrupt(digitalPinToInterrupt(g5_54_int));
  254.     delay(200);
  255.   state = true;
  256.   digitalWrite(svetodiod,HIGH);
  257.   delay(1000);
  258.   digitalWrite(svetodiod,LOW);
  259.  
  260. //=================================================================================================
  261. //запирание
  262.  
  263.   kluchi_In = B00000000;
  264.   kluchi_Uo = B11111111;
  265.   states = B00000000;
  266.   shiftOut(data_pin,sh_pin,LSBFIRST,states);
  267.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_Uo);
  268.   shiftOut(data_pin,sh_pin,LSBFIRST,kluchi_In);
  269.   digitalWrite(st_pin,HIGH);
  270.   digitalWrite(st_pin,LOW);
  271.   lcd.setCursor(0,0);
  272.   lcd.clear();
  273.   lcd.print("BCE 3AnEPTbI");
  274.   lcd.setCursor(0, 1);
  275.   lcd.print("CJIeg. npu6op");
  276.  
  277.   while (state) {
  278.     continue;
  279.   };
  280.   delay(200);
  281.   state = true;
  282.   digitalWrite(svetodiod,HIGH);
  283.   delay(1000);
  284.   digitalWrite(svetodiod,LOW);
  285.  
  286. //==================================================================================================
  287.   //баловство
  288.  
  289.   lcd.setCursor(0,0);
  290.   lcd.clear();
  291.   lcd.print("nepeklu4aume");
  292.   lcd.setCursor(0, 1);
  293.   lcd.print("guogbl kHonkou");
  294.  
  295.   allow_switch = 2;
  296.   attachInterrupt(digitalPinToInterrupt(g5_54_int), trigger, RISING);
  297.  
  298.   while (true) {
  299.    
  300.     while (state) {
  301.       continue;
  302.     };
  303.    
  304.     delay(200);
  305.     state = true;
  306.      
  307.     digitalWrite(svetodiod,HIGH);
  308.     delay(1000);
  309.     digitalWrite(svetodiod,LOW);
  310.   };
  311. }
  312.  
  313. //====================================================================================================
  314.  
  315. //прерывание от генератора
  316. void trigger() {
  317.   switch (allow_switch) {
  318.     case 1:
  319.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  320.       shiftOut(data_pin,sh_pin,LSBFIRST,ones);
  321.       shiftOut(data_pin,sh_pin,LSBFIRST,ones);
  322.       digitalWrite(st_pin,HIGH);
  323.       digitalWrite(st_pin,LOW);
  324.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  325.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  326.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  327.       digitalWrite(st_pin,HIGH);
  328.       digitalWrite(st_pin,LOW);
  329.       break;
  330.     case 2:
  331.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  332.       shiftOut(data_pin,sh_pin,LSBFIRST,ones);
  333.       shiftOut(data_pin,sh_pin,LSBFIRST,ones);
  334.       digitalWrite(st_pin,HIGH);
  335.       digitalWrite(st_pin,LOW);
  336.       break;
  337.     case 3:
  338.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  339.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  340.       shiftOut(data_pin,sh_pin,LSBFIRST,zeros);
  341.       digitalWrite(st_pin,HIGH);
  342.       digitalWrite(st_pin,LOW);
  343.       break;
  344.   }
  345.  
  346. }
  347.  
  348. void button() {
  349.   state = false;
  350. //  if (allow_switch == 2) {
  351. //    allow_switch = 3;
  352. //  }
  353. //  else if (allow_switch == 3) {
  354. //    allow_switch = 2;
  355. //  };
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement