• Tinkercad linklari: https://www.tinkercad.com/things/jJ72sHZ9zme-swanky-lahdi-gogo/editelsharecode=d5lCWsA3O7Oggf19EEukpwUMoKb5DI3_ktVVmkDvTrk Xulosa
  • O‘rnatilgan tizimlari fanidan 4-topshiriq mavzu: Bir razryadli va to’rt razryadli yetti segmetli indikator(display) Bajardi




    Download 0,8 Mb.
    bet2/2
    Sana17.05.2024
    Hajmi0,8 Mb.
    #239368
    1   2
    Bog'liq
    4-Topshiriq

    Amaliy qism:

    5-rasm: Amaliy qism ulanish sxemalari ko’rinishi
    Kod qismi:
    const int DATA_PIN = 2;
    const int CLOCK_PIN = 4;
    const int LATCH_PIN = 3;
    int displays[]={5,6,7,8};
    int leds[]={A0,A1,A2,A3,A4,A5,13,12,11,10};
    int btn = 9;
    int hbtn=LOW;
    int obtn=LOW;
    boolean tkq(boolean c){
    boolean d=digitalRead(btn);
    if(c !=d){
    delay(5);
    d=digitalRead(btn);
    return d;
    }
    }
    void setup()
    {
    pinMode(DATA_PIN, OUTPUT);
    pinMode(CLOCK_PIN, OUTPUT);
    pinMode(LATCH_PIN, OUTPUT);
    for(int i=0;i<4;i++){
    pinMode(displays[i],OUTPUT);
    }
    for(int i=0;i<10;i++){
    pinMode(leds[i],OUTPUT);
    }
    pinMode(btn,INPUT);
    }
    const byte arr[] = {
    B00111111, // 0
    B00000110, // 1
    B01011011, // 2
    B01001111, // 3
    B01100110, // 4
    B01101101, // 5
    B01111101, // 6
    B00000111, // 7
    B01111111, // 8
    B01101111 // 9
    };
    int num=0;
    void loop()
    {
    obtn=tkq(hbtn);
    if(obtn == LOW && hbtn==HIGH){
    num=random(10000);
    }
    hbtn=obtn;
    lamp(num);
    displayNumber(num);
    }
    void lamp(int a){
    for(int i=0;i<9;i++){
    digitalWrite(leds[i],0);
    }
    int k=0;
    while(a!=0){
    digitalWrite(leds[9-k],a%2);
    a=a/2;
    k++;
    }
    }
    void displayNumber(int number) {
    int digit1 = number / 1000;
    int digit2 = (number / 100) % 10;
    int digit3 = (number / 10) % 10;
    int digit4 = number % 10;
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(displays[0], 0);
    digitalWrite(displays[1], 1);
    digitalWrite(displays[2], 1);
    digitalWrite(displays[3], 1);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, arr[digit1]);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(displays[0], 1);
    digitalWrite(displays[1], 0);
    digitalWrite(displays[2], 1);
    digitalWrite(displays[3], 1);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, arr[digit2]);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(displays[0], 1);
    digitalWrite(displays[1], 1);
    digitalWrite(displays[2], 0);
    digitalWrite(displays[3], 1);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, arr[digit3]);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(displays[0], 1);
    digitalWrite(displays[1], 1);
    digitalWrite(displays[2], 1);
    digitalWrite(displays[3], 0);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, arr[digit4]);
    digitalWrite(LATCH_PIN, HIGH);
    digitalWrite(LATCH_PIN, LOW);
    shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
    digitalWrite(LATCH_PIN, HIGH);
    }
    Tinkercad linklari:
    https://www.tinkercad.com/things/jJ72sHZ9zme-swanky-lahdi-gogo/editel?sharecode=d5lCWsA3O7Oggf19EEukpwUMoKb5DI3_ktVVmkDvTrk

    Xulosa:
    Men bu topshiriqni bajarish davomida tinkercad.com sayti orqali tugma, to’rt razryadli yetti segmentli indikator va ledlar yordamida indikatorda qaysi son chiqsa, o’sha sonni ikkilikka o’tkazib o’sha ikkilik son bo’yicha ledlarni yoqish dasturini ishlab chiqdim. Bunda sonni ikkilikka o’tkazganimizda 3816 raqami bo’lsa o’shanga mos led yonadi. 0 raqami bo’lsa o’shanga mos led o’chadi.
    Download 0,8 Mb.
    1   2




    Download 0,8 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    O‘rnatilgan tizimlari fanidan 4-topshiriq mavzu: Bir razryadli va to’rt razryadli yetti segmetli indikator(display) Bajardi

    Download 0,8 Mb.