1

Тема: Часы на ИН-12А (ИН-15А) (LGT8F328)

http://forum.rcl-radio.ru/uploads/images/2024/09/6543e04ea67122bc6c2433454e77dc6e.gif


// LGT8F328

#define AN1     2
#define AN2     3
#define AN3     4
#define AN4     5
#define AN5     6

#define ID1     11
#define ID2     10
#define ID4     7
#define ID8     8

#define SET     A0 // BUTTON SET
#define UP      A2 // BUTTON +++
#define DW      A1 // BUTTON ---

#define BR      300  // 400-3000 яркость

#include <Wire.h> 
#include <DS3231.h> //http://rcl-radio.ru/wp-content/uploads/2022/10/DS3231.zip
  DS3231 clock;
  RTCDateTime DateTime;
  int an, segm,i;
  byte a[5];
  int dp,h,m,set,tic;
  unsigned long times0;
  bool x;

void setup() {
  Wire.begin();clock.begin();
  Serial.begin(9600);
  Serial.println("ok");
  pinMode(9,OUTPUT);// PWM TIMER_1
  pinMode(AN1,OUTPUT);pinMode(AN2,OUTPUT);pinMode(AN3,OUTPUT);pinMode(AN4,OUTPUT);pinMode(AN5,OUTPUT);
  pinMode(ID1,OUTPUT);pinMode(ID2,OUTPUT);pinMode(ID4,OUTPUT);pinMode(ID8,OUTPUT);
  pinMode(SET,INPUT_PULLUP);pinMode(UP,INPUT_PULLUP);pinMode(DW,INPUT_PULLUP);
  
 //  clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
  cli();
  //TIMER_1 PWM +170V
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  TCCR1A |= (1<<COM1A1);
  TCCR1B |= (1<<WGM12);
  TCCR1A |= (1<<WGM11);
  TCCR1B |= (1 << CS10); 
  ICR1 = 511; 
  OCR1A = 350;
  //TIMER_2
  TCCR2A = 0;
  TCCR2B = 0;
  TCNT2 = 0;
  OCR2A = 120;
  TCCR2A |= (1 << WGM21);
  TCCR2B |= (1 << CS22) | (1 << CS21) | (1 << CS20);
  TIMSK2 |= (1 << OCIE2A);
  sei();
  }
  
void loop() { 
  DateTime=clock.getDateTime();// опрос времени
  h = DateTime.hour;
  m = DateTime.minute;

  if(digitalRead(SET)==LOW){set++;if(set>2){set=0;}delay(200);}

  if(set==1){
  if(digitalRead(UP)==LOW){x=1;tic=0;h++;if(h>23){h=23;}delay(200);}
  if(digitalRead(DW)==LOW){x=1;tic=0;h--;if(h<0){h=0;}delay(200);}
  if(tic==0){a[0]=h/10%10;}else{a[0]=10;}
  if(tic==0){a[1]=h%10;}else{a[1]=10;}
  a[2]=7;
  a[3]=m/10%10;
  a[4]=m%10;
  }

  if(set==2){
  if(digitalRead(UP)==LOW){x=1;tic=0;m++;if(m>59){m=59;}delay(200);}
  if(digitalRead(DW)==LOW){x=1;tic=0;m--;if(m<0){m=0;}delay(200);}
  a[0]=h/10%10;
  a[1]=h%10;
  a[2]=7;
  if(tic==0){a[3]=m/10%10;}else{a[3]=10;}
  if(tic==0){a[4]=m%10;}else{a[4]=10;}
  }

  if(x==1){x=0;clock.setDateTime(2024, 1, 1, h, m, 0);}

  if(set==0){
  if(millis()-times0<500){dp=8;}
  if(millis()-times0>=500){dp=10;}
  if(millis()-times0>1000){times0=millis();}
  a[0]=h/10;
  a[1]=h%10;
  a[2]=dp;
  a[3]=m/10%10;
  a[4]=m%10;
  }
  
  tic++;
  if(tic>1){tic=0;}
  delay(100);
}

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID1,LOW);digitalWrite(ID2,LOW);digitalWrite(ID4,LOW);digitalWrite(ID8,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID1,LOW);digitalWrite(ID2,LOW);digitalWrite(ID4,LOW);digitalWrite(ID8,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID1,LOW);digitalWrite(ID2,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID8,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID1,LOW);digitalWrite(ID2,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID8,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID1,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID8,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID1,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID8,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID1,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID8,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID1,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID8,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID1,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID4,LOW);digitalWrite(ID8,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID1,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID4,LOW);digitalWrite(ID8,HIGH);break;   // DEC 9 = 0b0110
   case 10: digitalWrite(ID1,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID8,HIGH);break;
  }}
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(AN1,HIGH);digitalWrite(AN2,LOW);digitalWrite(AN3,LOW);digitalWrite(AN4,LOW);digitalWrite(AN5,LOW);break;    
    case 1: digitalWrite(AN1,LOW);digitalWrite(AN2,HIGH);digitalWrite(AN3,LOW);digitalWrite(AN4,LOW);digitalWrite(AN5,LOW);break;   
    case 2: digitalWrite(AN1,LOW);digitalWrite(AN2,LOW);digitalWrite(AN3,HIGH);digitalWrite(AN4,LOW);digitalWrite(AN5,LOW);break;   
    case 3: digitalWrite(AN1,LOW);digitalWrite(AN2,LOW);digitalWrite(AN3,LOW);digitalWrite(AN4,HIGH);digitalWrite(AN5,LOW);break; 
    case 4: digitalWrite(AN1,LOW);digitalWrite(AN2,LOW);digitalWrite(AN3,LOW);digitalWrite(AN4,LOW);digitalWrite(AN5,HIGH);break;   
  }}

