Тема: Драйвер VFD PT6312 на примере ИВ-21
Основная статья - http://rcl-radio.ru/?p=131596
http://rcl-radio.ru/wp-content/uploads/ … 2-v2.6.pdf
#define STB 4
#define DIN 2
#define CLK 3
#define SET 5
#define UP 6
#define DW 7
#include <Wire.h>
#include <DS3231.h> // http://rcl-radio.ru/wp-content/uploads/2022/10/DS3231.zip
DS3231 clock;RTCDateTime DateTime;
int a[8];
long times,times0;
int hour,minut,secon,temp,set;
bool d,mig;
void setup(){
Serial.begin(9600);clock.begin();
// clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
pinMode(STB,OUTPUT);
pinMode(DIN,OUTPUT);
pinMode(CLK,OUTPUT);
pinMode(SET,INPUT_PULLUP);
pinMode(UP,INPUT_PULLUP);
pinMode(DW,INPUT_PULLUP);
delay(100);
digitalWrite(STB,HIGH);delay(200);
// PWM OUTPUT D9 TIMER 1
TCCR1A = 0;TCCR1B = 0;
TCCR1A = (1 << COM1A1)|(1 << WGM11);
TCCR1B = (1 << WGM13)|(1 << WGM12)|(1 << CS10);
DDRB = 1 << DDB1; // OUTPUT PWM (OCR1A)
OCR1A = 16;
ICR1 = 40;
write_byte1_PT6312(0b01000100);// command 2
write_byte1_PT6312(0b00000100);// command 1 8dig/14seg
write_byte1_PT6312(0b10001111);// command 4 display on
}
void loop(){
DateTime = clock.getDateTime();
hour = DateTime.hour;
minut = DateTime.minute;
secon = DateTime.second;
if(millis()-times>10000){temp=clock.readTemperature()*10;times=millis();}
if(digitalRead(SET)==LOW){set++;if(set>3){set=0;} delay(300);}
if(digitalRead(UP)==LOW&&set==1){hour++;if(hour>23){hour=23;} clock.setDateTime(2024, 2, 22, hour, minut, secon);delay(100);}
if(digitalRead(DW)==LOW&&set==1){hour--;if(hour<0){hour=0;} clock.setDateTime(2024, 2, 22, hour, minut, secon);delay(100);}
if(digitalRead(UP)==LOW&&set==2){minut++;if(minut>59){minut=59;} clock.setDateTime(2024, 2, 22, hour, minut, secon);delay(100);}
if(digitalRead(DW)==LOW&&set==2){minut--;if(minut<0){minut=0;} clock.setDateTime(2024, 2, 22, hour, minut, secon);delay(100);}
if(digitalRead(UP)==LOW&&set==3){secon=0; clock.setDateTime(2024, 2, 22, hour, minut, secon);delay(100);}
if(digitalRead(DW)==LOW&&set==3){secon=0; clock.setDateTime(2024, 2, 22, hour, minut, secon);delay(100);}
if(millis()-times0<200){mig=1;}
if(millis()-times0>200){mig=0;}
if(millis()-times0>400){times0=millis();}
if(secon<55||set>0){ d=0;
if(set!=3){a[0]=secon%10;}
if(set!=3){a[1]=secon/10%10;}
if(set==3&&mig==0){a[0]=secon%10;}
if(set==3&&mig==0){a[1]=secon/10%10;}
if(set==3&&mig==1){a[0]=10;}
if(set==3&&mig==1){a[1]=10;}
a[2]=11;
if(set!=2){a[3]=minut%10;}
if(set!=2){a[4]=minut/10%10;}
if(set==2&&mig==0){a[3]=minut%10;}
if(set==2&&mig==0){a[4]=minut/10%10;}
if(set==2&&mig==1){a[3]=10;}
if(set==2&&mig==1){a[4]=10;}
a[5]=11;
if(set!=1){a[6]=hour%10;}
if(set!=1){a[7]=hour/10%10;}
if(set==1&&mig==0){a[6]=hour%10;}
if(set==1&&mig==0){a[7]=hour/10%10;}
if(set==1&&mig==1){a[6]=10;}
if(set==1&&mig==1){a[7]=10;}
}
if(secon>=55&&set==0){ d=1;
a[0]=10;
a[1]=13;
a[2]=12;
a[3]=temp%10;
a[4]=temp/10%10;
a[5]=temp/100%10;
a[6]=10;
a[7]=10;
}
//dp g f e d c b a
write_byte2_PT6312(0b11000000,seg(a[0],0));//GR1
write_byte2_PT6312(0b11000010,seg(a[1],0));//GR2
write_byte2_PT6312(0b11000100,seg(a[2],0));//GR3
write_byte2_PT6312(0b11000110,seg(a[3],0));//GR4
write_byte2_PT6312(0b11001000,seg(a[4],d));//GR5
write_byte2_PT6312(0b11001010,seg(a[5],0));//GR6
write_byte2_PT6312(0b11001100,seg(a[6],0));//GR7
write_byte2_PT6312(0b11001110,seg(a[7],0));//GR8
}
byte seg(int a, bool dp){
byte segm;
switch(a){
case 0: segm=0b00111111+(dp<<7);break;
case 1: segm=0b00000110+(dp<<7);break;
case 2: segm=0b01011011+(dp<<7);break;
case 3: segm=0b01001111+(dp<<7);break;
case 4: segm=0b01100110+(dp<<7);break;
case 5: segm=0b01101101+(dp<<7);break;
case 6: segm=0b01111101+(dp<<7);break;
case 7: segm=0b00000111+(dp<<7);break;
case 8: segm=0b01111111+(dp<<7);break;
case 9: segm=0b01101111+(dp<<7);break;
case 10:segm=0b00000000;break;// пусто
case 11:segm=0b01000000;break;// -
case 12:segm=0b01100011;break;// градус
case 13:segm=0b00111001;break;// С
}
return segm;
}
void write_byte1_PT6312(byte data){
digitalWrite(STB,LOW);
for(int i = 0; i <= 7; i++){
digitalWrite(CLK,LOW);
digitalWrite(DIN, (data >> i) & 1);
digitalWrite(CLK,HIGH);
}
digitalWrite(STB,HIGH);delay(1);
}
void write_byte2_PT6312(byte reg, byte data){
digitalWrite(STB,LOW);
for(int i = 0; i <= 7; i++){
digitalWrite(CLK,LOW);
digitalWrite(DIN, (reg >> i) & 1);
digitalWrite(CLK,HIGH);
}
delay(1);
for(int i = 0; i <= 7; i++){
digitalWrite(CLK,LOW);
digitalWrite(DIN, (data >> i) & 1);
digitalWrite(CLK,HIGH);
}
digitalWrite(STB,HIGH);delay(1);
}