Skip to content

Latest commit

 

History

History
170 lines (115 loc) · 4.71 KB

7세그먼트.md

File metadata and controls

170 lines (115 loc) · 4.71 KB

📌 7세그먼트

✔ 연결방법

![image](https://user-images.githubusercontent.com/54584063/84397983-51e0f780-ac3a-11ea-89d3-17056457934f.png)



✔ 7세그먼트

  • 표시장치

    • 8개의 LED = 7개 세그먼트 + 소숫점1개

    • 2개 공통핀 + 8개 제어핀

      • 공통 양극(Anode) 방식 : 0을 줘서 켬, 공통핀-VCC, 제어핀-GND 인가

      • 공통 음극(Cathode) 방식 : 1을 줘서 켬, 공통핀-GND, 제어핀-VCC 인가하여 제어

  • 내부 구조

    image

  • 숫자 표시

    image

    • 0표현 : abcdef = 음극 11111100 = 양극 00000011
  • 제어 데이터

    • 양극(Anode type) : 0을 줘서 켬, 공통핀VCC, 제어핀 GND인가

      image

    • 음극(Cathode type) : 1을 줘서 켬, 공통핀 GND, 제어핀 VCC인가해서 제어

      image

  • 4자리

    • 제어핀 수

      1자리 7세그먼트 제어를 위해 => 8개 제어핀 필요

      4자리 7세그먼트 => 8 x 4 = 32개

      => "공유" : 잔상효과 사용(Afterimage effect)

    • 구조

      "양극"에서 자리 선택 = 1, 세그먼트 켜기 = 0 "음극"에서 자리 선택 = 0, 세그먼트 켜기 = 1

      image

  • 연결방법



✔ LAB

- 1자리 숫자 표시

    ```c
    //0에서 9까지 숫자 표현
    byte pattern[] = {
        0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE4, 0xFE, 0xE6
    };

    //자릿수 선택 핀
    int digit_select_pin[] = {66,67,68,69};

    //해당 자리에 숫자 하나 표시
    void show_digit(int pos, int number){ //(위치, 출력할 숫자)
        for (int i=0; i<4; i++){
            if(i+1 == pos){
                digitalWrite(digit_select_pin[i], LOW);
            }
            else{
                digitalWrite(digit_select_pin[i], HIGH)
            }
        }
        for (int i=0; i<8; i++){
            boolean on_off = bitRead(patterns[number], 7-i);
            digitalWrite(segment_pin[i], on_off);
        }
        
    }
    ```
- 모든 자리 표시 및 0.1초 간격 카운터

    ```c
    // 4자리 7세그먼트 표시 장치에 4자리 숫자를 표시하는 함수 
    void show_4_digit(int number) {
        number = number % 10000;  // 4자리로 제한 

        int thousands = number / 1000; // 천 자리 
        number = number % 1000; 
        
        int hundreads = number / 100; // 백 자리 
        number = number % 100; 

        int tens = number / 10; // 십 자리 
        int ones = number % 10; // 일 자리 
        
        show_digit(1, thousands); 
        delay(SEGMENT_DELAY); 
        show_digit(2, hundreads); 
        delay(SEGMENT_DELAY); 
        show_digit(3, tens); 
        delay(SEGMENT_DELAY); 
        show_digit(4, ones); 
        delay(SEGMENT_DELAY); 
    } 
    void loop() { 
        time_current = millis();
        if (time_current time_previous >= 100) {
            time_previous = time_current; count++; 
        } 
        show_4_digit(count);
    }
    ```
- 시계 구현

    ```c
    void loop() {
        time_current = millis();
        if (time_current - time_previous >= 1000) {// 1초 경과 
        time_previous = time_current;
        seconds++; // 초 증가 
        
        if (seconds == 60) { // 60초가 되면 분 증가 
            seconds = 0; minutes++; 
        } 
        if (minutes == 60) {
            minutes = 0; // 60분이 되면 0으로 되돌림
        }
        show_4_digit(minutes * 100 + seconds); // 시간 표시를 위해 4자리 숫자로 만듦 
    }
    ```
- 가변저항 값 표시

    ```c
    void loop(){
        int reading = analogRead(A0);
        show_4_digit(reading);  //가변저항 값 표시
    }
    ```



🔎 정리

  • 7세그먼트 표시 장치

    • 8개 LED

    • 한 자리 = 8개 제어핀

    • 공통핀 VCC/GND를 가하는 공통 양극/음극 방식으로 구별

  • 3/4자리 7세그먼트 표시 장치

    • 잔상효과