Pada kesempatan yang berbahagia kali ini saya akan menjelaskan mengenai bagaimana cara mengakses IC 74164 yang digunakan untuk driver 7segment sehingga 7segment bisa aktif dan menampilkan nilai yang kita inginkan. Pada contoh ini IC 74164 digunakan untuk menampilkan nilai sebanyak 4 digit 7segment dengan dua mode tampilan, mode yang pertama yaitu mode TEXT yang mana menampilkan tulisan "HALO" dan diikuti dengan upcounter 0 sampai 9, kemudian mode kedua yaitu mode menampilkan nilai ADC Arduino mikrokontroller pada 7segment sebanyak 4 digit. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino UNO
b. Rangkaian 7Segment Driver IC 74164
c. Program Arduino IDE Menampilkan TEXT dan UPCOUNTER
// pin 7 = CP
// pin 6 = DATA A + B
// pin 5 - 2 = switch
#define data 6
#define clock 7
int sw1 = 5;
int sw2 = 4;
int sw3 = 3;
int sw4 = 2;
int count = 0;
byte zero = B00000011;
byte one = B10011111;
byte two = B00100101;
byte three = B00001101;
byte four = B10011001;
byte five = B01001001;
byte six = B01000001;
byte seven = B00011111;
byte eight = B00000001;
byte nine = B00001001;
byte clrs = B11111111;
byte h = B10010001;
byte a = B00010001;
byte l = B11100011;
int x = 5;
void setup()
{
pinMode(clock, OUTPUT);
pinMode(data , OUTPUT);
pinMode(sw1,OUTPUT);
pinMode(sw2,OUTPUT);
pinMode(sw3,OUTPUT);
pinMode(sw4,OUTPUT);
}
void loop(){
digitalWrite(sw1,LOW);
digitalWrite(sw2,LOW);
digitalWrite(sw3,LOW);
digitalWrite(sw4,HIGH);
shiftOut(data, clock, LSBFIRST, h);
delay(x);
// shiftOut(data, clock, LSBFIRST, clrs);
// delay(x);
digitalWrite(sw1,LOW);
digitalWrite(sw2,LOW);
digitalWrite(sw3,HIGH);
digitalWrite(sw4,LOW);
shiftOut(data, clock, LSBFIRST, a);
delay(x);
// shiftOut(data, clock, LSBFIRST, clrs);
// delay(x);
digitalWrite(sw1,LOW);
digitalWrite(sw2,HIGH);
digitalWrite(sw3,LOW);
digitalWrite(sw4,LOW);
shiftOut(data, clock, LSBFIRST, l);
delay(x);
// shiftOut(data, clock, LSBFIRST, clrs);
// delay(x);
digitalWrite(sw1,HIGH);
digitalWrite(sw2,LOW);
digitalWrite(sw3,LOW);
digitalWrite(sw4,LOW);
shiftOut(data, clock, LSBFIRST, zero);
delay(x);
digitalWrite(sw1,LOW);
digitalWrite(sw2,LOW);
digitalWrite(sw3,LOW);
digitalWrite(sw4,LOW);
shiftOut(data, clock, LSBFIRST, clrs);
delay(x);
count++;
if(count > 500){
count = 0;
counter();
}
}
void counter(){
digitalWrite(sw1,HIGH);
digitalWrite(sw2,HIGH);
digitalWrite(sw3,HIGH);
digitalWrite(sw4,HIGH);
shiftOut(data, clock, LSBFIRST, zero);
delay(500);
shiftOut(data, clock, LSBFIRST, one);
delay(500);
shiftOut(data, clock, LSBFIRST, two);
delay(500);
shiftOut(data, clock, LSBFIRST, three);
delay(500);
shiftOut(data, clock, LSBFIRST, four);
delay(500);
shiftOut(data, clock, LSBFIRST, five);
delay(500);
shiftOut(data, clock, LSBFIRST, six);
delay(500);
shiftOut(data, clock, LSBFIRST, seven);
delay(500);
shiftOut(data, clock, LSBFIRST, eight);
delay(500);
shiftOut(data, clock, LSBFIRST, nine);
delay(500);
}
d. Program Arduino IDE Menampilkan Nilai ADC Pada 7Segment
#define data 6
#define clock 7
int sw1 = 5;
int sw2 = 4;
int sw3 = 3;
int sw4 = 2;
byte zero = B00000011;
byte one = B10011111;
byte two = B00100101;
byte three = B00001101;
byte four = B10011001;
byte five = B01001001;
byte six = B01000001;
byte seven = B00011111;
byte eight = B00000001;
byte nine = B00001001;
int temp;
int x = 5;
void setup()
{
// put your setup code here, to run once:
pinMode(clock, OUTPUT); // make the clock pin an output
pinMode(data , OUTPUT); // make the data pin an output3
pinMode(sw1,OUTPUT);
pinMode(sw2,OUTPUT);
pinMode(sw3,OUTPUT);
pinMode(sw4,OUTPUT);
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(A0);
temp = sensorValue;
int ribuan = temp / 1000;
temp = temp % 1000;
int ratusan = temp / 100;
temp = temp % 100;
int puluhan = temp / 10;
int satuan = temp % 10;
switch(ribuan){
case 0:
ribuan = zero;
break;
case 1:
ribuan = one;
break;
case 2:
ribuan = two;
break;
case 3:
ribuan = three;
break;
case 4:
ribuan = four;
break;
case 5:
ribuan = five;
break;
case 6:
ribuan = six;
break;
case 7:
ribuan = seven;
break;
case 8:
ribuan = eight;
break;
case 9:
ribuan = nine;
break;
}
switch(ratusan){
case 0:
ratusan = zero;
break;
case 1:
ratusan = one;
break;
case 2:
ratusan = two;
break;
case 3:
ratusan = three;
break;
case 4:
ratusan = four;
break;
case 5:
ratusan = five;
break;
case 6:
ratusan = six;
break;
case 7:
ratusan = seven;
break;
case 8:
ratusan = eight;
break;
case 9:
ratusan = nine;
break;
}
switch(puluhan){
case 0:
puluhan = zero;
break;
case 1:
puluhan = one;
break;
case 2:
puluhan = two;
break;
case 3:
puluhan = three;
break;
case 4:
puluhan = four;
break;
case 5:
puluhan = five;
break;
case 6:
puluhan = six;
break;
case 7:
puluhan = seven;
break;
case 8:
puluhan = eight;
break;
case 9:
puluhan = nine;
break;
}
switch(satuan){
case 0:
satuan = zero;
break;
case 1:
satuan = one;
break;
case 2:
satuan = two;
break;
case 3:
satuan = three;
break;
case 4:
satuan = four;
break;
case 5:
satuan = five;
break;
case 6:
satuan = six;
break;
case 7:
satuan = seven;
break;
case 8:
satuan = eight;
break;
case 9:
satuan = nine;
break;
}
digitalWrite(sw1,LOW);
digitalWrite(sw2,LOW);
digitalWrite(sw3,LOW);
digitalWrite(sw4,HIGH);
shiftOut(data, clock, LSBFIRST, ribuan);
delay(x);
digitalWrite(sw1,LOW);
digitalWrite(sw2,LOW);
digitalWrite(sw3,HIGH);
digitalWrite(sw4,LOW);
shiftOut(data, clock, LSBFIRST, ratusan);
delay(x);
digitalWrite(sw1,LOW);
digitalWrite(sw2,HIGH);
digitalWrite(sw3,LOW);
digitalWrite(sw4,LOW);
shiftOut(data, clock, LSBFIRST, puluhan);
delay(x);
digitalWrite(sw1,HIGH);
digitalWrite(sw2,LOW);
digitalWrite(sw3,LOW);
digitalWrite(sw4,LOW);
shiftOut(data, clock, LSBFIRST, satuan);
delay(x);
}
e. VIDEO HASILNYA
No comments:
Post a Comment