QC

Hiển Thị Led 7 đoạn AVR

 HIỂN THỊ LED 7 ĐOẠN AVR

TÌM HIỂU LED 7 ĐOẠN XEM Ở ĐÂY.

   Trong hướng dẫn này, chúng tôi sẽ giao tiếp một đoạn bảy với ATmega32 và hiển thị bộ đếm hex một chữ số (0-F). Sau đó, điều tương tự sẽ được mở rộng cho các màn hình ghép 4 bảy đoạn để tạo ra bộ đếm 4 chữ số.

LED 7 ĐOẠN DƯƠNG CHUNG ( ANODE).




Code

#include <avr/io.h>
#include <util/delay.h>

#define SegOne   0x01
#define SegTwo   0x02
#define SegThree 0x04
#define SegFour  0x08	



int main() {
    char seg_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
    int cnt, num, temp,i;

    /* Configure the ports as output */
    DDRB = 0xff; // Data lines
    DDRD = 0xff; // Control signal PORTD0-PORTD3

    while (1) 
    {
        for (cnt = 0x00; cnt <= 9999; cnt++) // loop to display 0-9999
        {
            for (i = 0; i < 100; i++)
            {
                num = cnt;
                temp = num / 1000;
                num = num % 1000;
                PORTD = SegOne; 
                PORTB = seg_code[temp];               
                _delay_ms(1);

                temp = num / 100;
                num = num % 100;
                PORTD = SegTwo; 
                PORTB = seg_code[temp];
                _delay_ms(1);

                temp = num / 10;
                PORTD = SegThree;
                PORTB = seg_code[temp];
                _delay_ms(1);

                temp = num % 10;
                PORTD = SegFour;
                PORTB = seg_code[temp];
                _delay_ms(1);                              
            }
        }
    }
}


Giải Toán 10 Kết nối tri thức Bài tập cuối chương III

Giải Toán 10 Kết nối tri thức Bài tập cuối chương III 1. Bài 3.12 trang 44 Toán 10 Tập 1 - Kết nối tri thức 2. Bài 3.13 trang 44 Toán 10 Tập...