QC

Đếm từ 0 - 9 Led 7 đoạn PIC dùng Mlap.

 Đếm từ 0 - 9 Led 7 đoạn PIC dùng Mlap.

Yêu cầu : Em hãy thiết kế mạch đếm từ 0 - 9 dùng PIC. ( âm chung - catot chung).

I. Chuẩn bị shematic.


II. SOURCODE NHƯ SAU :

#include <xc.h>
#define _XTAL_FREQ 20000000 //define crystal frequency to 20MHz

// This array stores binary bit pattern that will be send to PORTD
unsigned char binary_pattern[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void main(void) 
{
    TRISD = 0x00; //define PORTD as a output pin
    while(1)
    {
        //this loop sends all binary patterns to PORTD
        for (int i=0;i<10;i++)
        {
            PORTD = binary_pattern[i];
            __delay_ms(1000);  //add delay of one second
        }
    }
    return;
}
GIẢI THÍCH CODE.

* Mã từ số 0 - 9.

unsigned char binary_pattern[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
VD: Bạn muốn hiển thị số 0. ( dùng PORTD).

PORD = binary_pattern[0]; // HIỂN THỊ SỐ 0.

PORD = binary_pattern[1]; // HIỂN THỊ SỐ 1.

PORD = binary_pattern[2]; // HIỂN THỊ SỐ 2.

PORD = binary_pattern[3]; // HIỂN THỊ SỐ 3.

PORD = binary_pattern[4]; // HIỂN THỊ SỐ 4.

PORD = binary_pattern[5]; // HIỂN THỊ SỐ 5.

PORD = binary_pattern[6]; // HIỂN THỊ SỐ 6.
PORD = binary_pattern[7]; // HIỂN THỊ SỐ 7.

PORD = binary_pattern[8]; // HIỂN THỊ SỐ 8.

PORD = binary_pattern[9]; // HIỂN THỊ SỐ 9.


PORD = binary_pattern[i]; // niếu i=6 thì hiển thị số 6.


* CẤU HÌNH OUTPUT.

 PORD LÀM HIỂN THỊ LED 7 ĐOẠN OUTPUT.

 TRISD = 0x00; //define PORTD as a output pin

*HIỂN THỊ TỪ 0 - 9.

   for (int i=0;i<10;i++)
        {
            PORTD = binary_pattern[i];
            __delay_ms(1000);  //add delay of one second
        }

MÔ PHỎNG NHƯ SAU.











Hóa học 10 Bài 8. Định luật tuần hoàn. Ý nghĩa của bảng tuần hoàn các nguyên tố hóa học trang 43, 44 Hóa 10 Kết nối tri thức

Câu hỏi Trang 43 MĐ Định luật tuần hoàn đóng vai trò như thế nào trong việc dự đoán tính chất của các chất? Phương pháp giải: Bảng tuần hoàn...