Re: управление драйвером жк lc75823
Пока только осилит 4 цифры и счет от 0 до 4
#define CE 10
#define CL 13
#define DI 11
int w;
unsigned long byte_1,byte_2,byte_3,byte_4,byte_5;
unsigned long h1,h2,h3,h4,h5,h6,h7,h8;
unsigned long kav_1=0,dvoetoh=0,toch=1,kav_2=1;
void setup() {
Serial.begin(9600);
pinMode(CE, OUTPUT);
pinMode(CL, OUTPUT);
pinMode(DI, OUTPUT);
digitalWrite(CE,LOW);
digitalWrite(CL,LOW);
delay(200);
// 1 32
//byte_1 00000000000000000000000000000000
// 33 64
//byte_2 00000000000000000000000000000000
// 65 96
//byte_3 00000000000000000000000000000000
}
void loop() {
w++;
if(w>4){w=0;}
h1 = segm(w);
h2 = segm(w);
h3 = segm(w);
h4 = segm(w);
byte_1 = h1>>6;
byte_2 = (h1&0b11111111)<<24 | (h2&0b1111111111000)<<10 |kav_1<<12 | (h2&0b11)<<10 | dvoetoh<<9 | h3>>5;
byte_3 = (h3&0b11111)<<27 | toch<<29 | h4<<12;
write_byte(0x41, byte_1,byte_2,byte_3,byte_4,byte_5, 0b0000);
delay(1000);
}
void write_byte(byte addr, unsigned long b0, unsigned long b1, unsigned long b2, unsigned long b3, unsigned long b4, byte contr){
/// addr 8 bit
digitalWrite(CE,LOW);
for(int i = 0; i <= 7; i++){
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(DI, (addr >> i) & 1);
digitalWrite(CL,HIGH);delayMicroseconds(10);
}
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(CE,HIGH);
// data 156 bit
// 1-24 seg
for(int i = 31;i >= 0; i--){
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(DI, (b0 >> i) & 1);
Serial.print((b0 >> i) & 1);
digitalWrite(CL,HIGH);delayMicroseconds(10);
}
Serial.print(" ");
for(int i = 31;i >= 0; i--){
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(DI, (b1 >> i) & 1);
Serial.print((b1 >> i) & 1);
digitalWrite(CL,HIGH);delayMicroseconds(10);
}
Serial.print(" ");
for(int i = 31;i >= 0; i--){
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(DI, (b2 >> i) & 1);
Serial.print((b2 >> i) & 1);
digitalWrite(CL,HIGH);delayMicroseconds(10);
}
Serial.print(" ");
for(int i = 31;i >= 0; i--){
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(DI, (b3 >> i) & 1);
digitalWrite(CL,HIGH);delayMicroseconds(10);
}
for(int i = 27;i >= 0; i--){
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(DI, (b4 >> i) & 1);
digitalWrite(CL,HIGH);delayMicroseconds(10);
}
Serial.println();
// control data 4 bit
for(int i = 3; i >= 0; i--){
digitalWrite(CL,LOW);delayMicroseconds(10);
digitalWrite(DI, (contr >> i) & 1);
digitalWrite(CL,HIGH);delayMicroseconds(10);
}
digitalWrite(CE,LOW);
digitalWrite(CL,LOW);
delay(10);
}
int segm(int cif){
unsigned int data_out;
switch(cif){
case 0: data_out=0b11000101000011;break;//0
case 1: data_out=0b00000000100011;break;//1
case 2: data_out=0b01010101010010;break;//2
case 3: data_out=0b00010101010011;break;//3
case 4: data_out=0b10010000010011;break;//4
case 5: data_out=0b00000000000000;break;//5
case 6: data_out=0b00000000000000;break;//6
case 7: data_out=0b00000000000000;break;//7
case 8: data_out=0b00000000000000;break;//8
case 9: data_out=0b00000000000000;break;//9
case 10: data_out=0b00000000000000;break;// пусто
case 11: data_out=0b11111111111011;break;// все
}
return data_out;
}