ISR(TIMER2_COMPA_vect) {
  switch(i){
    case 0: segm=a[0]; an=0;cl();delayMicroseconds(BR); anod(); segment();break;
    case 1: segm=a[1]; an=1;cl();delayMicroseconds(BR); anod(); segment();break;
    case 2: segm=a[2]; an=2;cl();delayMicroseconds(BR); anod(); segment();break;
    case 3: segm=a[3]; an=3;cl();delayMicroseconds(BR); anod(); segment();break;
    case 4: segm=a[4]; an=4;cl();delayMicroseconds(BR); anod(); segment();break;
    }
    i++;if(i>4){i=0;}}

void cl(){digitalWrite(AN1,LOW);digitalWrite(AN2,LOW);digitalWrite(AN3,LOW);digitalWrite(AN4,LOW);digitalWrite(AN5,LOW);
          digitalWrite(ID1,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID8,HIGH);
          }
 

2

Re: Часы на ИН-12А (ИН-15А) (LGT8F328)

http://forum.rcl-radio.ru/uploads/images/2024/09/7638c48fac4547b1414ba55331a4fe46.png

http://forum.rcl-radio.ru/uploads/images/2024/09/075aaeb8fa3498eb326c51e3772dd251.png

http://forum.rcl-radio.ru/uploads/images/2024/09/85843f642dd090738862c025079c0f7c.png

http://forum.rcl-radio.ru/uploads/images/2024/09/a236fea5a54cad9608999dd4856e86d4.png

http://forum.rcl-radio.ru/uploads/images/2024/09/94453224b705b8a788742a1c120f193e.png

http://forum.rcl-radio.ru/uploads/images/2024/09/ce813d58930c9cf6e6e4ec9650d506f0.png

http://forum.rcl-radio.ru/uploads/images/2024/09/63513dbd5efc1db0778e1910ecba0f3d.png

http://forum.rcl-radio.ru/uploads/images/2024/09/bc708eaeaf07b7ce1717dd69bf519788.png

http://forum.rcl-radio.ru/uploads/images/2024/09/2921657ea0c8b701fb509f5c91486898.png

http://forum.rcl-radio.ru/uploads/images/2024/09/25b57848af9075cbec35183cab099243.png

http://forum.rcl-radio.ru/uploads/images/2024/09/0ed60f5870b1af889b9b2e47eb6cc0ea.png

http://forum.rcl-radio.ru/uploads/images/2024/09/db748ab60de0e5a6afc1ac31daaec1dc.png

http://forum.rcl-radio.ru/uploads/images/2024/09/71ac9d2a9d8abc36351684dc6b82148a.png

http://forum.rcl-radio.ru/uploads/images/2024/09/f8e2aa01d3ed3921596a41f53573a37a.png

http://forum.rcl-radio.ru/uploads/images/2024/09/2453e09683daae25025ab89fbb3af36c.png

http://forum.rcl-radio.ru/uploads/images/2024/09/1e19cee70ec581c7875c5da402b51f15.png

3

Re: Часы на ИН-12А (ИН-15А) (LGT8F328)

Можно узнать какая библиотека ds3231.h

4

Re: Часы на ИН-12А (ИН-15А) (LGT8F328)

http://rcl-radio.ru/wp-content/uploads/ … DS3231.zip